SlideShare a Scribd company logo
Organizing Your
 PHP Projects
        Paul M. Jones
 VP Engineering, Company 52

       Memphis PHP
       26 Aug 2010
Read These
• “Mythical Man-Month”, Brooks
• “Art of Project Management”, Berkun
• “Peopleware”, DeMarco and Lister




                    2
Project Planning
        in One Lesson
•   Examine real-world projects

•   The One Lesson for
    organizing your project

•   Elements of The One Lesson

•   The One Lesson in practice




                              3
About Me
•   Web Architect

•   PHP since 1999 (PHP 3)

•   Solar Framework (lead)

•   Savant Template System (lead)

•   Zend Framework (found. contrib.)

•   PEAR Group (2007-2008)

•   Web framework benchmarks

                                    4
About You
•   Project lead/manager?

•   Improve team consistency?

•   Want to share your code
    with others?

•   Want to use code from
    others?

•   Want to reduce recurring
    integration issues?

                                5
Goals for Organizing
•   Security

•   Integration and extension

•   Adaptable to change

•   Predictable and maintainable

•   Teamwork consistency

•   Re-use rules on multiple projects


                                    6
Project Research;
              or,
“Step 1: Study Underpinnings”



              7
Project Evolution Tracks
               One-Off
                Heap

              Standalone
                 App

  Library         ?
                           Modular App
 Collection

 Framework                    CMS

                  8
One-Off Heap
•   No discernible architecture

•   Browse directly to the scripts

•   Add to it piece by piece

•   Little to no separation of concerns

•   All variables are global

•   Unmanageable, difficult to extend


                                       9
Standalone Application
•   One-off heap ++

•   Series of separate page
    scripts and common includes

•   Installed in web root

•   Each responsible for global
    execution environment

•   Script variables still global


                                    10
Standalone Application:
   Typical Main Script
// Setup or bootstrapping
define('INCLUDE_PATH', dirname(__FILE__) . '/');
include_once INCLUDE_PATH . 'inc/prepend.inc.php';
include_once INCLUDE_PATH . 'lib/foo.class.php';
include_once INCLUDE_PATH . 'lib/View.class.php';

// Actions (if we're lucky)
$foo = new Foo();
$data = $foo->getData();

// Display (if we're lucky)
$view = new View(INCLUDE_PATH . 'tpl/');
$view->assign($data);
echo $view->fetch('template.tpl');

// Teardown
include_once INCLUDE_PATH . "inc/append.inc.php";

                              11
Standalone Application:
  Typical Include File

// expects certain globals
if (! defined('APP_CONSTANT')) {
    die('Direct access not allowed.');
}




                   12
Standalone Application:
 Typical File Structure
 index.php               #   main pages
 page1.php               #
 page2.php               #
 page3.php               #
 sub/                    #   sub-section
      index.php          #
      zim.php            #
      gir.php            #
 inc/                    #   includes
      config.inc.php     #
      prepend.inc.php    #
 lib/                    #   libraries
      foo.class.php      #
      Bundle1/           #
      Bundle2/           #

                        13
Standalone Application:
   Support Structure
 bin/           #   command-line tools
 cache/         #   cache files
 css/           #   stylesheets
 docs/          #   documentation
 img/           #   images
 install/       #   installation scripts
 js/            #   javascript
 log/           #   log files
 sql/           #   schema migrations
 theme/         #   themes or skins
 tpl/           #   templates

 -- no standard naming or structure
 -- index.html file in each directory

                        14
Project Evolution Tracks
               One-Off
                Heap

              Standalone
                 App

  Library         ?
                           Modular App
 Collection

 Framework                    CMS

                  15
Modular Application
•   Standalone application ++

•   Same file structure and script style

•   One additional directory:
    “modules”, “plugins”, etc

•   Hooks in the “main” scripts for
    additional behaviors

•   Use global variables to coordinate
    between modules
                                16
CMS
•   Modular application ++

•   General-purpose application
    broker

•   All "main" scripts become
    sub-applications

•   Still in the web root, still
    using globals to coordinate



                                17
Application/CMS
             Projects
• Achievo         • Eventum     • PhpMyAdmin
• Code Igniter*   • Gallery     • Seagull*
• Coppermine      • Joomla/     • SugarCRM
                   Mambo
• DokuWiki                      • Vanilla
                  • MediaWiki
• Drupal                        • WordPress
                       18
Project Evolution Tracks
               One-Off
                Heap

              Standalone
                 App

  Library         ?
                           Modular App
 Collection

 Framework                    CMS

                  19
Library Collection
•   Specific, limited logic extracted
    from an app

•   Re-used directly in unrelated
    applications and other libraries

•   No global variables

•   Class-oriented

•   Can exist anywhere in the file
    system
                                       20
Library Project:
    Typical File Structure
Foo.php                 #    Foo
Foo/                    #
     Component.php      #    Foo_Component
     Component/         #
         Element1.php   #    Foo_Component_Element1
         Element2.php   #    Foo_Component_Element2
Bar.php                 #    Bar
Bar/                    #
     Task.php           #    Bar_Task
     Task/              #
         Part1.php      #    Bar_Task_Part1
         Part2.php      #    Bar_Task_Part2

                        21
Framework
•   Codebase

    •   Library collection

    •   Apps extend from it

•   Support structure

    •   Bootstrap file

    •   Public assets

    •   Protected assets

                              22
Library/Framework Projects
•   AdoDB            •   Lithium        •   Savant

•   Cake             •   Mojavi/Agavi   •   Seagull *

•   CgiApp           •   PAT            •   Smarty

•   Code Igniter *   •   PEAR           •   Solar

•   Doctrine         •   PHP Unit       •   SwiftMailer

•   EZ Components    •   Phing          •   Symfony

•   HtmlPurifier      •   Phly           •   WACT

•   Horde            •   Prado          •   Zend Framework

                                 23
Project Evolution Tracks
  class-       One-Off      include-
 oriented       Heap        oriented

              Standalone
                 App

  Library         ?
                           Modular App
 Collection

 Framework                    CMS

                  24
The One Lesson;
       or,
  “Step 2: ... ?”




        25
Organize your project
            as if
it is a library collection.
Elements of
        The One Lesson

• Stop using globals
• Namespace everything
• Class-to-file naming

                    27
1. Stop Using Globals

• Stop using
  register_globals

• Stop using $GLOBALS
• Stop using global

                        28
2. Namespace Everything

•   Automatic deconfliction of identifiers

    •   Classes (“vendor”)

    •   Functions, variables, constants

    •   Use with $_SESSION,
        $_COOKIE, etc. keys




                                    29
Choosing a Namespace

•   Project, client, brand, channel

•   A short word or acronym,
    not a letter (“Z”)

•   A unique name, not a generic
    name related to a task
    (Date, HTML, RSS, Table, User)




                                      30
PHP 5.2 “Namespaces”
// class User {}
class Vendor_User {}
$user = new Vendor_User();

// function get_info() {}
function vendor_get_info()

// $_SESSION["user_prefs"]
$_SESSION["Vendor_User"]["prefs"];
                31
PHP 5.3 Namespaces
namespace vendor;
class User {}

// relative namespace
namespace vendor;
$user = new User();

// absolute namespace
namespace other;
$user = new vendorUser();
                    32
3. Class-To-File Naming

• Class name maps directly to file name
 • Vendor_User    => Vendor/User.php

• Horde, PEAR, Solar, Zend, others
• Highly predictable file locations
• Lends itself to autoloading
                     33
Class-to-File Naming
 (PHP 5.2, Horde/PEAR)

// studly-caps needs preg_replace(), but:
VendorAuthOpenId => ...
    Vendor/Auth/Open/Id.php?
    Vendor/Auth/OpenId.php?

// underscores just need str_replace()
Vendor_Auth_OpenId => Vendor/Auth/OpenId.php




                      34
Class-to-File
          (PHP 5.3, PSR-0)

foo_barpkgMain     => /foo_bar/pkg/Main.php
foo_barpkgMain_Sub => /foo_bar/pkg/Main/Sub.php




      •   PEAR, Solar, Zend, Doctrine,
          Lithium, Symfony 2
                        35
The One Lesson In Practice;
           or,
     “Step 3: Profit!”




             36
Extended Effects of
             The One Lesson
•   Can be used anywhere
    (app, module, lib, CMS, framework)

•   Structure for refactoring and additions

•   Testing, profiling, and public files can
    parallel the same structure

