SlideShare a Scribd company logo
MAKINGTHE MOST
OF MODERN PHP
Ryan Szrama, Commerce Guys
DrupalCamp Asheville 2015
RUN FASTER,
JUMP HIGHER
… when you use PHP
the right way.

http://www.phptherightway.com
• Deliver more capable projects in less time.
• Improve the quality of your Drupal modules.
• Prepare yourself / your team for Drupal 8.
My real world example:
Integrating aTaxonomy Web Service
API integration, taxonomy term
creation, and tag management.
My real world example:
Integrating aTaxonomy Web Service
Delivered as a PHP library integrated
into Drupal in 50% of the estimate.
MODERN PHP IS
OBJECT ORIENTED
• Interfaces, Classes, Inheritance, Namespaces,Traits
• Class autoloading based on namespaces
• Object oriented design patterns are everywhere;
for example, consider Dependency Injection…
<?php
// In this case, Cars can only use
// a single type of engine.
class Car {
protected $engine;
function __construct() {
$this->engine = new Engine();
}
}
$car = new Car();
<?php
class Car {
protected $engine;
function __construct($engine) {
$this->engine = $engine;
}
}
// Use whatever engine you want.
$engine = new NormalEngine();
$car = new Car($engine);
$engine = new TurboEngine();
$turboCar = new Car($engine);
<?php
// Quick example of a dependency injection
// container in a Slim 3.x app.
include 'vendor/autoload.php';
$container = new SlimContainer();
$container['thing'] = function($container) {
return (object) array('doer' => 'done');
};
$app = new SlimApp($container);
echo $app->thing->doer;
MODERN PHP USES
INTEROPERABLE LIBRARIES
• The PHP Framework Interoperability Group
(PHP-FIG) discusses and ratifies PHP Standards
Recommendations (PSRs).
• PSRs are independent standards, not successive
levels of compliance. (e.g. PSR-4 deprecates PSR-0,
and a project can be PSR-2 without anything else.)
MODERN PHP USES
INTEROPERABLE LIBRARIES
• PSR-4 (or PSR-0):Autoloading
• PSR-1 / PSR-2: Coding standards
• PSR-3: Logging interface
• PSR-7: HTTP Request and Response interfaces
• Learn more at: http://www.php-fig.org
See them in use in Slim 3.x, created by Josh Lockhart
(a.k.a. @codeguy), author of Modern PHP
and PHP the Right Way.
http://www.phptherightway.com
<?php
// A smaller codebase than Drupal’s is
// easier to digest while learning.
require 'vendor/autoload.php';
$app = new SlimApp();
$app->get('/', function($request,
$response, $args) {
echo 'Hello, world!';
});
$app->run();
Read more: http://ryanszrama.com/topics/slim
In fact, learning to develop with Slim 3.x helped me
better understand essential concepts in Drupal 8.
COMMERCE 2.X IS BUILT ON
STANDALONE LIBRARIES
• commerceguys/intl (Currency formatting)
• commerceguys/addressing (Address formatting)
• commerceguys/zone (Address grouping)
• commerceguys/enum (Enumeration data structure)
• commerceguys/tax (Tax management)
MODERN PHP
USES COMPOSER
• Dependency management
tool; functionally equivalent
to .info files + drush make.
• Project information is
sourced from packagist.org.
• Excellent built-in support
for Packagist in GitHub.
{
“name”: “rszrama/negotiation-middleware”,
“type”: “library”,
“license”: “MIT”,
“require”: {
“php”: “>=5.4.0”,
“psr/http-message”: “1.0”,
“willdurand/negotiation”: “2.0.0-alpha1”
},
“autoload”: {
“psr-4”: {
“NegotiationMiddleware”: “src”
}
}
}
https://www.previousnext.com.au/blog/drupal-8-now-phpunit-tests-drupal-7
Bonus points: dig into PHPUnit to automate unit
testing your code… even on Drupal 7.
MODERN PHP IN DRUPAL 7
• Write API integrations and data modeling /
manipulation functions as standalone libraries.
• Ensure those libraries do not depend on Drupal.
• Use adapter classes or dependency injection to
make use of that code inside of Drupal.
MODERN PHP IN DRUPAL 7
• Drupal 7 only requires PHP 5.2.x, so its core
autoloading API does not support namespaces.
• Instead use Composer / the Composer Manager
module to manage your project dependencies.
• At least use PSR-4; to reach the larger PHP world,
consider using PSR-2 and the MIT license.
MODERN PHP IN DRUPAL 7
• Use the Standard PHP Library’s exception classes
or create your own more specific exceptions.
• Use try / catch to avoid crippling fatal errors…
EntityMetadataWrapper exceptions, anyone?
• Speaking of the SPL, check out the various data
structures it provides out of the box!
http://www.slimframework.com
If your project has components that don’t require a
full Drupal bootstrap, consider Slim 3.x or a similar
micro-framework to get off the Drupal island.
Learn and adopt the language improvements, tools,
and design principles of modern PHP to become a
better Drupal developer today.
Questions? Find me onTwitter: @ryanszrama

More Related Content

