Skip to content

Commit

Permalink
Issue #330: Move common logic to Core module
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Nov 30, 2024
1 parent 6f5dae0 commit abd7cd5
Show file tree
Hide file tree
Showing 104 changed files with 525 additions and 443 deletions.
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@ Based on Enrico Zimuel's [Zend Expressive API - Skeleton example](https://github

Using your terminal, navigate inside the directory you want to download the project files into. Make sure that the directory is empty before proceeding to the download process. Once there, run the following command:

git clone https://github.com/dotkernel/api.git .
```shell
git clone https://github.com/dotkernel/api.git .
```

## Step 2: Install project's dependencies

composer install
```shell
composer install
```

## Step 3: Development mode

If you're installing the project for development, make sure you have development mode enabled, by running:

composer development-enable
```shell
composer development-enable
```

You can disable development mode by running:

composer development-disable
```shell
composer development-disable
```

You can check if you have development mode enabled by running:

composer development-status
```shell
composer development-status
```

## Step 4: Prepare config files

Expand All @@ -56,11 +66,13 @@ You can check if you have development mode enabled by running:
* fill out the database connection params in `config/autoload/local.php` under `$databases['default']`
* run the database migrations by using the following command:

php vendor/bin/doctrine-migrations migrate
```shell
php vendor/bin/doctrine-migrations migrate
```

This command will prompt you to confirm that you want to run it:

WARNING! You are about to execute a migration in database "..." that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
> WARNING! You are about to execute a migration in database "..." that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
Hit `Enter` to confirm the operation.

Expand All @@ -70,29 +82,39 @@ Hit `Enter` to confirm the operation.

To list all the fixtures, run:

php bin/doctrine fixtures:list
```shell
php bin/doctrine fixtures:list
```

This will output all the fixtures in the order of execution.

To execute all fixtures, run:

php bin/doctrine fixtures:execute
```shell
php bin/doctrine fixtures:execute
```

To execute a specific fixture, run:

php bin/doctrine fixtures:execute --class=FixtureClassName
```shell
php bin/doctrine fixtures:execute --class=FixtureClassName
```

More details on how fixtures work can be found here: https://github.com/dotkernel/dot-data-fixtures#creating-fixtures

## Step 6: Test the installation

php -S 0.0.0.0:8080 -t public
```shell
php -S 0.0.0.0:8080 -t public
```

