add Dependencies and Routes classes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c344dce8eb
commit
7cc2d40660
|
|
@ -11,7 +11,8 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.4",
|
"php": "^7.4",
|
||||||
"slim/slim": "^4.5",
|
"slim/slim": "^4.5",
|
||||||
"slim/psr7": "^1.1"
|
"slim/psr7": "^1.1",
|
||||||
|
"php-di/php-di": "^6.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9"
|
"phpunit/phpunit": "^9"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c94e0dc94538087f6c99d168389da841",
|
"content-hash": "c9b48ebdf86b04852bf99bd1932d57e8",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "fig/http-message-util",
|
"name": "fig/http-message-util",
|
||||||
|
|
@ -104,6 +104,219 @@
|
||||||
],
|
],
|
||||||
"time": "2018-02-13T20:26:39+00:00"
|
"time": "2018-02-13T20:26:39+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "opis/closure",
|
||||||
|
"version": "3.5.5",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/opis/closure.git",
|
||||||
|
"reference": "dec9fc5ecfca93f45cd6121f8e6f14457dff372c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/opis/closure/zipball/dec9fc5ecfca93f45cd6121f8e6f14457dff372c",
|
||||||
|
"reference": "dec9fc5ecfca93f45cd6121f8e6f14457dff372c",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^5.4 || ^7.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"jeremeamia/superclosure": "^2.0",
|
||||||
|
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.5.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Opis\\Closure\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"functions.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Marius Sarca",
|
||||||
|
"email": "marius.sarca@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sorin Sarca",
|
||||||
|
"email": "sarca_sorin@hotmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.",
|
||||||
|
"homepage": "https://opis.io/closure",
|
||||||
|
"keywords": [
|
||||||
|
"anonymous functions",
|
||||||
|
"closure",
|
||||||
|
"function",
|
||||||
|
"serializable",
|
||||||
|
"serialization",
|
||||||
|
"serialize"
|
||||||
|
],
|
||||||
|
"time": "2020-06-17T14:59:55+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-di/invoker",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHP-DI/Invoker.git",
|
||||||
|
"reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/540c27c86f663e20fe39a24cd72fa76cdb21d41a",
|
||||||
|
"reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"psr/container": "~1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"athletic/athletic": "~0.1.8",
|
||||||
|
"phpunit/phpunit": "~4.5"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Invoker\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "Generic and extensible callable invoker",
|
||||||
|
"homepage": "https://github.com/PHP-DI/Invoker",
|
||||||
|
"keywords": [
|
||||||
|
"callable",
|
||||||
|
"dependency",
|
||||||
|
"dependency-injection",
|
||||||
|
"injection",
|
||||||
|
"invoke",
|
||||||
|
"invoker"
|
||||||
|
],
|
||||||
|
"time": "2017-03-20T19:28:22+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-di/php-di",
|
||||||
|
"version": "6.2.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHP-DI/PHP-DI.git",
|
||||||
|
"reference": "6875fe557c244b3830862c072c7719ca4ac2efe4"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/6875fe557c244b3830862c072c7719ca4ac2efe4",
|
||||||
|
"reference": "6875fe557c244b3830862c072c7719ca4ac2efe4",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"opis/closure": "^3.5.5",
|
||||||
|
"php": ">=7.2.0",
|
||||||
|
"php-di/invoker": "^2.0",
|
||||||
|
"php-di/phpdoc-reader": "^2.0.1",
|
||||||
|
"psr/container": "^1.0"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"psr/container-implementation": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"doctrine/annotations": "~1.2",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.4",
|
||||||
|
"mnapoli/phpunit-easymock": "^1.2",
|
||||||
|
"ocramius/proxy-manager": "~2.0.2",
|
||||||
|
"phpstan/phpstan": "^0.12",
|
||||||
|
"phpunit/phpunit": "^8.5"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"doctrine/annotations": "Install it if you want to use annotations (version ~1.2)",
|
||||||
|
"ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DI\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/functions.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "The dependency injection container for humans",
|
||||||
|
"homepage": "https://php-di.org/",
|
||||||
|
"keywords": [
|
||||||
|
"PSR-11",
|
||||||
|
"container",
|
||||||
|
"container-interop",
|
||||||
|
"dependency injection",
|
||||||
|
"di",
|
||||||
|
"ioc",
|
||||||
|
"psr11"
|
||||||
|
],
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/mnapoli",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/php-di/php-di",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2020-06-18T09:54:32+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-di/phpdoc-reader",
|
||||||
|
"version": "2.1.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHP-DI/PhpDocReader.git",
|
||||||
|
"reference": "15678f7451c020226807f520efb867ad26fbbfcf"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/15678f7451c020226807f520efb867ad26fbbfcf",
|
||||||
|
"reference": "15678f7451c020226807f520efb867ad26fbbfcf",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.6"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PhpDocReader\\": "src/PhpDocReader"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)",
|
||||||
|
"keywords": [
|
||||||
|
"phpdoc",
|
||||||
|
"reflection"
|
||||||
|
],
|
||||||
|
"time": "2019-09-26T11:24:58+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "psr/container",
|
"name": "psr/container",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use NoteCat\Dependencies;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use NoteCat\Routes;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
|
|
||||||
use NoteCat\HelloWorld;
|
$container = Dependencies::createContainer();
|
||||||
|
$app = AppFactory::createFromContainer($container);
|
||||||
|
|
||||||
$app = AppFactory::create();
|
Routes::setRoutes($app);
|
||||||
|
|
||||||
$app->get('/', function (Request $request, Response $response, $args) {
|
|
||||||
$hello = new HelloWorld();
|
|
||||||
$response->getBody()->write('<b>' . $hello->getHello() . "</b>\n");
|
|
||||||
return $response;
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace NoteCat;
|
||||||
|
|
||||||
|
use DI\Container;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class Dependencies
|
||||||
|
{
|
||||||
|
public static function createContainer(): Container
|
||||||
|
{
|
||||||
|
$container = new Container();
|
||||||
|
|
||||||
|
// Controllers
|
||||||
|
$container->set(HelloWorldController::class, function (ContainerInterface $c) {
|
||||||
|
return new HelloWorldController(
|
||||||
|
$c->get(HelloWorld::class)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Services
|
||||||
|
$container->set(HelloWorld::class, function () {
|
||||||
|
return new HelloWorld();
|
||||||
|
});
|
||||||
|
|
||||||
|
return $container;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace NoteCat;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
class HelloWorldController
|
||||||
|
{
|
||||||
|
private HelloWorld $hello;
|
||||||
|
|
||||||
|
public function __construct(HelloWorld $hello)
|
||||||
|
{
|
||||||
|
$this->hello = $hello;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hello(Request $request, Response $response): Response
|
||||||
|
{
|
||||||
|
$response->getBody()->write('<b>' . $this->hello->getHello() . "</b>\n");
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace NoteCat;
|
||||||
|
|
||||||
|
use NoteCat\HelloWorldController;
|
||||||
|
use Slim\App;
|
||||||
|
|
||||||
|
class Routes
|
||||||
|
{
|
||||||
|
public static function setRoutes(App $app): void
|
||||||
|
{
|
||||||
|
$app->get('/', HelloWorldController::class . ':hello');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue