My names is ....
I work for FFW (Formely knonw as Blink reaction & Propeople
@erikaheidi http://erikaheidi.com/blog/celebrating-php-twenty-years
This session name is "The New PHP", WAT, wait, but PHP is already 20 years old.
Maybe, the not so New PHP could be a better session title.
The most resent PHP version is 5.6.9 and the next major version will be 7.0.
Because we all know 7 came after 5 right.
PHP 7 will be released before the end of 2015.
Probably before Drupal 8.
Another major release happening by the end of this year and also probably before Drupal 8 too is Symfony 3.
And according to drupalreleasedate.com Drupal 8 will be release on.
Stop talking about promises and focus on taling about what is already out and we can take advantage of.
We can define Symfony as a group of decoupled components and other stand alone libraries.
And then based on these components Symfony is a full-stack web framework.
Does anyone knows which aproach is Drupal 8 using ?
Drupal is not using Symfony as a full stack framework.
Drupal is only taking advantage of some specific components.
The way to be more productive is to write less code and to reuse more code.
Sharing is how Open Source works
The more code you have, the more places there are for bugs to hide.
The more code you have, the more code you need to maintain.
http://www.php-fig.org
Some people say is like the United Nations of the PHP, but I am not sure if that is a good or bad reference.
The idea behind this group is to group the project representatives of different frameworks to talk about the similitudes between the projects and find ways to work together.
http://getcomposer.org/
Composer is a Dependency Manager for PHP.
It allows you to declare the dependent libraries your project needs and take care of downloading.
Probably this library you are requiring is also dependent on another library or libraries, well worry not composer will resolve that too.
$ curl -sS https://getcomposer.org/installer | php $ chmod +x composer.phar $ mv composer.phar /usr/local/bin/composer
$ composer init $ composer search faker $ composer show fzaninotto/faker $ composer require fzaninotto/faker:v1.3.0
/* composer.json */ { "require": { "fzaninotto/faker": "v1.3.0" } } $ composer install $ composer update $ composer show --installed
Awesome now you know how to handle, third party dependencies in every moder PHP framework but not Drupal.
Because ...
$ drush dl composer_manager $ drush en -y composer_manager $ drush composer-manager-init
http://drupal.org/project/composer_manager
As a friend of mine Luis Cordova a developer from Perú, but this is drupal/drupal and it won't be that easy.
And I need to say he is maybe right, seems like we use to make thing harder or maybe not hareder, just different "Drupalisims anyone"
We already have drush why not use for this purpose ...
Where are those libraries definitions stored.
All those libraries are stored at Packagist, the PHP archivist.
You may be wonder why having an standard mechanisim for sharing libraries is so important.
We already have drush and drush help us to download modules.
Remeber the copy-pasta era, where you just copy/paste code from a geocities page you found atfer searching using yahoo or altavista.
Oh boy ... the good old days.
Then you learn the cool kids those days used to visit phpclasses.org to download libraries.
Fortunely those days are over.
In every web application regardless of the used language or framework.
You are probably working with PHP using Symfony, Silex, Drupal or Laravel or may you are working with Pyhton using Django or Flask, how about Ruby using Rails or Java developing with Scala.
Your only goal as a web developer is to properly understand the incoming HTTP Request in order to build and return and appropiate HTTP response.
The client sends an HTTP request. When I said client this could be a web-site, mobile app or even an application runing from the terminal.
Now as I mentioned before it is your responsability to build a proper response, this will be based on what the client is asking for, this could be anything form a HTML page to JSON, XML even and attachment or a multimedia file as well.
Well the flow looks like this.
Symfony/Silex/Drupal use the front controller design-pattern. This mean every single request is routed from a PHP file app.php or app_ENV.php in the case of Symfony and index.php if using Silex or Drupal. The main goal of the front controller is to bootstrap your Application and performing the global initialization of required objects.
Also takes care of extracting information form the requested URL about the path and match this on the routing system and then execute the proper Controller.
We can define a Route as a map from a URL to a controller.
Is in the route definition where where we especify the path for a resource and the controller that will be executed.
Now that I have been mentioning the Controller
A Controller is a method or call-back that takes information from the HTTP request object and based on the implemented code contructs and returns a proper HTTP response.
Lets see how these two looks in code.
hello_name: path: /hello/{name} defaults: { _controller: AppBundle:Hello:index }
namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Response; class HelloController { public function indexAction($name) { return new Response('Hello '.$name); } }
In order to add a new route and the matching controller in Symfony we need to declare this on the Bundle routing.yml file.
Within this file, the Route name, the matching Path and the executed controller must be given.
A Controller class must be added this class must containing a method that returns the proper HTTP response.
Remeber what I told you about Symfony-isms. If you pay attention to the _controller: key value it does not include the words Controller for the Class and Action for the method, what it means for this case we are using a shortcut not the fully qualified path name.
require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get('/hello/{name}', function($name) { return 'Hello '.$name; }); $app->run();
Silex it is a Microframework and by default is more simple, what you see here is a complete Silex aplication.
The way I am registering a new route in this code is:
Creating a new instance of the Silex/Application class and using the get method on the app object. You may also use post/match methods depending on your needs.
The get() method it's exepecting two arguments the first is the path of the resource and the second is a closure or anonymous function, from there we can return a String
What if my application need to scale and grow.
$app->get( '/hello-controller/{name}', 'DrupalCampSP\Controller\HelloController::indexAction' );
namespace DrupalCampSP\Controller; use Symfony\Component\HttpFoundation\Response; class HelloController { public function indexAction($name) { return new Response('Hello '.$name); } }
One common misconception about Silex and microframeworks in general is that they are only for small, simple app and APIs. Which is not true
When you need to scale your Silex app, you need to organize and structure your code into different file classes.
For this example a new Controller class must be created with a method returning a HTTP Response object. Yeah the exact same code we use on the Symfony example. Do you see where I am going.
In order to register this ControllerClass we replaced the second argument passed to the get() method and use the fully qualified path name and the methodName separated by double ::
As you can see here, we are using Controller and Action.
drupalcampsp.hello_controller: path: 'hello/{name}' defaults: _content: '\Drupal\drupalcampsp\Controller\HelloController::index'
namespace Drupal\drupalcampsp\Controller; class HelloController { public function index($name) { return [ '#type' => 'markup', '#markup' => $this->t('Hello @name!', ['@name' => $name]) ]; } }
In order to achieve this in Drupal we declares a new route at the MODULE_NAME.routing.yml file, adding the Route name and Path.
But instead of using _controller we will replace it with _content 'That was a Drupal-isms' and point to the Controller the same way we did it on Silex, we will be using the fully qualified path name plus :: methodName.
A new Controller Class must be added with a method that could return a String.
As you can see it's kinda a mix of Symfony & Silex but the final result is pretty similar and we shared a lot of concepts and code.
https://github.com/symfony/Console
https://github.com/KnpLabs/ConsoleServiceProvider