boneframework / skeleton
Bone Framework
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: ^8.2
- ext-fileinfo: *
- ext-intl: *
- ext-json: *
- ext-pdo: *
- boneframework/bone: ^3.11
- delboy1978uk/cdn: ^2.0
- delboy1978uk/image: ^2.1
Requires (Dev)
- delboy1978uk/dev-tools: ^1.0
- roave/security-advisories: dev-latest
- dev-master
- v3.11.0
- v3.10.4
- v3.10.3
- v3.10.2
- v3.10.1
- v3.10.0
- v3.9.2
- v3.9.1
- v3.9.0
- v3.8.11
- v3.8.10
- v3.8.9
- v3.8.8
- v3.8.7
- v3.8.6
- v3.8.5
- v3.8.4
- v3.8.3
- v3.8.2
- v3.8.1
- v3.8.0
- v3.7.9
- v3.7.8
- v3.7.7
- v3.7.6
- v3.7.5
- v3.7.3
- v3.7.2
- v3.7.1
- v3.7.0
- v3.6.5
- v3.6.4
- v3.6.3
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.1
- v3.5.0
- v3.4.11
- v3.4.10
- v3.4.9
- v3.4.8
- v3.4.7
- v3.4.6
- v3.4.5
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.9
- v3.3.8
- v3.3.7
- v3.3.6
- v3.3.5
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.9
- v3.2.8
- v3.2.7
- v3.2.6
- v3.2.5
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.0
- v2.1.0
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-11-07 13:12:34 UTC
README
Be ye wantin a PHP framework peppered with local pirate lingo?
It be the most fearsome framework in the seven seas!
http://github.com/boneframework
features
- PSR-7 http messaging
- PSR-11 dependency injection container configuration
- PSR-15 middleware routing
- i18n translator
- Self contained package based architecture
- Built in optional Docker dev environment
- Extendable Command Line Interface
installation
via composer
We recommend using our Docker environment, however you can use your own setup, install via composer:
composer create-project boneframework/skeleton your/path/here
cp your/path/here/.env.example your/path/here/.env
via docker
The Docker dev environment saves you from all the usual devops nonsense. Clone boneframework/lamp
, then replace
the code folder boneframework/skeleton
, then start it up.
git clone https://github.com/boneframework/lamp myproject
cd myproject
rm -fr code // remove lamp stack default placeholder page
git clone https://github.com/boneframework/skeleton code
cp code/.env.example code .env
bin/setdomain yourdomain.com // optional, default dev domain is boneframework.docker
Add 127.0.0.1 boneframework.docker
to your /etc/hosts
(or your custom domain).
To start the docker server environment:
bin/start
Then browse to https://boneframework.docker
, and you will see the site running.
The development also has Mailhog running at http://boneframework.docker:8025
, so you can configure any dev emails to use
SMTP port 1025
and all outgoing mails will appear in the Mailhog outbox.
MariaDB is running, on host mariadb
(see docker-compose.yml
), and config/bone-db.php
).
To "SSH" into your server in order to run PHP commands like composer etc, type the following in a fresh terminal window.
bin/terminal php // for the PHP container
bin/terminal mariadb // for the DB container
To shut down your server, CTRL-C out, then type bin/stop
.
a quick introduction to bone framework
skeleton project files
There are a few folders and files in your project, here's a quick description:
- config (Configuration for your application)
- data (Files your project will use (translations, cache, uploads, etc))
- public (The usual index.php endpoint and front end assets like css and images and js)
- src (Your application packages live in here)
- tests (Because it's nice knowing your code works)
- vendor (Third party composer libs, don't edit, don't commit!)
bone framework application cycle
Upon launching Bone Framework (public/index.php
), the application does a few things:
- Starts a session
- Loads the config from the config folder (different folders for different environments can be used, or environment vars)
- Registers bone framework core packages
- Registers packages from the
config/packages.php
into the DI container - Adds any site wide middleware configured in
config/middleware.php
- Dispatches a Request, returns a Response
config
You can drop in any number of .php
files into the config/
folder. Make sure they return an array with the config . You
can override configuration based on environment var APPLICATION_ENV
, so for instance if the environment was production
it would load the additional config the production subdirectory.
There are several config files included, some are for optional bone packages and may be removed :
bone-db.php
bone-firewall.php
bone-i18n.php
bone-log.php
layouts.php
middleware.php
packages.php
paginator.php
paths.php
site.php
views.php
In your config files, you can add anything you want.
the package class
Packages are a key component in a Bone Framework application. You will see in the config/packages.php
which Packages are currently running on the framework. Take note that the order is important,
as packages may have a dependency which it needs defined from another package. Have a look inside
src/App/AppPackage.php
:
<?php namespace Bone\App; use Bone\App\Controller\IndexController; use Bone\Controller\Init; use Bone\Router\Router; use Bone\Router\RouterConfigInterface; use Barnacle\RegistrationInterface; use Barnacle\Container; class AppPackage implements RegistrationInterface, RouterConfigInterface { /** * @param Container $c */ public function addToContainer(Container $c) { $c[IndexController::class] = $c->factory(function (Container $c) { $controller = new IndexController(); return Init::controller($controller, $c); }); } /** * @param Container $c * @param Router $router * @return Router */ public function addRoutes(Container $c, Router $router): Router { $router->map('GET', '/', [IndexController::class, 'indexAction']); $router->map('GET', '/learn', [IndexController::class, 'learnAction']); return $router; } }
You will see two methods, which are implementations of RegistrationInterface
and RouterConfigInterface
.
See the league/route
docs on usage of the router. In the addToContainer()
method, you can create factories for
your controllers and other dependencies.
controllers
You will notice in the above App package that the factory for the controller returns Controller::init($controller, $c)
.
This is a convenient initialisation class that will setup a few things into your class. To make things real easy, here's
all you need to do for each component:
- View Engine (implement
Bone\View\ViewAwareInterface
and useBone\View\Traits\HasViewTrait
) - Translator (implement
Bone\I18n\I18nAwareInterface
and useBone\I18n\Traits\HasTranslatorTrait
) - Site Config (implement
Bone\Server\SiteConfigAwareInterface
and useBone\Server\Traits\HasSiteConfigTrait
) - Session (implement
Bone\Server\SessionAwareInterface
and useBone\Server\HasSessionTrait
) - Logger (implement
Bone\Log\LoggerAwareInterface
and useBone\Log\HasLoggerTrait
)
You can also choose to extend Bone\Controller\Controller
, which will give you a view, translator, and site config
immediately.
controller action methods
You can see the configured routes in the package class, and which controller class and method to call. Each action
method is essentially a PSR-15 Server Request Handler Interface https://www.php-fig.org/psr/psr-15/
. See
src/App/Controller/IndexController.php
for a basic example.
db
Set your default db credentials in the main config/bone-db.php, and any environment specific configs in a subdirectory
'db' => [ 'host' => '127.0.0.1', 'database' => 'bone', 'user' => 'leChuck', 'pass' => 'bigWh00p', ],
In your package class, you can gert the connection from the container using $c->get(PDO::class)
.
i18n
Bone supports translation into different locales. Translation files (gettext .po
and .mo
) should be placed in
data/translations
, under a subdirectory of the locale, eg data/translations/en_GB/en_GB.po
. You can set the default
locale and an array of supported locales.
<?php use Laminas\I18n\Translator\Loader\Gettext; return [ 'i18n' => [ 'translations_dir' => 'data/translations', 'type' => Gettext::class, 'default_locale' => 'en_PI', 'supported_locales' => ['en_PI', 'en_GB', 'nl_BE', 'fr_BE'], ], ];
To use the translator, you can simply call:To use the translator, you can simply call:
<?php // from a controller: $this->getTranslator()->translate('placeholder.string'); // to set locale $this->getTranslator()->setLocale($locale); // from a view file: $this->t('placeholder');
You can also set a supported locale into any URL, it will be stripped off the request and the locale set.
For example, if you have an endpooint /morte/info
, you can make it /nl_BE/more/info
or whatever, your route will
still resolve but now the locale will be the one you set. You can call $this->l()
in a view file, to generate this
first part of your url.
logs
Bone uses monolog/monolog, and logs can be found in data/logs. Currently we only support writing to files, but you can add as many channels as you like:
<?php return [ 'log' => [ 'channels' => [ 'default' => 'data/logs/default_log', ], ], ];
To use the logger in a controller:
$this->getLogger()->debug($message) // or error(), etc, see PSR-3
recommended packages
Bone Framework has a variety of packages already extending the framework further. Give these a try!
delboy1978uk/bone-form
- Generate forms, handle errors, i18n compatibledelboy1978uk/bone-doctrine
- A Doctrine Entity Mangerdelboy1978uk/bone-mail
- Mail functionality for Bone Frameworkdelboy1978uk/bone-user
- Full user registration system including activation emails etcdelboy1978uk/generator
- Generate new package templates quicklydelboy1978uk/bone-oauth2
- OAuth2 Authorization and Resource Serverdelboy1978uk/bone-open-api
- Open API Swagger documentationdelboy1978uk/image
- An easy image class based ongd