•   Intuitive for new developers

•   No more include-path woes

                                      37
Mambo CMS
administrator/
components/
editor/
files/
help/
images/
includes/
    Vendor/
index.php
installation/
language/
mainbody.php
mambots/
media/
modules/
templates/
            38
Zend Framework
 project/
     application/
          bootstrap.php
          configs/
          controllers/
          models/
          views/
              helpers/
              scripts/
     library/
          Zend/
          Vendor/
     public
          index.php

              39
Lithium
app/
    config/
    controllers/
    extensions/
    index.php
    libraries/
    models/
    resources/
    tests/
    views/
    webroot/
libraries/
    lithium/
    vendor/

            40
Symfony 2
hello/
     config/
     console/
     HelloKernel.php
src/
     Application/
         HelloBundle/
              Bundle.php
              Controller/
              Resources/
     autoload.php
     vendor/
         symfony/
         zend/
         vendor/
web/
             41
Solar
system/
    config/
    config.php
    docroot/
         index.php
         public/
    include/
         Solar.php
         Solar/
         Vendor/
    script/
    source/
    sqlite/
    tmp/

             42
Solar Apps Are Libraries Too
          include/
            Solar/
            Vendor/
              App/
                Page.php
                Page/
                   Layout/
                   Locale/
                   Public/
                   View/
              Model/
                Gir.php
                Gir/
              Zim.php
              Zim/
                 43
Refactoring
• Move from existing include-based architecture
  to class-based architecture ...
  • ... by functionality
  • ... by script
• Then build scripts out of classes, not includes
• Then build apps out of classes, not scripts
• Leads to MVC / MVP / PAC architecture
                           44
Summary
The One Lesson

• Organize your project as if it will be part of
  a library collection
  • Avoid globals
  • Use namespaces for deconfliction
  • Use class-to-file naming convention

                         46
Goals for Organizing
•   Security

•   Integration and extension

•   Adaptable to change

•   Predictable and maintainable

•   Teamwork consistency

•   Re-use rules on multiple projects


                                   47
• Questions?
• Comments?
• Criticism?


               48
Thanks!

• <http://paul-m-jones.com>
• <http://solarphp.com>
• Google for “web framework benchmarks”

                   49
Organinzing Your PHP Projects (2010 Memphis PHP)

More Related Content

What's hot

Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Fabien Potencier
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir Ahmad
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World DominationcPanel
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź
AEM HUB
 
Wt unit 1 ppts web development process
Wt unit 1 ppts web development processWt unit 1 ppts web development process
Wt unit 1 ppts web development process
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
princeirfancivil
 
Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
Khan625
 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 Refresher
Ivano Malavolta
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
Dinh Pham
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
Phạm Thu Thủy
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
Oscar Merida
 
Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)
Ryan Mauger
 
Building search app with ElasticSearch
Building search app with ElasticSearchBuilding search app with ElasticSearch
Building search app with ElasticSearch
Lukas Vlcek
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
Ryan Mauger
 

What's hot (20)

Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź
 
Wt unit 1 ppts web development process
Wt unit 1 ppts web development processWt unit 1 ppts web development process
Wt unit 1 ppts web development process
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
Maven
MavenMaven
Maven
 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 Refresher
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 
20jsp
20jsp20jsp
20jsp
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)
 
Building search app with ElasticSearch
Building search app with ElasticSearchBuilding search app with ElasticSearch
Building search app with ElasticSearch
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 

Viewers also liked

How Do We Get The Deficit To Zero?
How Do We Get The Deficit To Zero?How Do We Get The Deficit To Zero?
How Do We Get The Deficit To Zero?Paul Jones
 
Same Thing Happens Every Time
Same Thing Happens Every TimeSame Thing Happens Every Time
Same Thing Happens Every Time
Paul Jones
 
All You Jokers
All You JokersAll You Jokers
All You JokersPaul Jones
 
Framework and Application Benchmarking
Framework and Application BenchmarkingFramework and Application Benchmarking
Framework and Application BenchmarkingPaul Jones
 
Decoupled Libraries for PHP
Decoupled Libraries for PHPDecoupled Libraries for PHP
Decoupled Libraries for PHPPaul Jones
 
