Anzeige
Anzeige

Más contenido relacionado

Anzeige

Más de Wong Hoi Sing Edison(20)

Anzeige

[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?

  1. Hong Kong Drupal User Group (HKDUG) What's News in PHP? BarCamp Hong Kong 2016 2016 Dec 10th
  2. Edison Wong ● 2005 - Drupal Developer & Contributor – https://drupal.org/user/33940 ● 2008 - HKDUG Co-founder – https://groups.drupal.org/drupalhk ● 2010 - CEO, PantaRei Design – hswong3i@pantarei-design.com
  3. PantaRei Design ● Everything Changes and Nothing Remains Still ● Reinvent Enterprise with Open Source Software and Cloud Computing ● Hong Kong based FOSS service provider – Content Management System (CMS) with Drupal – Cloud Hosting Solution with Amazon Web Services (AWS) – Team collaborate solution with Atlassian ● Business Partner with industry leaders – 2012, AWS Consulting Partner – 2013, Acquia Partner – 2013, Atlassian Experts – 2014, Rackspace Hosting Partner ● http://pantarei-design.com
  4. Hong Kong Drupal User Group ● The Hong Kong Drupal User Group are open to everyone with an interest in Drupal and are a great opportunity to learn more about what Drupal can do and what folks are building with it. ● Drupal is a free software package that allows you to easily organize, manage and publish your content, with an endless variety of customization. – Event organizing: http://www.meetup.com/drupalhk – Technological discussion: https://groups.drupal.org/drupalhk – Business connection: http://www.linkedin.com/groups/?gid=6644792 – General sharing: https://www.facebook.com/groups/drupalhk
  5. Outline ● PHP 7.1 ● PHP-FIG ● Composer ● Symfony 3.2 ● Drupal 8.2
  6. PHP 7.1 ● PHP 7.1 is released on 2016 Dec 01th ● PHP 7 is up to twice as fast as PHP 5.6 ● PHP 7.1.0 comes with numerous improvements and new features such as – Nullable types – Void return type – Iterable pseudo-type – Class constant visiblity modifiers – Square bracket syntax for list() and the ability to specify keys in list() – Catching multiple exceptions types – Many more features and changes… ● http://php.net/archive/2016.php#id2016-12-01-3
  7. Class constant visiblity modifiers <?php class Token { // Constants default to public const PUBLIC_CONST = 0; // Constants then also can have a defined visibility private const PRIVATE_CONST = 0; protected const PROTECTED_CONST = 0; public const PUBLIC_CONST_TWO = 0; //Constants can only have one visibility declaration list private const FOO = 1, BAR = 2; }
  8. Square bracket syntax for array destructuring assignment <?php // The two lines in each of the following pairs are equivalent to each other list($a, $b, $c) = array(1, 2, 3); [$a, $b, $c] = [1, 2, 3]; list("a" => $a, "b" => $b, "c" => $c) = array("a" => 1, "b" => 2, "c" => 3); ["a" => $a, "b" => $b, "c" => $c] = ["a" => 1, "b" => 2, "c" => 3]; list($a, $b) = array($b, $a); [$a, $b] = [$b, $a];
  9. Allow specifying keys in list() <?php list( CURLOPT_GET => $isGet, CURLOPT_POST => $isPost, CURLOPT_URL => $url ) = $curlOptions; $points = [ ["x" => 1, "y" => 2], ["x" => 2, "y" => 1] ]; list(list("x" => $x1, "y" => $y1), list("x" => $x2, "y" => $y2)) = $points; $points = [ "first" => [1, 2], "second" => [2, 1] ]; list("first" => list($x1, $y1), "second" => list($x2, $y2)) = $points;
  10. Catching Multiple Exception Types <?php try { // Some code... } catch (ExceptionType1 | ExceptionType2 $e) { // Code to handle the exception } catch (Exception $e) { // ... }
  11. PHP-FIG ● The FIG stands for Framework Interoperability Group. The name until recently was “PHP Standards Group” but this was somewhat inaccurate of the intentions of the group ● http://www.php-fig.org/
  12. Accepted PSR  PSR-1: Basic Coding Standard  PSR-2: Coding Style Guide  PSR-3: Logger Interface  PSR-4: Autoloader  PSR-6: Caching Interface  PSR-7: HTTP message interfaces  PSR-13: Link definition interfaces
  13. PSR-4: Autoloader  This PSR describes a specification for autoloading classes from file paths, e.g. – Fully Qualified Class Name ● SymfonyCoreRequest – Namespace Prefix ● SymfonyCore – Base Directory ● ./vendor/Symfony/Core/ – Resulting File Path ● ./vendor/Symfony/Core/Request.php
  14. Composer ● Composer is a tool for dependency management in PHP ● It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. ● https://getcomposer.org/
  15. Installation  php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"  php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195c ad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d' ) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"  php composer-setup.php  php -r "unlink('composer-setup.php');"
  16. composer.json { "require": { "monolog/monolog": "1.0.*" } }
  17. Basic usage  composer install  composer update
  18. Autoloading  For libraries that specify autoload information, Composer generates a vendor/autoload.php file. You can simply include this file and you will get autoloading for free – require __DIR__ . '/vendor/autoload.php'; – $log = new MonologLogger('name'); – $log->pushHandler(new MonologHandlerStreamHandler('app.log', MonologLogger::WARNING)); – $log->addWarning('Foo');  Composer also support PSR-4 autoloading
  19. Symfony 3.2 ● Symfony 3.2 is released on 2016 Nov 30th ● 150+ new features in this releases in total, e.g. – DX (Experience *Exceptional*) improvements – Runtime Environment Variables – Web Debug Toolbar and Profiler Improvements – CSV and YAML encoders for Serializer – Cache improvements – Firewall config class and profiler – Unicode routing support ● http://symfony.com/blog/symfony-3-2-0-released
  20. Installation  composer create-project symfony/framework-standard-edition my_project_name  cd my_project_name/  php bin/console server:run  http://symfony.com/doc/current/setup.html
  21. Creating a Page: Route and Controller // src/AppBundle/Controller/LuckyController.php namespace AppBundleController; use SensioBundleFrameworkExtraBundleConfigurationRoute; use SymfonyComponentHttpFoundationResponse; class LuckyController { /** * @Route("/lucky/number") */ public function numberAction() { $number = mt_rand(0, 100); return new Response( '<html><body>Lucky number: '.$number.'</body></html>' ); } }
  22. Drupal 8.2 ● Drupal 8.2.4 is released on 2016 Dec 08th ● As of Drupal 8.0, Drupal has replaced several fundamental pieces with fresh components from Symfony2 ● As of Drupal 8.1, Drupal core directly uses Composer to manage dependencies ● Drupal 8.2 introduce numbers of new features – Easier to place and configure blocks on pages – Content moderation now included – Support for date ranges – Site building, content authoring, and administrative improvements – Platform features for web services ● https://www.drupal.org/project/drupal/releases/8.2.4
  23. Install with Composer ● composer create-project --stability dev --no- interaction drustack/framework-standard- edition:develop drustack ● https://github.com/drustack/drustack-standa rd ● https://github.com/drustack/drustack-stand ard/blob/develop/composer.json
  24. Configure Repositories { "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/8" }, { "package": { "dist": { "type": "zip", "url": "https://github.com/twbs/bootstrap/releases/download/v3.3.7/bootstrap-3.3.7-dist.zip" }, "name": "twbs/bootstrap", "require": { "composer/installers": "~1.0" }, "type": "drupal-library", "version": "3.3.7" }, "type": "package" } } }
  25. Control the installer target folder { "extra": { "installer-paths": { "web/core": [ "type:drupal-core" ], "web/libraries/{$name}": [ "type:drupal-library" ], "web/modules/contrib/{$name}": [ "type:drupal-module" ], "web/profiles/{$name}": [ "type:drupal-profile" ], "web/themes/contrib/{$name}": [ "type:drupal-theme" ] } }, "require": { "composer/installers": "~1.0" } }
  26. Apply patches { "patches": { "drupal/core": { "https://drupal.org/node/2619250": "https://drupal.org/files/issues/drupal- do_not_disable_MultiViews_htaccess-2619250-24.patch", "https://drupal.org/node/2716019": "https://drupal.org/files/issues/core_views- implements_title_callback-2716019-23-D8.patch" }, }, "require": { "drupal/core": "~8.2.0", "cweagans/composer-patches": "~1.0" } }
  27. Generate version information for `.info.yml` files in YAML format <?php // https://github.com/drustack/drustack-standard/blob/develop/src/Composer/ScriptHandler.php class ScriptHandler { /** * Generate version information for `.info.yml` files in YAML format. * * @see _drush_pm_generate_info_yaml_metadata() */ protected static function generateInfoYamlMetadata($version, $project, $datestamp) { $core = preg_replace('/^([0-9]).*$/', '$1.x', $version); $date = date('Y-m-d', $datestamp); $info = <<<METADATA # Information add by composer on {$date} core: "{$core}" project: "{$project}" version: "{$version}" datestamp: "{$datestamp}" METADATA; return $info; } }
  28. Q&A
  29. I Need More Help! ● Read documents from Drupal Community – https://drupal.org/documentation ● Join Hong Kong Drupal User Group – Event organizing: http://www.meetup.com/drupalhk – Technological discussion: https://groups.drupal.org/drupalhk – Business connection: http://www.linkedin.com/groups/?gid=6644792 – General sharing: https://www.facebook.com/groups/drupalhk ● Contact us for one (1) month free-trial support service – http://pantarei-design.com/services/support/#support-service-plans
  30. Address: Unit 326, 3/F, Building 16W No.16 Science Park West Avenue, Hong Kong Science Park, Shatin, N.T. – Phone: +852 3576 3812 – Fax: +852 3753 3663 – Email: sales@pantarei-design.com – Web: http://pantarei-design.com Contact us
Anzeige