createApi improvements
This commit is contained in:
parent
0201c5c559
commit
2b210fd8bc
@ -21,6 +21,7 @@ $cqrsDirectoryPath = $projectSourceDirectory . 'HandlingDomain/' . $cqrsNamespac
|
|||||||
# API Handler
|
# API Handler
|
||||||
$apiHandlerName = $apiName . 'Handler';
|
$apiHandlerName = $apiName . 'Handler';
|
||||||
$apiHandlerNamespace = $projectNamespace . '\\API\\' . $apiType . '\\' . $apiNamespace . '\\Handler';
|
$apiHandlerNamespace = $projectNamespace . '\\API\\' . $apiType . '\\' . $apiNamespace . '\\Handler';
|
||||||
|
$apiHandlerUsingNamespace = $apiHandlerNamespace . '\\' . $apiHandlerName;
|
||||||
$apiHandlerFilePath = $apiDirectoryPath . 'src/Handler/' . $apiHandlerName . '.php';
|
$apiHandlerFilePath = $apiDirectoryPath . 'src/Handler/' . $apiHandlerName . '.php';
|
||||||
|
|
||||||
# Response Formatter
|
# Response Formatter
|
||||||
@ -74,8 +75,67 @@ function writeToFile($path, $content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($apiDirectoryPath)) {
|
if (!file_exists($apiDirectoryPath)) {
|
||||||
|
|
||||||
|
$routesFileContent = "<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use {$apiHandlerUsingNamespace};
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'name' => 'TODO.TODO',
|
||||||
|
'path' => '/api/TODO/TODO[/]',
|
||||||
|
'allowed_methods' => ['POST'],
|
||||||
|
'middleware' => [
|
||||||
|
{$apiHandlerName}::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
";
|
||||||
$routesFilePath = $apiDirectoryPath . 'config/routes.php';
|
$routesFilePath = $apiDirectoryPath . 'config/routes.php';
|
||||||
|
writeToFile($routesFilePath, $routesFileContent);
|
||||||
|
|
||||||
|
$serviceManagerFileContent = "<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use {$apiHandlerUsingNamespace};
|
||||||
|
use {$apiResponseFormatterUsingNamespace};
|
||||||
|
use Reinfi\DependencyInjection\Factory\AutoWiringFactory;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'factories' => [
|
||||||
|
// Handler
|
||||||
|
{$apiHandlerName}::class => AutoWiringFactory::class,
|
||||||
|
|
||||||
|
// Response Formatter
|
||||||
|
{$$apiResponseFormatterName}::class => AutoWiringFactory::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
";
|
||||||
$serviceManagerFilePath = $apiDirectoryPath . 'config/service_manager.php';
|
$serviceManagerFilePath = $apiDirectoryPath . 'config/service_manager.php';
|
||||||
|
writeToFile($serviceManagerFilePath, $serviceManagerFileContent);
|
||||||
|
|
||||||
|
$configProviderFileContent = "<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyTube\API\{$apiType}\{$apiNamespace};
|
||||||
|
|
||||||
|
class ConfigProvider
|
||||||
|
{
|
||||||
|
public function __invoke(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'dependencies' => require __DIR__ . './../config/service_manager.php',
|
||||||
|
'routes' => require __DIR__ . '/./../config/routes.php',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
$configProviderFilePath = $apiDirectoryPath . 'src/ConfigProvider.php';
|
||||||
|
writeToFile($configProviderFilePath, $configProviderFileContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiHandlerFileContent = "<?php
|
$apiHandlerFileContent = "<?php
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user