How To Train Your Manager
How To Train Your ManagerHow To Train Your Manager
How To Train Your Manager
Paul Jones
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Paul Jones
 
Career and Life Management
Career and Life ManagementCareer and Life Management
Career and Life ManagementPaul Jones
 

Viewers also liked (8)

How Do We Get The Deficit To Zero?
How Do We Get The Deficit To Zero?How Do We Get The Deficit To Zero?
How Do We Get The Deficit To Zero?
 
Same Thing Happens Every Time
Same Thing Happens Every TimeSame Thing Happens Every Time
Same Thing Happens Every Time
 
All You Jokers
All You JokersAll You Jokers
All You Jokers
 
Framework and Application Benchmarking
Framework and Application BenchmarkingFramework and Application Benchmarking
Framework and Application Benchmarking
 
Decoupled Libraries for PHP
Decoupled Libraries for PHPDecoupled Libraries for PHP
Decoupled Libraries for PHP
 
How To Train Your Manager
How To Train Your ManagerHow To Train Your Manager
How To Train Your Manager
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
 
Career and Life Management
Career and Life ManagementCareer and Life Management
Career and Life Management
 

Similar to Organinzing Your PHP Projects (2010 Memphis PHP)

Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovsky
php-user-group-minsk
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Max Romanovsky
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
Ralph Schindler
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
Scheidt & Bachmann
 
Zend Framework MVC driven ExtJS
Zend Framework MVC driven ExtJSZend Framework MVC driven ExtJS
Zend Framework MVC driven ExtJS
Thorsten Suckow-Homberg
 
Drupal, git and sanity
Drupal, git and sanityDrupal, git and sanity
Drupal, git and sanity
Charlie Morris
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutionsSangjin Lee
 
Phase2 Large Drupal Multisites (gta case study)
Phase2   Large Drupal Multisites (gta case study)Phase2   Large Drupal Multisites (gta case study)
Phase2 Large Drupal Multisites (gta case study)
Phase2
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayTony Ng
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
Arnaud Héritier
 
One drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp CaceresOne drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp Cacereshernanibf
 
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenutiSymfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Michele Orselli
 
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenutiSymfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Manuel Baldassarri
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-study
peter_ibuildings
 
Zend Code in ZF 2.0
Zend Code in ZF 2.0Zend Code in ZF 2.0
Zend Code in ZF 2.0
Ralph Schindler
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2
Anil Sagar
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Frameworkphilipjting
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
hernanibf
 
Howtobuildyourownframework
HowtobuildyourownframeworkHowtobuildyourownframework
Howtobuildyourownframeworkhazzaz
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
Mohammad Emran Hasan
 

Similar to Organinzing Your PHP Projects (2010 Memphis PHP) (20)

Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovsky
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Zend Framework MVC driven ExtJS
Zend Framework MVC driven ExtJSZend Framework MVC driven ExtJS
Zend Framework MVC driven ExtJS
 
Drupal, git and sanity
Drupal, git and sanityDrupal, git and sanity
Drupal, git and sanity
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutions
 
Phase2 Large Drupal Multisites (gta case study)
Phase2   Large Drupal Multisites (gta case study)Phase2   Large Drupal Multisites (gta case study)
Phase2 Large Drupal Multisites (gta case study)
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBay
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
 
One drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp CaceresOne drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp Caceres
 
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenutiSymfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
 
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenutiSymfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-study
 
Zend Code in ZF 2.0
Zend Code in ZF 2.0Zend Code in ZF 2.0
Zend Code in ZF 2.0
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Framework
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
 
Howtobuildyourownframework
HowtobuildyourownframeworkHowtobuildyourownframework
Howtobuildyourownframework
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 