Sending a GET request to the [home page](http://0.0.0.0:8080/) should output the following message:

{
```text
{
"message": "DotKernel API version 5"
}
}
```

## Documentation

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
"Api\\Admin\\": "src/Admin/src/",
"Api\\App\\": "src/App/src/",
"Api\\User\\": "src/User/src/",
"Api\\Fixtures\\": "data/doctrine/fixtures/"
"Core\\Admin\\": "src/Core/src/Admin/src",
"Core\\App\\": "src/Core/src/App/src",
"Core\\User\\": "src/Core/src/User/src"
}
},
"autoload-dev": {
Expand Down
4 changes: 2 additions & 2 deletions config/autoload/authorization.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use Api\Admin\Entity\AdminRole;
use Api\User\Entity\UserRole;
use Core\Admin\Entity\AdminRole;
use Core\User\Entity\UserRole;

return [
/**
Expand Down
16 changes: 8 additions & 8 deletions config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use Api\App\Factory\OAuthScopeRepositoryFactory;
use Api\App\Factory\UserIdentityFactory;
use Api\App\Factory\UserRepositoryFactory;
use Api\App\Repository\OAuthAccessTokenRepository;
use Api\App\Repository\OAuthAuthCodeRepository;
use Api\App\Repository\OAuthClientRepository;
use Api\App\Repository\OAuthRefreshTokenRepository;
use Api\App\Repository\OAuthScopeRepository;
use Api\App\UserIdentity;
use Api\User\Repository\UserRepository;
use Core\App\Repository\OAuthAccessTokenRepository;
use Core\App\Repository\OAuthAuthCodeRepository;
use Core\App\Repository\OAuthClientRepository;
use Core\App\Repository\OAuthRefreshTokenRepository;
use Core\App\Repository\OAuthScopeRepository;
use Core\User\Repository\UserRepository;
use Core\User\UserIdentity;
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
use Dot\ErrorHandler\ErrorHandlerInterface;
use Dot\ErrorHandler\LogErrorHandler;
Expand All @@ -41,8 +41,8 @@
ClientRepositoryInterface::class => OAuthClientRepository::class,
RefreshTokenRepositoryInterface::class => OAuthRefreshTokenRepository::class,
ScopeRepositoryInterface::class => OAuthScopeRepository::class,
ErrorHandlerInterface::class => LogErrorHandler::class,
Mezzio\Authentication\UserInterface::class => UserIdentity::class,
ErrorHandlerInterface::class => LogErrorHandler::class,
Mezzio\Authorization\AuthorizationInterface::class => Mezzio\Authorization\Rbac\LaminasRbac::class,
UserRepositoryInterface::class => UserRepository::class,
],
Expand Down
69 changes: 0 additions & 69 deletions config/autoload/doctrine.global.php

This file was deleted.

4 changes: 2 additions & 2 deletions config/cli-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
declare(strict_types=1);

use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\Configuration\Migration\PhpFile;
use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\ORM\EntityManager;

$container = require 'config/container.php';

return DependencyFactory::fromEntityManager(
new PhpFile('config/migrations.php'),
new ConfigurationArray($container->get('config')['doctrine']['migrations']),
new ExistingEntityManager(
$container->get(EntityManager::class)
)
Expand Down
4 changes: 4 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ class_exists(Mezzio\Tooling\ConfigProvider::class)
Dot\Cache\ConfigProvider::class,

// Default App module config
Core\Admin\ConfigProvider::class,
Core\App\ConfigProvider::class,
Core\User\ConfigProvider::class,
Api\Admin\ConfigProvider::class,
Api\App\ConfigProvider::class,
Api\User\ConfigProvider::class,

// Load application config in a pre-defined order in such a way that local settings
// overwrite global settings. (Loaded as first to last):
// - `global.php`
Expand Down
18 changes: 0 additions & 18 deletions config/migrations.php

This file was deleted.

2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<file>src</file>
<file>test</file>

<exclude-pattern>src/Core/src/App/src/Migration/*</exclude-pattern>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
4 changes: 2 additions & 2 deletions src/Admin/src/Command/AdminCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Api\Admin\Command;

use Api\Admin\Entity\AdminRole;
use Api\Admin\InputFilter\CreateAdminInputFilter;
use Api\Admin\Service\AdminRoleService;
use Api\Admin\Service\AdminService;
use Api\App\Exception\BadRequestException;
use Api\App\Exception\ConflictException;
use Api\App\Exception\NotFoundException;
use Api\App\Message;
use Core\Admin\Entity\AdminRole;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -34,7 +34,7 @@ class AdminCreateCommand extends Command

public function __construct(
protected AdminService $adminService,
protected AdminRoleService $adminRoleService
protected AdminRoleService $adminRoleService,
) {
parent::__construct(self::$defaultName);
}
Expand Down
28 changes: 4 additions & 24 deletions src/Admin/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
use Api\Admin\Collection\AdminCollection;
use Api\Admin\Collection\AdminRoleCollection;
use Api\Admin\Command\AdminCreateCommand;
use Api\Admin\Entity\Admin;
use Api\Admin\Entity\AdminRole;
use Api\Admin\Factory\AdminCreateCommandFactory;
use Api\Admin\Handler\AdminAccountHandler;
use Api\Admin\Handler\AdminCollectionHandler;
use Api\Admin\Handler\AdminHandler;
use Api\Admin\Handler\AdminRoleCollectionHandler;
use Api\Admin\Handler\AdminRoleHandler;
use Api\Admin\Repository\AdminRepository;
use Api\Admin\Repository\AdminRoleRepository;
use Api\Admin\Service\AdminRoleService;
use Api\Admin\Service\AdminRoleServiceInterface;
use Api\Admin\Service\AdminService;
use Api\Admin\Service\AdminServiceInterface;
use Api\App\ConfigProvider as AppConfigProvider;
use Api\App\Factory\HandlerDelegatorFactory;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Core\Admin\Entity\Admin;
use Core\Admin\Entity\AdminRole;
use Core\Admin\Repository\AdminRepository;
use Core\Admin\Repository\AdminRoleRepository;
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Mezzio\Application;
Expand All @@ -35,7 +34,6 @@ public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
MetadataMap::class => $this->getHalConfig(),
];
}
Expand Down Expand Up @@ -70,24 +68,6 @@ public function getDependencies(): array
];
}

private function getDoctrineConfig(): array
{
return [
'driver' => [
'orm_default' => [
'drivers' => [
'Api\Admin\Entity' => 'AdminEntities',
],
],
'AdminEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/Entity',
],
],
];
}

public function getHalConfig(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/src/Handler/AdminAccountHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Api\Admin\Handler;

use Api\Admin\Entity\Admin;
use Api\Admin\InputFilter\UpdateAdminInputFilter;
use Api\Admin\Service\AdminServiceInterface;
use Api\App\Exception\BadRequestException;
use Api\App\Exception\ConflictException;
use Api\App\Exception\NotFoundException;
use Api\App\Handler\AbstractHandler;
use Core\Admin\Entity\Admin;
use Dot\DependencyInjection\Attribute\Inject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/src/InputFilter/Input/StatusInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Api\Admin\InputFilter\Input;

use Api\Admin\Enum\AdminStatusEnum;
use Api\App\Message;
use Core\Admin\Enum\AdminStatusEnum;
use Laminas\Filter\StringTrim;
use Laminas\Filter\StripTags;
use Laminas\InputFilter\Input;
Expand Down
Loading

0 comments on commit abd7cd5

Please sign in to comment.