From ece717e2060092250f4de0b826882057653a30d8 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 28 Jul 2015 16:45:49 +0200 Subject: [PATCH 1/3] Quick review of 'create framework' tutorial --- create_framework/dependency-injection.rst | 5 --- create_framework/event-dispatcher.rst | 13 ++----- create_framework/front-controller.rst | 8 ----- create_framework/http-foundation.rst | 14 +++----- .../http-kernel-controller-resolver.rst | 2 +- .../http-kernel-httpkernel-class.rst | 8 ++--- .../http-kernel-httpkernelinterface.rst | 35 ++++++++++++++----- create_framework/introduction.rst | 10 +++--- create_framework/routing.rst | 24 +++++-------- create_framework/separation-of-concerns.rst | 14 ++------ create_framework/templating.rst | 5 +-- create_framework/unit-testing.rst | 21 ++++------- 12 files changed, 64 insertions(+), 95 deletions(-) diff --git a/create_framework/dependency-injection.rst b/create_framework/dependency-injection.rst index 39eaae4702e..f5ff56c1b38 100644 --- a/create_framework/dependency-injection.rst +++ b/create_framework/dependency-injection.rst @@ -7,7 +7,6 @@ empty class, you might be tempted to move some code from the front controller to it:: // example.com/src/Simplex/Framework.php - namespace Simplex; use Symfony\Component\Routing; @@ -33,7 +32,6 @@ to it:: The front controller code would become more concise:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -94,7 +92,6 @@ container: Create a new file to host the dependency injection container configuration:: // example.com/src/container.php - use Symfony\Component\DependencyInjection; use Symfony\Component\DependencyInjection\Reference; @@ -147,7 +144,6 @@ it in other object definitions. The front controller is now only about wiring everything together:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -165,7 +161,6 @@ As all the objects are now created in the dependency injection container, the framework code should be the previous simple version:: // example.com/src/Simplex/Framework.php - namespace Simplex; use Symfony\Component\HttpKernel\HttpKernel; diff --git a/create_framework/event-dispatcher.rst b/create_framework/event-dispatcher.rst index d2b062e415b..3964cf5ae46 100644 --- a/create_framework/event-dispatcher.rst +++ b/create_framework/event-dispatcher.rst @@ -34,7 +34,6 @@ To make it work, the framework must dispatch an event just before returning the Response instance:: // example.com/src/Simplex/Framework.php - namespace Simplex; use Symfony\Component\HttpFoundation\Request; @@ -46,9 +45,9 @@ the Response instance:: class Framework { - protected $matcher; - protected $resolver; - protected $dispatcher; + private $matcher; + private $resolver; + private $dispatcher; public function __construct(EventDispatcher $dispatcher, UrlMatcherInterface $matcher, ControllerResolverInterface $resolver) { @@ -85,7 +84,6 @@ Each time the framework handles a Request, a ``ResponseEvent`` event is now dispatched:: // example.com/src/Simplex/ResponseEvent.php - namespace Simplex; use Symfony\Component\HttpFoundation\Request; @@ -118,7 +116,6 @@ The last step is the creation of the dispatcher in the front controller and the registration of a listener for the ``response`` event:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; // ... @@ -197,7 +194,6 @@ the priority to ``-255``:: Let's refactor the code a bit by moving the Google listener to its own class:: // example.com/src/Simplex/GoogleListener.php - namespace Simplex; class GoogleListener @@ -220,7 +216,6 @@ Let's refactor the code a bit by moving the Google listener to its own class:: And do the same with the other listener:: // example.com/src/Simplex/ContentLengthListener.php - namespace Simplex; class ContentLengthListener @@ -259,7 +254,6 @@ information to the dispatcher via the ``getSubscribedEvents()`` method. Have a look at the new version of the ``GoogleListener``:: // example.com/src/Simplex/GoogleListener.php - namespace Simplex; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -277,7 +271,6 @@ look at the new version of the ``GoogleListener``:: And here is the new version of ``ContentLengthListener``:: // example.com/src/Simplex/ContentLengthListener.php - namespace Simplex; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/create_framework/front-controller.rst b/create_framework/front-controller.rst index 3ef47eb618b..212fbb47599 100644 --- a/create_framework/front-controller.rst +++ b/create_framework/front-controller.rst @@ -6,7 +6,6 @@ spice things up a little bit, let's go crazy and add another page that says goodbye:: // framework/bye.php - require_once __DIR__.'/vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -26,7 +25,6 @@ The PHP way of doing the refactoring would probably be the creation of an include file:: // framework/init.php - require_once __DIR__.'/vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -38,7 +36,6 @@ include file:: Let's see it in action:: // framework/index.php - require_once __DIR__.'/init.php'; $input = $request->get('name', 'World'); @@ -49,7 +46,6 @@ Let's see it in action:: And for the "Goodbye" page:: // framework/bye.php - require_once __DIR__.'/init.php'; $response->setContent('Goodbye!'); @@ -76,7 +72,6 @@ routing all client requests to a single PHP script. Such a script might look like the following:: // framework/front.php - require_once __DIR__.'/vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -103,7 +98,6 @@ Such a script might look like the following:: And here is for instance the new ``hello.php`` script:: // framework/hello.php - $input = $request->get('name', 'World'); $response->setContent(sprintf('Hello %s', htmlspecialchars($input, ENT_QUOTES, 'UTF-8'))); @@ -194,7 +188,6 @@ the ``setContent()`` directly from the front controller script:: And the ``hello.php`` script can now be converted to a template:: - get('name', 'World') ?> Hello @@ -202,7 +195,6 @@ And the ``hello.php`` script can now be converted to a template:: We have the first version of our framework:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; diff --git a/create_framework/http-foundation.rst b/create_framework/http-foundation.rst index fcaa6c005b2..9a87109bcec 100644 --- a/create_framework/http-foundation.rst +++ b/create_framework/http-foundation.rst @@ -18,7 +18,6 @@ Even if the "application" we wrote in the previous chapter was simple enough, it suffers from a few problems:: // framework/index.php - $input = $_GET['name']; printf('Hello %s', $input); @@ -27,7 +26,6 @@ First, if the ``name`` query parameter is not defined in the URL query string, you will get a PHP warning; so let's fix it:: // framework/index.php - $input = isset($_GET['name']) ? $_GET['name'] : 'World'; printf('Hello %s', $input); @@ -60,7 +58,6 @@ snippet of PHP code is not natural and feels ugly. Here is a tentative PHPUnit unit test for the above code:: // framework/test.php - class IndexTest extends \PHPUnit_Framework_TestCase { public function testHello() @@ -147,7 +144,6 @@ Now, let's rewrite our application by using the ``Request`` and the ``Response`` classes:: // framework/index.php - require_once __DIR__.'/vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -227,7 +223,7 @@ With the ``Response`` class, you can easily tweak the response:: .. tip:: - To debug a Response, cast it to a string; it will return the HTTP + To debug a response, cast it to a string; it will return the HTTP representation of the response (headers and content). Last but not the least, these classes, like every other class in the Symfony @@ -239,7 +235,7 @@ framework? Even something as simple as getting the client IP address can be insecure:: - if ($myIp == $_SERVER['REMOTE_ADDR']) { + if ($myIp === $_SERVER['REMOTE_ADDR']) { // the client is a known one, so give it some more privilege } @@ -248,7 +244,7 @@ production servers; at this point, you will have to change your code to make it work on both your development machine (where you don't have a proxy) and your servers:: - if ($myIp == $_SERVER['HTTP_X_FORWARDED_FOR'] || $myIp == $_SERVER['REMOTE_ADDR']) { + if ($myIp === $_SERVER['HTTP_X_FORWARDED_FOR'] || $myIp === $_SERVER['REMOTE_ADDR']) { // the client is a known one, so give it some more privilege } @@ -258,7 +254,7 @@ chained proxies):: $request = Request::createFromGlobals(); - if ($myIp == $request->getClientIp()) { + if ($myIp === $request->getClientIp()) { // the client is a known one, so give it some more privilege } @@ -271,7 +267,7 @@ explicitly trust your reverse proxies by calling ``setTrustedProxies()``:: Request::setTrustedProxies(array('10.0.0.1')); - if ($myIp == $request->getClientIp(true)) { + if ($myIp === $request->getClientIp(true)) { // the client is a known one, so give it some more privilege } diff --git a/create_framework/http-kernel-controller-resolver.rst b/create_framework/http-kernel-controller-resolver.rst index 202c7769f63..c0cf260cf0b 100644 --- a/create_framework/http-kernel-controller-resolver.rst +++ b/create_framework/http-kernel-controller-resolver.rst @@ -50,6 +50,7 @@ a Request object. All controller resolvers implement the following interface:: namespace Symfony\Component\HttpKernel\Controller; + // ... interface ControllerResolverInterface { function getController(Request $request); @@ -151,7 +152,6 @@ method is not defined, an argument has no matching attribute, ...). Let's conclude with the new version of our framework:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; diff --git a/create_framework/http-kernel-httpkernel-class.rst b/create_framework/http-kernel-httpkernel-class.rst index ab0663dcbce..be2a2c7a09f 100644 --- a/create_framework/http-kernel-httpkernel-class.rst +++ b/create_framework/http-kernel-httpkernel-class.rst @@ -23,7 +23,6 @@ feedback when a problem arises. Here is the new framework code:: // example.com/src/Simplex/Framework.php - namespace Simplex; use Symfony\Component\HttpKernel\HttpKernel; @@ -35,7 +34,6 @@ Here is the new framework code:: And the new front controller:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -79,13 +77,14 @@ thrown ``Exception`` instance to ease exception manipulation and display. It can take any valid controller as an exception handler, so you can create an ErrorController class instead of using a Closure:: - $listener = new HttpKernel\EventListener\ExceptionListener('Calendar\\Controller\\ErrorController::exceptionAction'); + $listener = new HttpKernel\EventListener\ExceptionListener( + 'Calendar\\Controller\\ErrorController::exceptionAction' + ); $dispatcher->addSubscriber($listener); The error controller reads as follows:: // example.com/src/Calendar/Controller/ErrorController.php - namespace Calendar\Controller; use Symfony\Component\HttpFoundation\Response; @@ -148,7 +147,6 @@ is to convert the controller return value to a proper Response instance, but only if needed:: // example.com/src/Simplex/StringResponseListener.php - namespace Simplex; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/create_framework/http-kernel-httpkernelinterface.rst b/create_framework/http-kernel-httpkernelinterface.rst index f229b5578b0..6ceb87facd9 100644 --- a/create_framework/http-kernel-httpkernelinterface.rst +++ b/create_framework/http-kernel-httpkernelinterface.rst @@ -8,12 +8,18 @@ goal by making our framework implement ``HttpKernelInterface``:: namespace Symfony\Component\HttpKernel; + // ... + interface HttpKernelInterface { /** * @return Response A Response instance */ - function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true); + public function handle( + Request $request, + $type = self::MASTER_REQUEST, + $catch = true + ); } ``HttpKernelInterface`` is probably the most important piece of code in the @@ -26,15 +32,17 @@ Update your framework so that it implements this interface:: // example.com/src/Framework.php // ... - use Symfony\Component\HttpKernel\HttpKernelInterface; class Framework implements HttpKernelInterface { // ... - public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) - { + public function handle( + Request $request, + $type = HttpKernelInterface::MASTER_REQUEST, + $catch = true + ) { // ... } } @@ -47,9 +55,11 @@ PHP; it implements ``HttpKernelInterface`` and wraps another ``HttpKernelInterface`` instance:: // example.com/web/front.php - $framework = new Simplex\Framework($dispatcher, $matcher, $resolver); - $framework = new HttpKernel\HttpCache\HttpCache($framework, new HttpKernel\HttpCache\Store(__DIR__.'/../cache')); + $framework = new HttpKernel\HttpCache\HttpCache( + $framework, + new HttpKernel\HttpCache\Store(__DIR__.'/../cache') + ); $framework->handle($request)->send(); @@ -61,6 +71,7 @@ to cache a response for 10 seconds, use the ``Response::setTtl()`` method:: // example.com/src/Calendar/Controller/LeapYearController.php + // ... public function indexAction(Request $request, $year) { $leapyear = new LeapYear(); @@ -130,6 +141,7 @@ early as possible:: if ($response->isNotModified($request)) { return $response; } + $response->setContent('The computed content of the response'); return $response; @@ -138,7 +150,9 @@ Using HTTP caching is great, but what if you cannot cache the whole page? What if you can cache everything but some sidebar that is more dynamic that the rest of the content? Edge Side Includes (`ESI`_) to the rescue! Instead of generating the whole content in one go, ESI allows you to mark a region of a -page as being the content of a sub-request call:: +page as being the content of a sub-request call: + +.. code-block:: text This is the content of your page @@ -166,7 +180,12 @@ When using complex HTTP caching strategies and/or many ESI include tags, it can be hard to understand why and when a resource should be cached or not. To ease debugging, you can enable the debug mode:: - $framework = new HttpCache($framework, new Store(__DIR__.'/../cache'), new Esi(), array('debug' => true)); + $framework = new HttpKernel\HttpCache\HttpCache( + $framework, + new HttpKernel\HttpCache\Store(__DIR__.'/../cache'), + new HttpKernel\HttpCache\Esi(), + array('debug' => true) + ); The debug mode adds a ``X-Symfony-Cache`` header to each response that describes what the cache layer did: diff --git a/create_framework/introduction.rst b/create_framework/introduction.rst index 1d1bb864639..a69a4fc08d1 100644 --- a/create_framework/introduction.rst +++ b/create_framework/introduction.rst @@ -104,21 +104,21 @@ Instead of creating our framework from scratch, we are going to write the same start with the simplest web application we can think of in PHP:: // framework/index.php - $input = $_GET['name']; printf('Hello %s', $input); If you have PHP 5.4, you can use the PHP built-in server to test this great -application in a browser (``http://localhost:4321/index.php?name=Fabien``). -Otherwise, use your own server (Apache, Nginx, etc.): +application in a browser (``http://localhost:4321/index.php?name=Fabien``): .. code-block:: bash $ php -S 127.0.0.1:4321 -In the next chapter, we are going to introduce the HttpFoundation Component -and see what it brings us. +Otherwise, you can always use your own server (Apache, Nginx, etc.). + +In the :doc:`next chapter `, we are going to +introduce the HttpFoundation Component and see what it brings us. .. _`Symfony`: http://symfony.com/ .. _`Silex`: http://silex.sensiolabs.org/ diff --git a/create_framework/routing.rst b/create_framework/routing.rst index 2d994b4d8f0..b1bbcd0cc6f 100644 --- a/create_framework/routing.rst +++ b/create_framework/routing.rst @@ -5,7 +5,6 @@ Before we start diving into the Routing component, let's refactor our current framework just a little to make templates even more readable:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -34,7 +33,6 @@ As we now extract the request query parameters, simplify the ``hello.php`` template as follows:: - Hello Now, we are in good shape to add new features. @@ -43,13 +41,8 @@ One very important aspect of any website is the form of its URLs. Thanks to the URL map, we have decoupled the URL from the code that generates the associated response, but it is not yet flexible enough. For instance, we might want to support dynamic paths to allow embedding data directly into the URL -instead of relying on a query string: - - # Before - /hello?name=Fabien - - # After - /hello/Fabien +instead of relying on a query string (like ``/hello/Fabien`` instead of +``/hello?name=Fabien``). To support this feature, add the Symfony Routing component as a dependency: @@ -102,21 +95,27 @@ The ``match()`` method takes a request path and returns an array of attributes ``_route`` attribute):: print_r($matcher->match('/bye')); + /* Gives: array ( '_route' => 'bye', ); + */ print_r($matcher->match('/hello/Fabien')); + /* Gives: array ( 'name' => 'Fabien', '_route' => 'hello', ); + */ print_r($matcher->match('/hello')); + /* Gives: array ( 'name' => 'World', '_route' => 'hello', ); + */ .. note:: @@ -132,7 +131,6 @@ The URL matcher throws an exception when none of the routes match:: With this knowledge in mind, let's write the new version of our framework:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -169,15 +167,11 @@ There are a few new things in the code: * Request attributes are extracted to keep our templates simple:: - Hello -* Route configuration has been moved to its own file: - - .. code-block:: php +* Route configuration has been moved to its own file:: // example.com/src/app.php - use Symfony\Component\Routing; $routes = new Routing\RouteCollection(); diff --git a/create_framework/separation-of-concerns.rst b/create_framework/separation-of-concerns.rst index 8eba278c6da..20a429e2bbe 100644 --- a/create_framework/separation-of-concerns.rst +++ b/create_framework/separation-of-concerns.rst @@ -16,7 +16,6 @@ Let's create our very own namespace for our framework: ``Simplex``. Move the request handling logic into its own ``Simplex\\Framework`` class:: // example.com/src/Simplex/Framework.php - namespace Simplex; use Symfony\Component\HttpFoundation\Request; @@ -60,7 +59,6 @@ And update ``example.com/web/front.php`` accordingly:: // example.com/web/front.php // ... - $request = Request::createFromGlobals(); $routes = include __DIR__.'/../src/app.php'; @@ -79,14 +77,10 @@ To wrap up the refactoring, let's move everything but routes definition from For the classes defined under the ``Simplex`` and ``Calendar`` namespaces to be autoloaded, update the ``composer.json`` file: -.. code-block:: javascript +.. code-block:: json { - "require": { - "symfony/http-foundation": "2.5.*", - "symfony/routing": "2.5.*", - "symfony/http-kernel": "2.5.*" - }, + "...": "...", "autoload": { "psr-0": { "Simplex\\": "src/", "Calendar\\": "src/" } } @@ -96,10 +90,9 @@ be autoloaded, update the ``composer.json`` file: For the Composer autoloader to be updated, run ``composer update``. -Move the controller to ``Calendar\\Controller\\LeapYearController``:: +Move the controller to ``Calendar\Controller\LeapYearController``:: // example.com/src/Calendar/Controller/LeapYearController.php - namespace Calendar\Controller; use Symfony\Component\HttpFoundation\Request; @@ -122,7 +115,6 @@ Move the controller to ``Calendar\\Controller\\LeapYearController``:: And move the ``is_leap_year()`` function to its own class too:: // example.com/src/Calendar/Model/LeapYear.php - namespace Calendar\Model; class LeapYear diff --git a/create_framework/templating.rst b/create_framework/templating.rst index 5fa4b4bc468..21dd890979e 100644 --- a/create_framework/templating.rst +++ b/create_framework/templating.rst @@ -17,7 +17,6 @@ Change the template rendering part of the framework to read as follows:: // example.com/web/front.php // ... - try { $request->attributes->add($matcher->match($request->getPathInfo())); $response = call_user_func('render_template', $request); @@ -101,7 +100,6 @@ you can even pass additional arguments to the template:: Here is the updated and improved version of our framework:: // example.com/web/front.php - require_once __DIR__.'/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; @@ -144,7 +142,6 @@ framework does not need to be modified in any way, just create a new ``app.php`` file:: // example.com/src/app.php - use Symfony\Component\Routing; use Symfony\Component\HttpFoundation\Response; @@ -153,7 +150,7 @@ framework does not need to be modified in any way, just create a new $year = date('Y'); } - return 0 == $year % 400 || (0 == $year % 4 && 0 != $year % 100); + return 0 === $year % 400 || (0 === $year % 4 && 0 !== $year % 100); } $routes = new Routing\RouteCollection(); diff --git a/create_framework/unit-testing.rst b/create_framework/unit-testing.rst index 323dfee6ab7..85ab1ae693e 100644 --- a/create_framework/unit-testing.rst +++ b/create_framework/unit-testing.rst @@ -14,17 +14,12 @@ using `PHPUnit`_. Create a PHPUnit configuration file in .. code-block:: xml - - @@ -45,7 +40,6 @@ such interfaces for core objects like the URL matcher and the controller resolver. Modify the framework to make use of them:: // example.com/src/Simplex/Framework.php - namespace Simplex; // ... @@ -70,7 +64,6 @@ resolver. Modify the framework to make use of them:: We are now ready to write our first test:: // example.com/tests/Simplex/Tests/FrameworkTest.php - namespace Simplex\Tests; use Simplex\Framework; @@ -88,7 +81,7 @@ We are now ready to write our first test:: $this->assertEquals(404, $response->getStatusCode()); } - protected function getFrameworkForException($exception) + private function getFrameworkForException($exception) { $matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); $matcher From 613d6bc8438abfd98d91813491595f7bd2c345f0 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 28 Jul 2015 17:03:31 +0200 Subject: [PATCH 2/3] Use underscores in file name --- ...-injection.rst => dependency_injection.rst} | 0 ...ent-dispatcher.rst => event_dispatcher.rst} | 0 ...ont-controller.rst => front_controller.rst} | 0 ...http-foundation.rst => http_foundation.rst} | 0 ...rst => http_kernel_controller_resolver.rst} | 0 ...ss.rst => http_kernel_httpkernel_class.rst} | 0 ...rst => http_kernel_httpkernelinterface.rst} | 0 create_framework/index.rst | 18 +++++++++--------- create_framework/map.rst.inc | 18 +++++++++--------- ...concerns.rst => separation_of_concerns.rst} | 0 .../{unit-testing.rst => unit_testing.rst} | 0 redirection_map | 9 +++++++++ 12 files changed, 27 insertions(+), 18 deletions(-) rename create_framework/{dependency-injection.rst => dependency_injection.rst} (100%) rename create_framework/{event-dispatcher.rst => event_dispatcher.rst} (100%) rename create_framework/{front-controller.rst => front_controller.rst} (100%) rename create_framework/{http-foundation.rst => http_foundation.rst} (100%) rename create_framework/{http-kernel-controller-resolver.rst => http_kernel_controller_resolver.rst} (100%) rename create_framework/{http-kernel-httpkernel-class.rst => http_kernel_httpkernel_class.rst} (100%) rename create_framework/{http-kernel-httpkernelinterface.rst => http_kernel_httpkernelinterface.rst} (100%) rename create_framework/{separation-of-concerns.rst => separation_of_concerns.rst} (100%) rename create_framework/{unit-testing.rst => unit_testing.rst} (100%) diff --git a/create_framework/dependency-injection.rst b/create_framework/dependency_injection.rst similarity index 100% rename from create_framework/dependency-injection.rst rename to create_framework/dependency_injection.rst diff --git a/create_framework/event-dispatcher.rst b/create_framework/event_dispatcher.rst similarity index 100% rename from create_framework/event-dispatcher.rst rename to create_framework/event_dispatcher.rst diff --git a/create_framework/front-controller.rst b/create_framework/front_controller.rst similarity index 100% rename from create_framework/front-controller.rst rename to create_framework/front_controller.rst diff --git a/create_framework/http-foundation.rst b/create_framework/http_foundation.rst similarity index 100% rename from create_framework/http-foundation.rst rename to create_framework/http_foundation.rst diff --git a/create_framework/http-kernel-controller-resolver.rst b/create_framework/http_kernel_controller_resolver.rst similarity index 100% rename from create_framework/http-kernel-controller-resolver.rst rename to create_framework/http_kernel_controller_resolver.rst diff --git a/create_framework/http-kernel-httpkernel-class.rst b/create_framework/http_kernel_httpkernel_class.rst similarity index 100% rename from create_framework/http-kernel-httpkernel-class.rst rename to create_framework/http_kernel_httpkernel_class.rst diff --git a/create_framework/http-kernel-httpkernelinterface.rst b/create_framework/http_kernel_httpkernelinterface.rst similarity index 100% rename from create_framework/http-kernel-httpkernelinterface.rst rename to create_framework/http_kernel_httpkernelinterface.rst diff --git a/create_framework/index.rst b/create_framework/index.rst index b6a70f5e264..342a95960ec 100644 --- a/create_framework/index.rst +++ b/create_framework/index.rst @@ -4,14 +4,14 @@ Create your own PHP Framework .. toctree:: introduction - http-foundation - front-controller + http_foundation + front_controller routing templating - http-kernel-controller-resolver - separation-of-concerns - unit-testing - event-dispatcher - http-kernel-httpkernelinterface - http-kernel-httpkernel-class - dependency-injection + http_kernel_controller_resolver + separation_of_concerns + unit_testing + event_dispatcher + http_kernel_httpkernelinterface + http_kernel_httpkernel_class + dependency_injection diff --git a/create_framework/map.rst.inc b/create_framework/map.rst.inc index 574c0f5e769..0f3bc41cbab 100644 --- a/create_framework/map.rst.inc +++ b/create_framework/map.rst.inc @@ -1,12 +1,12 @@ * :doc:`/create_framework/introduction` -* :doc:`/create_framework/http-foundation` -* :doc:`/create_framework/front-controller` +* :doc:`/create_framework/http_foundation` +* :doc:`/create_framework/front_controller` * :doc:`/create_framework/routing` * :doc:`/create_framework/templating` -* :doc:`/create_framework/http-kernel-controller-resolver` -* :doc:`/create_framework/separation-of-concerns` -* :doc:`/create_framework/unit-testing` -* :doc:`/create_framework/event-dispatcher` -* :doc:`/create_framework/http-kernel-httpkernelinterface` -* :doc:`/create_framework/http-kernel-httpkernel-class` -* :doc:`/create_framework/dependency-injection` +* :doc:`/create_framework/http_kernel_controller_resolver` +* :doc:`/create_framework/separation_of_concerns` +* :doc:`/create_framework/unit_testing` +* :doc:`/create_framework/event_dispatcher` +* :doc:`/create_framework/http_kernel_httpkernelinterface` +* :doc:`/create_framework/http_kernel_httpkernel_class` +* :doc:`/create_framework/dependency_injection` diff --git a/create_framework/separation-of-concerns.rst b/create_framework/separation_of_concerns.rst similarity index 100% rename from create_framework/separation-of-concerns.rst rename to create_framework/separation_of_concerns.rst diff --git a/create_framework/unit-testing.rst b/create_framework/unit_testing.rst similarity index 100% rename from create_framework/unit-testing.rst rename to create_framework/unit_testing.rst diff --git a/redirection_map b/redirection_map index 2abbaf55500..959f59b9b92 100644 --- a/redirection_map +++ b/redirection_map @@ -29,3 +29,12 @@ /cookbook/configuration/pdo_session_storage /cookbook/doctrine/pdo_session_storage /cookbook/configuration/mongodb_session_storage /cookbook/doctrine/mongodb_session_storage /cookbook/service_container/event_listener /cookbook/event_dispatcher/event_listener +/create_framework/http_foundation /create_framework/http-foundation +/create_framework/front_controller /create_framework/front-controller +/create_framework/http_kernel_controller_resolver /create_framework/http-kernel-controller-resolver +/create_framework/separation_of_concerns /create_framework/separation-of-concerns +/create_framework/unit_testing /create_framework/unit-testing +/create_framework/event_dispatcher /create_framework/event-dispatcher +/create_framework/http_kernel_httpkernelinterface /create_framework/http-kernel-httpkernelinterface +/create_framework/http_kernel_httpkernel_class /create_framework/http-kernel-httpkernel-class +/create_framework/dependency_injection /create_framework/dependency-injection From 3f8e61d9658e295cde877e6b0c37f8faadd444ee Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 19 Dec 2015 14:15:27 +0100 Subject: [PATCH 3/3] Apply suggestions from the comments --- .../http_kernel_httpkernelinterface.rst | 1 - create_framework/separation_of_concerns.rst | 4 ++-- create_framework/unit_testing.rst | 2 +- redirection_map | 18 +++++++++--------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/create_framework/http_kernel_httpkernelinterface.rst b/create_framework/http_kernel_httpkernelinterface.rst index 6ceb87facd9..8f64dd41376 100644 --- a/create_framework/http_kernel_httpkernelinterface.rst +++ b/create_framework/http_kernel_httpkernelinterface.rst @@ -9,7 +9,6 @@ goal by making our framework implement ``HttpKernelInterface``:: namespace Symfony\Component\HttpKernel; // ... - interface HttpKernelInterface { /** diff --git a/create_framework/separation_of_concerns.rst b/create_framework/separation_of_concerns.rst index 20a429e2bbe..9340e3b6519 100644 --- a/create_framework/separation_of_concerns.rst +++ b/create_framework/separation_of_concerns.rst @@ -82,13 +82,13 @@ be autoloaded, update the ``composer.json`` file: { "...": "...", "autoload": { - "psr-0": { "Simplex\\": "src/", "Calendar\\": "src/" } + "psr-4": { "": "src/" } } } .. note:: - For the Composer autoloader to be updated, run ``composer update``. + For the Composer autoloader to be updated, run ``composer dump-autoload``. Move the controller to ``Calendar\Controller\LeapYearController``:: diff --git a/create_framework/unit_testing.rst b/create_framework/unit_testing.rst index 85ab1ae693e..580b1d7e428 100644 --- a/create_framework/unit_testing.rst +++ b/create_framework/unit_testing.rst @@ -16,7 +16,7 @@ using `PHPUnit`_. Create a PHPUnit configuration file in