What's hot

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
Azukisoft Pte Ltd
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
Vikas Chauhan
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
Michael Peacock
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
Christopher Pecoraro
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
Inviqa
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
John Dave Decano
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
Brian Feaver
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
Mayank Panchal
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
SWAAM Tech
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
Bukhori Aqid
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
Eli Wheaton
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
Raf Kewl
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
What Is Hobo ?
What Is Hobo ?What Is Hobo ?
What Is Hobo ?
Evarist Lobo
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
Titouan BENOIT
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
Jonathan Goode
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
Dimitrios Zorbas
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
Obinna Akunne
 
Rails engines in large apps
Rails engines in large appsRails engines in large apps
Rails engines in large appsEnrico Teotti
 

What's hot (20)

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
What Is Hobo ?
What Is Hobo ?What Is Hobo ?
What Is Hobo ?
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Rails engines in large apps
Rails engines in large appsRails engines in large apps
Rails engines in large apps
 

Similar to Making the Most of Modern PHP in Drupal 7

Basics PHP
Basics PHPBasics PHP
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Roohul Amin
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida realPHP Conference Argentina
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
10n Software, LLC
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
Wong Hoi Sing Edison
 
Php
PhpPhp
Software Development with PHP & Laravel
Software Development  with PHP & LaravelSoftware Development  with PHP & Laravel
Software Development with PHP & Laravel
Juan Victor Minaya León
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
ShaimaaMohamedGalal
 
GTU MCA PHP Interview Questions And Answers for freshers
GTU MCA PHP  Interview Questions And Answers for freshersGTU MCA PHP  Interview Questions And Answers for freshers
GTU MCA PHP Interview Questions And Answers for freshers
TOPS Technologies
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
DanWooster1
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
Jackson F. de A. Mafra
 
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
Lucas Arruda
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
Eric Johnson
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
Php intro
Php introPhp intro
Php intro
sana mateen
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.DrupalCampDN
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
Muhammad Ghazali
 

