* initial commit

This commit is contained in:
Danyi Dávid
2016-07-31 20:47:25 +02:00
commit f3939bbd13
62 changed files with 6827 additions and 0 deletions

2
config/autoload/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
local.php
*.local.php

View File

@@ -0,0 +1,26 @@
<?php
use Zend\Expressive\Application;
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
return [
// Provides application-wide services.
// We recommend using fully-qualified class names whenever possible as
// service names.
'dependencies' => [
// Use 'invokables' for constructor-less services, or services that do
// not require arguments to the constructor. Map a service name to the
// class name.
'invokables' => [
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
Application::class => ApplicationFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
'doctrine.entity_manager.orm_default' => \ContainerInteropDoctrine\EntityManagerFactory::class,
'doctrine.hydrator' => \App\Hydrator\DoctrineObjectFactory::class,
],
],
];

View File

@@ -0,0 +1,19 @@
<?php
return [
'doctrine' => [
'driver' => [
'orm_default' => [
'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class,
'drivers' => [
'App\Entity' => 'my_entity',
],
],
'my_entity' => [
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/App/Entity',
],
],
],
];

View File

@@ -0,0 +1,14 @@
<?php
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'params' => [
'url' => 'mysqli://user:passwd@host/database',
'charset' => 'UTF8',
],
],
],
],
];

View File

@@ -0,0 +1,21 @@
<?php
return [
'dependencies' => [
'invokables' => [
'Zend\Expressive\Whoops' => Whoops\Run::class,
'Zend\Expressive\WhoopsPageHandler' => Whoops\Handler\PrettyPageHandler::class,
],
'factories' => [
'Zend\Expressive\FinalHandler' => Zend\Expressive\Container\WhoopsErrorHandlerFactory::class,
],
],
'whoops' => [
'json_exceptions' => [
'display' => true,
'show_trace' => true,
'ajax_only' => true,
],
],
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'debug' => true,
'config_cache_enabled' => false,
];

View File

@@ -0,0 +1,69 @@
<?php
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
return [
'dependencies' => [
'factories' => [
Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class,
Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class,
],
],
// This can be used to seed pre- and/or post-routing middleware
'middleware_pipeline' => [
// An array of middleware to register. Each item is of the following
// specification:
//
// [
// Required:
// 'middleware' => 'Name or array of names of middleware services and/or callables',
// Optional:
// 'path' => '/path/to/match', // string; literal path prefix to match
// // middleware will not execute
// // if path does not match!
// 'error' => true, // boolean; true for error middleware
// 'priority' => 1, // int; higher values == register early;
// // lower/negative == register last;
// // default is 1, if none is provided.
// ],
//
// While the ApplicationFactory ignores the keys associated with
// specifications, they can be used to allow merging related values
// defined in multiple configuration files/locations. This file defines
// some conventional keys for middleware to execute early, routing
// middleware, and error middleware.
'always' => [
'middleware' => [
// Add more middleware here that you want to execute on
// every request:
// - bootstrapping
// - pre-conditions
// - modifications to outgoing responses
Helper\ServerUrlMiddleware::class,
],
'priority' => 10000,
],
'routing' => [
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
Helper\UrlHelperMiddleware::class,
// Add more middleware here that needs to introspect the routing
// results; this might include:
// - route-based authentication
// - route-based validation
// - etc.
ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [
// Add error middleware here.
],
'error' => true,
'priority' => -10000,
],
],
];

View File

@@ -0,0 +1,62 @@
<?php
return [
'dependencies' => [
'invokables' => [
Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouter::class,
App\Action\PingAction::class => App\Action\PingAction::class,
],
'factories' => [
App\Action\HomePageAction::class => App\Action\HomePageFactory::class,
App\Action\Article\ListAction::class => App\Action\Article\ListFactory::class,
App\Action\Article\GetAction::class => App\Action\Article\GetFactory::class,
App\Action\Article\PostAction::class => App\Action\Article\PostFactory::class,
App\Action\Article\PutAction::class => App\Action\Article\PutFactory::class,
App\Action\Article\DeleteAction::class => App\Action\Article\DeleteFactory::class,
],
],
'routes' => [
[
'name' => 'home',
'path' => '/',
'middleware' => App\Action\HomePageAction::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'api.article.list',
'path' => '/api/article',
'middleware' => App\Action\Article\ListAction::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'api.article.get',
'path' => '/api/article/{id:\d+}',
'middleware' => App\Action\Article\GetAction::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'api.article.add',
'path' => '/api/article',
'middleware' => App\Action\Article\PostAction::class,
'allowed_methods' => ['POST'],
],
[
'name' => 'api.article.update',
'path' => '/api/article/{id:\d+}',
'middleware' => App\Action\Article\PutAction::class,
'allowed_methods' => ['PUT'],
],
[
'name' => 'api.article.delete',
'path' => '/api/article/{id:\d+}',
'middleware' => App\Action\Article\DeleteAction::class,
'allowed_methods' => ['DELETE'],
],
[
'name' => 'api.ping',
'path' => '/api/ping',
'middleware' => App\Action\PingAction::class,
'allowed_methods' => ['GET'],
],
],
];

View File

@@ -0,0 +1,14 @@
<?php
return [
'debug' => false,
'config_cache_enabled' => false,
'zend-expressive' => [
'error_handler' => [
'template_404' => 'error::404',
'template_error' => 'error::error',
],
],
];

35
config/config.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Glob;
/**
* Configuration files are loaded in a specific order. First ``global.php``, then ``*.global.php``.
* then ``local.php`` and finally ``*.local.php``. This way local settings overwrite global settings.
*
* The configuration can be cached. This can be done by setting ``config_cache_enabled`` to ``true``.
*
* Obviously, if you use closures in your config you can't cache it.
*/
$cachedConfigFile = 'data/cache/app_config.php';
$config = [];
if (is_file($cachedConfigFile)) {
// Try to load the cached config
$config = include $cachedConfigFile;
} else {
// Load configuration from autoload path
foreach (Glob::glob('config/autoload/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) {
$config = ArrayUtils::merge($config, include $file);
}
// Cache config if enabled
if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) {
file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';');
}
}
// Return an ArrayObject so we can inject the config as a service in Aura.Di
// and still use array checks like ``is_array``.
return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);

16
config/container.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
// Load configuration
$config = require __DIR__ . '/config.php';
// Build container
$container = new ServiceManager();
(new Config($config['dependencies']))->configureServiceManager($container);
// Inject config
$container->setService('config', $config);
return $container;