Organinzing Your PHP Projects (2010 Memphis PHP)

  • 1. Organizing Your PHP Projects Paul M. Jones VP Engineering, Company 52 Memphis PHP 26 Aug 2010
  • 2. Read These • “Mythical Man-Month”, Brooks • “Art of Project Management”, Berkun • “Peopleware”, DeMarco and Lister 2
  • 3. Project Planning in One Lesson • Examine real-world projects • The One Lesson for organizing your project • Elements of The One Lesson • The One Lesson in practice 3
  • 4. About Me • Web Architect • PHP since 1999 (PHP 3) • Solar Framework (lead) • Savant Template System (lead) • Zend Framework (found. contrib.) • PEAR Group (2007-2008) • Web framework benchmarks 4
  • 5. About You • Project lead/manager? • Improve team consistency? • Want to share your code with others? • Want to use code from others? • Want to reduce recurring integration issues? 5
  • 6. Goals for Organizing • Security • Integration and extension • Adaptable to change • Predictable and maintainable • Teamwork consistency • Re-use rules on multiple projects 6
  • 7. Project Research; or, “Step 1: Study Underpinnings” 7
  • 8. Project Evolution Tracks One-Off Heap Standalone App Library ? Modular App Collection Framework CMS 8
  • 9. One-Off Heap • No discernible architecture • Browse directly to the scripts • Add to it piece by piece • Little to no separation of concerns • All variables are global • Unmanageable, difficult to extend 9
  • 10. Standalone Application • One-off heap ++ • Series of separate page scripts and common includes • Installed in web root • Each responsible for global execution environment • Script variables still global 10
  • 11. Standalone Application: Typical Main Script // Setup or bootstrapping define('INCLUDE_PATH', dirname(__FILE__) . '/'); include_once INCLUDE_PATH . 'inc/prepend.inc.php'; include_once INCLUDE_PATH . 'lib/foo.class.php'; include_once INCLUDE_PATH . 'lib/View.class.php'; // Actions (if we're lucky) $foo = new Foo(); $data = $foo->getData(); // Display (if we're lucky) $view = new View(INCLUDE_PATH . 'tpl/'); $view->assign($data); echo $view->fetch('template.tpl'); // Teardown include_once INCLUDE_PATH . "inc/append.inc.php"; 11
  • 12. Standalone Application: Typical Include File // expects certain globals if (! defined('APP_CONSTANT')) {     die('Direct access not allowed.'); } 12
  • 13. Standalone Application: Typical File Structure index.php # main pages page1.php # page2.php # page3.php # sub/ # sub-section index.php # zim.php # gir.php # inc/ # includes config.inc.php # prepend.inc.php # lib/ # libraries foo.class.php # Bundle1/ # Bundle2/ # 13
  • 14. Standalone Application: Support Structure bin/ # command-line tools cache/ # cache files css/ # stylesheets docs/ # documentation img/ # images install/ # installation scripts js/ # javascript log/ # log files sql/ # schema migrations theme/ # themes or skins tpl/ # templates -- no standard naming or structure -- index.html file in each directory 14
  • 15. Project Evolution Tracks One-Off Heap Standalone App Library ? Modular App Collection Framework CMS 15
  • 16. Modular Application • Standalone application ++ • Same file structure and script style • One additional directory: “modules”, “plugins”, etc • Hooks in the “main” scripts for additional behaviors • Use global variables to coordinate between modules 16
  • 17. CMS • Modular application ++ • General-purpose application broker • All "main" scripts become sub-applications • Still in the web root, still using globals to coordinate 17
  • 18. Application/CMS Projects • Achievo • Eventum • PhpMyAdmin • Code Igniter* • Gallery • Seagull* • Coppermine • Joomla/ • SugarCRM Mambo • DokuWiki • Vanilla • MediaWiki • Drupal • WordPress 18
  • 19. Project Evolution Tracks One-Off Heap Standalone App Library ? Modular App Collection Framework CMS 19
  • 20. Library Collection • Specific, limited logic extracted from an app • Re-used directly in unrelated applications and other libraries • No global variables • Class-oriented • Can exist anywhere in the file system 20
  • 21. Library Project: Typical File Structure Foo.php # Foo Foo/ # Component.php # Foo_Component Component/ # Element1.php # Foo_Component_Element1 Element2.php # Foo_Component_Element2 Bar.php # Bar Bar/ # Task.php # Bar_Task Task/ # Part1.php # Bar_Task_Part1 Part2.php # Bar_Task_Part2 21
  • 22. Framework • Codebase • Library collection • Apps extend from it • Support structure • Bootstrap file • Public assets • Protected assets 22
  • 23. Library/Framework Projects • AdoDB • Lithium • Savant • Cake • Mojavi/Agavi • Seagull * • CgiApp • PAT • Smarty • Code Igniter * • PEAR • Solar • Doctrine • PHP Unit • SwiftMailer • EZ Components • Phing • Symfony • HtmlPurifier • Phly • WACT • Horde • Prado • Zend Framework 23
  • 24. Project Evolution Tracks class- One-Off include- oriented Heap oriented Standalone App Library ? Modular App Collection Framework CMS 24
  • 25. The One Lesson; or, “Step 2: ... ?” 25
  • 26. Organize your project as if it is a library collection.
  • 27. Elements of The One Lesson • Stop using globals • Namespace everything • Class-to-file naming 27
  • 28. 1. Stop Using Globals • Stop using register_globals • Stop using $GLOBALS • Stop using global 28
  • 29. 2. Namespace Everything • Automatic deconfliction of identifiers • Classes (“vendor”) • Functions, variables, constants • Use with $_SESSION, $_COOKIE, etc. keys 29
  • 30. Choosing a Namespace • Project, client, brand, channel • A short word or acronym, not a letter (“Z”) • A unique name, not a generic name related to a task (Date, HTML, RSS, Table, User) 30
  • 32. PHP 5.3 Namespaces namespace vendor; class User {} // relative namespace namespace vendor; $user = new User(); // absolute namespace namespace other; $user = new vendorUser(); 32
  • 33. 3. Class-To-File Naming • Class name maps directly to file name • Vendor_User => Vendor/User.php • Horde, PEAR, Solar, Zend, others • Highly predictable file locations • Lends itself to autoloading 33
  • 34. Class-to-File Naming (PHP 5.2, Horde/PEAR) // studly-caps needs preg_replace(), but: VendorAuthOpenId => ... Vendor/Auth/Open/Id.php? Vendor/Auth/OpenId.php? // underscores just need str_replace() Vendor_Auth_OpenId => Vendor/Auth/OpenId.php 34
  • 35. Class-to-File (PHP 5.3, PSR-0) foo_barpkgMain => /foo_bar/pkg/Main.php foo_barpkgMain_Sub => /foo_bar/pkg/Main/Sub.php • PEAR, Solar, Zend, Doctrine, Lithium, Symfony 2 35
  • 36. The One Lesson In Practice; or, “Step 3: Profit!” 36
  • 37. Extended Effects of The One Lesson • Can be used anywhere (app, module, lib, CMS, framework) • Structure for refactoring and additions • Testing, profiling, and public files can parallel the same structure • Intuitive for new developers • No more include-path woes 37
  • 38. Mambo CMS administrator/ components/ editor/ files/ help/ images/ includes/ Vendor/ index.php installation/ language/ mainbody.php mambots/ media/ modules/ templates/ 38
  • 39. Zend Framework project/ application/ bootstrap.php configs/ controllers/ models/ views/ helpers/ scripts/ library/ Zend/ Vendor/ public index.php 39
  • 40. Lithium app/ config/ controllers/ extensions/ index.php libraries/ models/ resources/ tests/ views/ webroot/ libraries/ lithium/ vendor/ 40
  • 41. Symfony 2 hello/ config/ console/ HelloKernel.php src/ Application/ HelloBundle/ Bundle.php Controller/ Resources/ autoload.php vendor/ symfony/ zend/ vendor/ web/ 41
  • 42. Solar system/ config/ config.php docroot/ index.php public/ include/ Solar.php Solar/ Vendor/ script/ source/ sqlite/ tmp/ 42
  • 43. Solar Apps Are Libraries Too include/ Solar/ Vendor/ App/ Page.php Page/ Layout/ Locale/ Public/ View/ Model/ Gir.php Gir/ Zim.php Zim/ 43
  • 44. Refactoring • Move from existing include-based architecture to class-based architecture ... • ... by functionality • ... by script • Then build scripts out of classes, not includes • Then build apps out of classes, not scripts • Leads to MVC / MVP / PAC architecture 44
  • 46. The One Lesson • Organize your project as if it will be part of a library collection • Avoid globals • Use namespaces for deconfliction • Use class-to-file naming convention 46
  • 47. Goals for Organizing • Security • Integration and extension • Adaptable to change • Predictable and maintainable • Teamwork consistency • Re-use rules on multiple projects 47
  • 49. Thanks! • <http://paul-m-jones.com> • <http://solarphp.com> • Google for “web framework benchmarks” 49