commit 901fbd61a3538caac50a284ead82b6907eebb618 Author: Alejandro Celaya Date: Sun Apr 10 09:38:07 2016 +0200 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..397e34a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +composer.lock +vendor/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..4d90fc81 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +sudo: false + +language: php + +matrix: + fast_finish: true + include: + - php: 5.5 + - php: 5.6 + env: + - EXECUTE_CS_CHECK=true + - php: 7 + - php: hhvm + allow_failures: + - php: hhvm + +before_install: + - composer self-update + +install: + - travis_retry composer install --no-interaction --ignore-platform-reqs --prefer-source --no-scripts + +script: + - composer test + - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then composer cs ; fi + +notifications: + email: true diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..0aaee0a0 --- /dev/null +++ b/composer.json @@ -0,0 +1,52 @@ +{ + "name": "acelaya/url-shortener", + "type": "project", + "homepage": "https://github.com/acelaya/url-shortener", + "license": "MIT", + "authors": [ + { + "name": "Alejandro Celaya ALastrué", + "homepage": "http://www.alejandrocelaya.com", + "email": "alejandro@alejandrocelaya.com" + } + ], + "require": { + "php": "^5.5 || ^7.0", + "zendframework/zend-expressive": "^1.0", + "zendframework/zend-expressive-helpers": "^2.0", + "zendframework/zend-stdlib": "^2.7", + "zendframework/zend-expressive-aurarouter": "^1.0", + "zendframework/zend-servicemanager": "^3.0", + "zendframework/zend-expressive-twigrenderer": "^1.0", + "acelaya/expressive-slim-router": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8", + "squizlabs/php_codesniffer": "^2.3", + "roave/security-advisories": "dev-master", + "filp/whoops": "^2.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/App/", + "Acelaya\\UrlShortener\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "AppTest\\": "tests/AppTest/", + "AcelayaTest\\UrlShortener\\": "tests" + } + }, + "scripts": { + "check": [ + "@cs", + "@test" + ], + "cs": "phpcs", + "cs-fix": "phpcbf", + "serve": "php -S 0.0.0.0:8000 -t public/", + "test": "phpunit", + "pretty-test": "phpunit -c tests/phpunit.xml --coverage-html build/coverage" + } +} diff --git a/config/autoload/.gitignore b/config/autoload/.gitignore new file mode 100644 index 00000000..1a83fda6 --- /dev/null +++ b/config/autoload/.gitignore @@ -0,0 +1,2 @@ +local.php +*.local.php diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist new file mode 100644 index 00000000..75c8b9c2 --- /dev/null +++ b/config/autoload/local.php.dist @@ -0,0 +1,7 @@ + true, + + 'config_cache_enabled' => false, +]; diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php new file mode 100644 index 00000000..9f5f2d63 --- /dev/null +++ b/config/autoload/middleware-pipeline.global.php @@ -0,0 +1,30 @@ + [ + 'always' => [ + 'middleware' => [ + Helper\ServerUrlMiddleware::class, + ], + 'priority' => 10000, + ], + + 'routing' => [ + 'middleware' => [ + ApplicationFactory::ROUTING_MIDDLEWARE, + Helper\UrlHelperMiddleware::class, + ApplicationFactory::DISPATCH_MIDDLEWARE, + ], + 'priority' => 1, + ], + + 'error' => [ + 'middleware' => [], + 'error' => true, + 'priority' => -10000, + ], + ], +]; diff --git a/config/autoload/routes.global.php b/config/autoload/routes.global.php new file mode 100644 index 00000000..83650c5c --- /dev/null +++ b/config/autoload/routes.global.php @@ -0,0 +1,17 @@ + [ + [ + 'name' => 'home', + 'path' => '/', + 'middleware' => function ($req, $resp) { + $resp->getBody()->write('Hello world'); + return $resp; + }, + 'allowed_methods' => ['GET'], + ], + ], + +]; diff --git a/config/autoload/services.global.php b/config/autoload/services.global.php new file mode 100644 index 00000000..8f2a8816 --- /dev/null +++ b/config/autoload/services.global.php @@ -0,0 +1,29 @@ + [ + 'invokables' => [ + Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class, + Router\RouterInterface::class => Router\AuraRouter::class, + ], + 'factories' => [ + Application::class => Container\ApplicationFactory::class, + + // Url helpers + Helper\UrlHelper::class => Helper\UrlHelperFactory::class, + Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class, + Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class, + + // View + 'Zend\Expressive\FinalHandler' => Container\TemplatedErrorHandlerFactory::class, + Template\TemplateRendererInterface::class => Zend\Expressive\Twig\TwigRendererFactory::class, + ], + ], + +]; diff --git a/config/autoload/templates.global.php b/config/autoload/templates.global.php new file mode 100644 index 00000000..b0a57959 --- /dev/null +++ b/config/autoload/templates.global.php @@ -0,0 +1,16 @@ + [ + 'extension' => 'html.twig', + ], + + 'twig' => [ + 'cache_dir' => 'data/cache/twig', + 'extensions' => [ + // extension service names or instances + ], + ], + +]; diff --git a/config/autoload/templates.local.php.dist b/config/autoload/templates.local.php.dist new file mode 100644 index 00000000..13d4a711 --- /dev/null +++ b/config/autoload/templates.local.php.dist @@ -0,0 +1,9 @@ + [ + 'cache_dir' => false, + ], + +]; diff --git a/config/autoload/zend-expressive.global.php b/config/autoload/zend-expressive.global.php new file mode 100644 index 00000000..db5e3f38 --- /dev/null +++ b/config/autoload/zend-expressive.global.php @@ -0,0 +1,14 @@ + false, + + 'config_cache_enabled' => false, + + 'zend-expressive' => [ + 'error_handler' => [ + 'template_404' => 'error/404.html.twig', + 'template_error' => 'error/error.html.twig', + ], + ], +]; diff --git a/config/config.php b/config/config.php new file mode 100644 index 00000000..a5446be7 --- /dev/null +++ b/config/config.php @@ -0,0 +1,35 @@ +configureServiceManager($container); + +// Inject config +$container->setService('config', $config); + +return $container; diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..51649659 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,23 @@ + + + Coding standard + + + + + + + + + + + + + + + + src + tests + config + public/index.php + diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..bb69885f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + ./test + + + + + + src + + + diff --git a/public/index.php b/public/index.php new file mode 100644 index 00000000..8324c8d5 --- /dev/null +++ b/public/index.php @@ -0,0 +1,11 @@ +get(\Zend\Expressive\Application::class); +$app->run(); diff --git a/templates/app/home-page.html.twig b/templates/app/home-page.html.twig new file mode 100644 index 00000000..fc793c1e --- /dev/null +++ b/templates/app/home-page.html.twig @@ -0,0 +1,113 @@ +{% extends '@layout/default.html.twig' %} + +{% block title %}Home{% endblock %} + +{% block content %} +
+

Welcome to zend-expressive

+

+ Congratulations! You have successfully installed the + zend-expressive skeleton application. + This skeleton can serve as a simple starting point for you to begin building your application. +

+

+ Expressive builds on zend-stratigility to provide a minimalist PSR-7 middleware framework for PHP. +

+
+ +
+
+

+ + Agile & Lean + +

+

+ Expressive is fast, small and perfect for rapid application development, prototyping and api's. You decide how you + extend it and choose the best packages from major framework or standalone projects. +

+
+ +
+

+ + HTTP Messages + +

+

+ HTTP messages are the foundation of web development. Web browsers and HTTP clients such as cURL create + HTTP request messages that are sent to a web server, which provides an HTTP response message. + Server-side code receives an HTTP request message, and returns an HTTP response message. +

+
+ +
+

+ + Middleware + +

+

+ Middleware is code that exists between the request and response, and which can take the incoming + request, perform actions based on it, and either complete the response or pass delegation on to the + next middleware in the queue. Your application is easily extended with custom middleware created by + yourself or others. +

+
+
+ +
+
+

+ + Containers + +

+

+ Expressive promotes and advocates the usage of Dependency Injection/Inversion of Control containers + when writing your applications. Expressive supports multiple containers which typehints against + container-interop. +

+
+ +
+

+ + Routers + +

+

+ One fundamental feature of zend-expressive is that it provides mechanisms for implementing dynamic + routing, a feature required in most modern web applications. Expressive ships with multiple adapters. +

+ {% if routerName is defined %} +

+ + Get started with {{ routerName }}. + +

+ {% endif %} +
+ +
+

+ + Templating + +

+

+ By default, no middleware in Expressive is templated. We do not even provide a default templating + engine, as the choice of templating engine is often very specific to the project and/or organization. + However, Expressive does provide abstraction for templating, which allows you to write middleware that + is engine-agnostic. +

+ {% if templateName is defined %} +

+ + Get started with {{ templateName }}. + +

+ {% endif %} +
+
+{% endblock %} diff --git a/templates/error/404.html.twig b/templates/error/404.html.twig new file mode 100644 index 00000000..7b4e363e --- /dev/null +++ b/templates/error/404.html.twig @@ -0,0 +1,13 @@ +{% extends 'layout/default.html.twig' %} + +{% block title %}404 Not Found{% endblock %} + +{% block content %} +

Oops!

+

This is awkward.

+

We encountered a 404 Not Found error.

+

+ You are looking for something that doesn't exist or may have moved. Check out one of the links on this page + or head back to Home. +

+{% endblock %} diff --git a/templates/error/error.html.twig b/templates/error/error.html.twig new file mode 100644 index 00000000..c9b66893 --- /dev/null +++ b/templates/error/error.html.twig @@ -0,0 +1,15 @@ +{% extends 'layout/default.html.twig' %} + +{% block title %}{{ status }} {{ reason }}{% endblock %} + +{% block content %} +

Oops!

+

This is awkward.

+

We encountered a {{ status }} {{ reason }} error.

+ {% if status == 404 %} +

+ You are looking for something that doesn't exist or may have moved. Check out one of the links on this page + or head back to Home. +

+ {% endif %} +{% endblock %} diff --git a/templates/layout/default.html.twig b/templates/layout/default.html.twig new file mode 100644 index 00000000..163e6437 --- /dev/null +++ b/templates/layout/default.html.twig @@ -0,0 +1,77 @@ + + + + + + {% block title %}{% endblock %} - zend-expressive + + + + + {% block stylesheets %}{% endblock %} + + +
+ +
+ +
+
+ {% block content %}{% endblock %} +
+
+ + + + + + {% block javascript %}{% endblock %} + +