Similar to Making the Most of Modern PHP in Drupal 7 (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 
Php
PhpPhp
Php
 
Software Development with PHP & Laravel
Software Development  with PHP & LaravelSoftware Development  with PHP & Laravel
Software Development with PHP & Laravel
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
 
Drupal development
Drupal development Drupal development
Drupal development
 
GTU MCA PHP Interview Questions And Answers for freshers
GTU MCA PHP  Interview Questions And Answers for freshersGTU MCA PHP  Interview Questions And Answers for freshers
GTU MCA PHP Interview Questions And Answers for freshers
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Wc13
Wc13Wc13
Wc13
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
Escalando PHP e Drupal: performance ao infinito e além! - DrupalCamp SP 2015
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
 
Php intro
Php introPhp intro
Php intro
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 

More from Ryan Szrama

Developing with Configuration Management on Drupal 7
Developing with Configuration Management on Drupal 7Developing with Configuration Management on Drupal 7
Developing with Configuration Management on Drupal 7
Ryan Szrama
 
Drupal Commerce at DrupalCon Chicago
Drupal Commerce at DrupalCon ChicagoDrupal Commerce at DrupalCon Chicago
Drupal Commerce at DrupalCon Chicago
Ryan Szrama
 
Paris Commerce Sprint
Paris Commerce SprintParis Commerce Sprint
Paris Commerce Sprint
Ryan Szrama
 
Drupal Commerce, DrupalCamp Colorado 2010
Drupal Commerce, DrupalCamp Colorado 2010Drupal Commerce, DrupalCamp Colorado 2010
Drupal Commerce, DrupalCamp Colorado 2010
Ryan Szrama
 
10 Tips for E-commerce on Drupal
10 Tips for E-commerce on Drupal10 Tips for E-commerce on Drupal
10 Tips for E-commerce on Drupal
Ryan Szrama
 
Drupal Commerce, Web Content 2010
Drupal Commerce, Web Content 2010Drupal Commerce, Web Content 2010
Drupal Commerce, Web Content 2010
Ryan Szrama
 

More from Ryan Szrama (6)

Developing with Configuration Management on Drupal 7
Developing with Configuration Management on Drupal 7Developing with Configuration Management on Drupal 7
Developing with Configuration Management on Drupal 7
 
Drupal Commerce at DrupalCon Chicago
Drupal Commerce at DrupalCon ChicagoDrupal Commerce at DrupalCon Chicago
Drupal Commerce at DrupalCon Chicago
 
Paris Commerce Sprint
Paris Commerce SprintParis Commerce Sprint
Paris Commerce Sprint
 
Drupal Commerce, DrupalCamp Colorado 2010
Drupal Commerce, DrupalCamp Colorado 2010Drupal Commerce, DrupalCamp Colorado 2010
Drupal Commerce, DrupalCamp Colorado 2010
 
10 Tips for E-commerce on Drupal
10 Tips for E-commerce on Drupal10 Tips for E-commerce on Drupal
10 Tips for E-commerce on Drupal
 
Drupal Commerce, Web Content 2010
Drupal Commerce, Web Content 2010Drupal Commerce, Web Content 2010
Drupal Commerce, Web Content 2010
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 

Making the Most of Modern PHP in Drupal 7

  • 1. MAKINGTHE MOST OF MODERN PHP Ryan Szrama, Commerce Guys DrupalCamp Asheville 2015
  • 2. RUN FASTER, JUMP HIGHER … when you use PHP the right way.
 http://www.phptherightway.com
  • 3. • Deliver more capable projects in less time. • Improve the quality of your Drupal modules. • Prepare yourself / your team for Drupal 8.
  • 4. My real world example: Integrating aTaxonomy Web Service API integration, taxonomy term creation, and tag management.
  • 5. My real world example: Integrating aTaxonomy Web Service Delivered as a PHP library integrated into Drupal in 50% of the estimate.
  • 6. MODERN PHP IS OBJECT ORIENTED • Interfaces, Classes, Inheritance, Namespaces,Traits • Class autoloading based on namespaces • Object oriented design patterns are everywhere; for example, consider Dependency Injection…
  • 7. <?php // In this case, Cars can only use // a single type of engine. class Car { protected $engine; function __construct() { $this->engine = new Engine(); } } $car = new Car();
  • 8. <?php class Car { protected $engine; function __construct($engine) { $this->engine = $engine; } } // Use whatever engine you want. $engine = new NormalEngine(); $car = new Car($engine); $engine = new TurboEngine(); $turboCar = new Car($engine);
  • 9. <?php // Quick example of a dependency injection // container in a Slim 3.x app. include 'vendor/autoload.php'; $container = new SlimContainer(); $container['thing'] = function($container) { return (object) array('doer' => 'done'); }; $app = new SlimApp($container); echo $app->thing->doer;
  • 10. MODERN PHP USES INTEROPERABLE LIBRARIES • The PHP Framework Interoperability Group (PHP-FIG) discusses and ratifies PHP Standards Recommendations (PSRs). • PSRs are independent standards, not successive levels of compliance. (e.g. PSR-4 deprecates PSR-0, and a project can be PSR-2 without anything else.)
  • 11. MODERN PHP USES INTEROPERABLE LIBRARIES • PSR-4 (or PSR-0):Autoloading • PSR-1 / PSR-2: Coding standards • PSR-3: Logging interface • PSR-7: HTTP Request and Response interfaces • Learn more at: http://www.php-fig.org
  • 12. See them in use in Slim 3.x, created by Josh Lockhart (a.k.a. @codeguy), author of Modern PHP and PHP the Right Way. http://www.phptherightway.com
  • 13. <?php // A smaller codebase than Drupal’s is // easier to digest while learning. require 'vendor/autoload.php'; $app = new SlimApp(); $app->get('/', function($request, $response, $args) { echo 'Hello, world!'; }); $app->run();
  • 14. Read more: http://ryanszrama.com/topics/slim In fact, learning to develop with Slim 3.x helped me better understand essential concepts in Drupal 8.
  • 15. COMMERCE 2.X IS BUILT ON STANDALONE LIBRARIES • commerceguys/intl (Currency formatting) • commerceguys/addressing (Address formatting) • commerceguys/zone (Address grouping) • commerceguys/enum (Enumeration data structure) • commerceguys/tax (Tax management)
  • 16. MODERN PHP USES COMPOSER • Dependency management tool; functionally equivalent to .info files + drush make. • Project information is sourced from packagist.org. • Excellent built-in support for Packagist in GitHub.
  • 17. { “name”: “rszrama/negotiation-middleware”, “type”: “library”, “license”: “MIT”, “require”: { “php”: “>=5.4.0”, “psr/http-message”: “1.0”, “willdurand/negotiation”: “2.0.0-alpha1” }, “autoload”: { “psr-4”: { “NegotiationMiddleware”: “src” } } }
  • 18. https://www.previousnext.com.au/blog/drupal-8-now-phpunit-tests-drupal-7 Bonus points: dig into PHPUnit to automate unit testing your code… even on Drupal 7.
  • 19. MODERN PHP IN DRUPAL 7 • Write API integrations and data modeling / manipulation functions as standalone libraries. • Ensure those libraries do not depend on Drupal. • Use adapter classes or dependency injection to make use of that code inside of Drupal.
  • 20. MODERN PHP IN DRUPAL 7 • Drupal 7 only requires PHP 5.2.x, so its core autoloading API does not support namespaces. • Instead use Composer / the Composer Manager module to manage your project dependencies. • At least use PSR-4; to reach the larger PHP world, consider using PSR-2 and the MIT license.
  • 21. MODERN PHP IN DRUPAL 7 • Use the Standard PHP Library’s exception classes or create your own more specific exceptions. • Use try / catch to avoid crippling fatal errors… EntityMetadataWrapper exceptions, anyone? • Speaking of the SPL, check out the various data structures it provides out of the box!
  • 22. http://www.slimframework.com If your project has components that don’t require a full Drupal bootstrap, consider Slim 3.x or a similar micro-framework to get off the Drupal island.
  • 23. Learn and adopt the language improvements, tools, and design principles of modern PHP to become a better Drupal developer today. Questions? Find me onTwitter: @ryanszrama