+ All Categories
Home > Technology > [HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?

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

Date post: 16-Apr-2017
Category:
Upload: wong-hoi-sing-edison
View: 130 times
Download: 0 times
Share this document with a friend
50
Hong Kong Drupal User Group (HKDUG) What's News in PHP? BarCamp Hong Kong 2016 2016 Dec 10th
Transcript

Hong Kong Drupal User Group(HKDUG)

What's News in PHP?

BarCamp Hong Kong 20162016 Dec 10th

Edison Wong

● 2005 - Drupal Developer & Contributor– https://drupal.org/user/33940

● 2008 - HKDUG Co-founder– https://groups.drupal.org/drupalhk

● 2010 - CEO, PantaRei Design– [email protected]

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

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 moreabout what Drupal can do and what folks are building with it.

● Drupal is a free software package that allows you to easilyorganize, manage and publish your content, with an endlessvariety 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

Outline

● PHP 7.1● PHP-FIG● Composer● Symfony 3.2● Drupal 8.2

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

Class constant visiblity modifiers<?php class Token {// Constants default to publicconst 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;}

Square bracket syntax for arraydestructuring 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];

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;

Catching Multiple Exception Types

<?php try { // Some code...} catch (ExceptionType1 | ExceptionType2 $e) { // Code to handle the exception} catch (\Exception $e) { // ...}

PHP-FIG

● The FIG stands for FrameworkInteroperability Group. The name untilrecently was “PHP Standards Group” but thiswas somewhat inaccurate of the intentionsof the group

● http://www.php-fig.org/

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

PSR-4: Autoloader This PSR describes a specification for autoloading

classes from file paths, e.g.– Fully Qualified Class Name

● \Symfony\Core\Request– Namespace Prefix

● Symfony\Core– Base Directory

● ./vendor/Symfony/Core/– Resulting File Path

● ./vendor/Symfony/Core/Request.php

Composer

● Composer is a tool for dependencymanagement in PHP

● It allows you to declare the libraries yourproject depends on and it will manage(install/update) them for you.

● https://getcomposer.org/

Installation php -r "copy('https://getcomposer.org/installer',

'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') ===

'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt';unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php php -r "unlink('composer-setup.php');"

composer.json

{ "require": { "monolog/monolog": "1.0.*" }}

Basic usage

composer install composer update

Autoloading For libraries that specify autoload information,

Composer generates a vendor/autoload.php file. Youcan simply include this file and you will get autoloadingfor free– require __DIR__ . '/vendor/autoload.php';– $log = new Monolog\Logger('name');– $log->pushHandler(new

Monolog\Handler\StreamHandler('app.log',Monolog\Logger::WARNING));

– $log->addWarning('Foo'); Composer also support PSR-4 autoloading

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

Installation

composer create-projectsymfony/framework-standard-editionmy_project_name

cd my_project_name/ php bin/console server:run http://symfony.com/doc/current/setup.html

Creating a Page: Route andController

// src/AppBundle/Controller/LuckyController.phpnamespace AppBundle\Controller;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Response;class LuckyController{ /** * @Route("/lucky/number") */ public function numberAction() { $number = mt_rand(0, 100); return new Response( '<html><body>Lucky number: '.$number.'</body></html>' ); }}

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 freshcomponents 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

Install with Composer

● composer create-project --stability dev --no-interaction drustack/framework-standard-edition:develop drustack

● https://github.com/drustack/drustack-standard

● https://github.com/drustack/drustack-standard/blob/develop/composer.json

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" } }}

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" }}

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" }}

Generate version information for`.info.yml` files in YAML format

<?php// https://github.com/drustack/drustack-standard/blob/develop/src/Composer/ScriptHandler.phpclass 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; }}

Q&A

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

Address: Unit 326, 3/F, Building 16WNo.16 Science Park West Avenue,Hong Kong Science Park, Shatin, N.T.– Phone: +852 3576 3812– Fax: +852 3753 3663– Email: [email protected]– Web: http://pantarei-design.com

Contact us


Recommended