20250302#1
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
# PROD / DEV
|
# PROD / DEV
|
||||||
APP_MODE=DEV
|
APP_MODE=DEV
|
||||||
APP_NODES_FILE=application/config/app.php
|
APP_NODES_FILE=application/config/app.php
|
||||||
|
APPCLI_NODES_FILE=application/config/app-cli.php
|
||||||
APP_COMPONENTS_FILE=application/config/components.php
|
APP_COMPONENTS_FILE=application/config/components.php
|
||||||
CONTAINER_INI=application/config/container.php
|
CONTAINER_INI=application/config/container.php
|
||||||
CONTAINER_CACHE=var/cache/container
|
CONTAINER_CACHE=var/cache/container
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ composer create-project rmphp/skeleton project-name
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton:"^4.6" project-name
|
composer create-project rmphp/skeleton:"^4.7" project-name
|
||||||
```
|
```
|
||||||
|
|||||||
72
application/base/Controllers/AbstractHandler.php
Normal file
72
application/base/Controllers/AbstractHandler.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Base\Controllers;
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response\HtmlResponse;
|
||||||
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
|
use Laminas\Diactoros\Response\RedirectResponse;
|
||||||
|
use Laminas\Diactoros\Response\TextResponse;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Rmphp\Kernel\Main;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
abstract class AbstractHandler extends Main {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Throwable $throwable
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logException(Throwable $throwable, array $data = []) : void {
|
||||||
|
$this->logger()->warning($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Throwable $throwable
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logError(Throwable $throwable, array $data = []) : void {
|
||||||
|
$this->logger()->error($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addHeader(string $name, string $value) : void {
|
||||||
|
$this->globals()->addHeader($name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $html
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function htmlResponse($html, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new HtmlResponse($html, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $text
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function textResponse($text, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new TextResponse($text, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $array
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function jsonResponse(array $array, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new JsonResponse($array, $status, array_merge($this->globals()->response()->getHeaders(), $headers), JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/php
|
#!/usr/bin/php
|
||||||
<?php
|
<?php
|
||||||
require_once dirname(__FILE__).'/cli.php';
|
require_once dirname(__FILE__).'/console.php';
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use DI\Container;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Log\LoggerInterface;use Rmphp\Kernel\ResponseEmitter;
|
|
||||||
|
|
||||||
require_once dirname(__DIR__,2).'/vendor/autoload.php';
|
|
||||||
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__,2).'/.env');
|
|
||||||
|
|
||||||
/** @var LoggerInterface $logger */
|
|
||||||
$logger = require_once dirname(__DIR__,2).'/application/config/components/loggerFactory.php';
|
|
||||||
/** @var Container $container */
|
|
||||||
$container = require_once dirname(__DIR__,2).'/application/config/components/containerFactory.php';
|
|
||||||
$container->set(LoggerInterface::class, $logger);
|
|
||||||
|
|
||||||
if(str_contains($argv[1], ':')) {
|
|
||||||
list($className, $method) = explode(':', $argv[1]);
|
|
||||||
if(class_exists($className)) {
|
|
||||||
try {
|
|
||||||
$controllers = $container->get($className);
|
|
||||||
if(method_exists($controllers, $method)) {
|
|
||||||
$response = $controllers->$method();
|
|
||||||
}
|
|
||||||
if(isset($response)) {
|
|
||||||
if($response instanceof ResponseInterface) (new ResponseEmitter())->emit($response);
|
|
||||||
elseif(!is_bool($response)) echo $response;
|
|
||||||
}
|
|
||||||
} catch(Throwable $throwable){
|
|
||||||
$logger->error($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else echo "Class $className does not exist";
|
|
||||||
}
|
|
||||||
3
application/bin/console
Normal file
3
application/bin/console
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
require_once dirname(__FILE__).'/console.php';
|
||||||
13
application/bin/console.php
Normal file
13
application/bin/console.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response;
|
||||||
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
|
use Rmphp\Kernel\AppCli;
|
||||||
|
use Rmphp\Kernel\ResponseEmitter;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__,2).'/vendor/autoload.php';
|
||||||
|
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__,2).'/.env');
|
||||||
|
|
||||||
|
$app = new AppCli();
|
||||||
|
$response = $app->handler(ServerRequestFactory::fromGlobals(), new Response());
|
||||||
|
(new ResponseEmitter())->emit($response);
|
||||||
19
application/config/app-cli.php
Normal file
19
application/config/app-cli.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
# Example:
|
||||||
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
|
# ['key'=>'', 'router'=>'application/config/routes-cli/routes.php'],
|
||||||
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
|
return [
|
||||||
|
['key'=>'', 'router'=>[
|
||||||
|
[
|
||||||
|
'key'=>'index',
|
||||||
|
'routes' => [
|
||||||
|
[
|
||||||
|
'action' => "App\Infrastructure\Handlers\IndexHandler",
|
||||||
|
'method' => "index"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]],
|
||||||
|
];
|
||||||
@@ -12,9 +12,9 @@
|
|||||||
"monolog/monolog": "^2.3",
|
"monolog/monolog": "^2.3",
|
||||||
"php-di/php-di": "^6.3",
|
"php-di/php-di": "^6.3",
|
||||||
"ramsey/uuid": "^4.7",
|
"ramsey/uuid": "^4.7",
|
||||||
"rmphp/content": "^3.1",
|
"rmphp/content": "^4.0",
|
||||||
"rmphp/kernel": "^5.0",
|
"rmphp/kernel": "^6.0",
|
||||||
"rmphp/router": "^1.2",
|
"rmphp/router": "^2.0",
|
||||||
"rmphp/session": "^1.1",
|
"rmphp/session": "^1.1",
|
||||||
"rmphp/redis": "^1.0",
|
"rmphp/redis": "^1.0",
|
||||||
"rmphp/storage": "^6.0",
|
"rmphp/storage": "^6.0",
|
||||||
|
|||||||
22
src/Infrastructure/Handlers/IndexHandler.php
Normal file
22
src/Infrastructure/Handlers/IndexHandler.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Zuev Yuri
|
||||||
|
* Date: 02.03.2025
|
||||||
|
* Time: 22:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Infrastructure\Handlers;
|
||||||
|
|
||||||
|
use Base\Controllers\AbstractHandler;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
class IndexHandler extends AbstractHandler {
|
||||||
|
|
||||||
|
public function index() : bool|ResponseInterface {
|
||||||
|
|
||||||
|
return $this->textResponse((new \DateTime())->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user