DotKernel's PSR-15 API built around the Zend Expressive API skeleton.
Step 1: Install project dependencies by running:
$ composer install
Step 2: Prepare config files:
- duplicate
config/autoload/db.local.php.dist
asconfig/autoload/db.local.php
- duplicate
config/autoload/local.php.dist
asconfig/autoload/local.php
- duplicate
config/autoload/authorization.local.php.dist
asconfig/autoload/authorization.local.php
Step 3: Setup database:
- create a new MySQL database - set collation to
utf8mb4_general_ci
- fill out the database connection params in
config/autoload/db.local.php
- run the database migrations by using the following command:
$ vendor/bin/doctrine-migrations migrate
After the project has been successfully installed, you should modify the default OAuth2 client and it's secret phrase.
You can access Zend Expressive's CLI by using the following command:
$ composer expressive
You can access Doctrine's CLI by using the following command:
$ php vendor/doctrine/orm/bin/doctrine
You can access Doctrine's migration tools by using the following command:
$ vendor/bin/doctrine-migrations
$ composer expressive module:create Module
This will create the directory structure under: src/Module
with the module's ConfigProvider and add the it to config/config.php
$ composer expressive handler:create Module\Example\Handler\ExampleHandler
This will create:
- the handler:
src/Module/Example/Handler/ExampleHandler.php
- the factory:
src/Module/Example/Handler/ExampleHandlerFactory.php
and register it in:config/autoload/zend-expressive-tooling-factories.global.php
For a cleaner structure, it is recommended refactoring handler factories by moving them to their own directory:Factory
. In this case, make sure the factory's namespace is changed accordingly and that the change is reflected inconfig/autoload/zend-expressive-tooling-factories.global.php
as well.
Routes can be created in one of the following locations:
config/routes.php
src/{module-name}/RoutesDelegator.php
(First, make sure you registered it insrc/App/ConfigProvider.php
'sgetDependencies
method, under thedelegators
key). By using this method, if you want to move a module between projects, you will automatically move the related endpoints as well.
A good practice is storing all related entities in the same directory Entity
, next to the module's Handler
directory. For example:
src/Module/Example/Entity/ExampleEntity.php
src/Module/Example/Entity/ExampleDetailEntity.php
src/Module/Example/Entity/ExampleCategoryEntity.php
$ php -S 0.0.0.0:8080 -t public
To test the application, visit the test page. You should get the following message:
{
"message": "Welcome to DotKernel API!",
"debug": {
"database": "connected",
"php": "7.x.x"
}
}
If the request is successful, you can delete this endpoint from src/App/RoutesDelegator.php
Visit this link to access the application's documentation.