By using a few simple organizational principles, developers can make their project structure predictable, extensible, and modular. These techniques make it easy to de-conflict and share code between multiple projects. They also make it easy to automate project-support tasks such as testing, documentation, and distribution. This talk will discuss these principles, how they can be discovered from researching publicly available PHP projects, and how they are used (or not used) in popular applications and frameworks.
Exploring the Future Potential of AI-Enabled Smartphone Processors
Â
Organizing Your PHP Projects (2010 ConFoo)
1. Organizing Your
PHP Projects
Paul M. Jones
ConFoo, MontrĂŠal
10 Mar 2010
http://joind.in/1289
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
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, difďŹcult 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
12. Standalone Application:
Typical Include File
// expects certain globals
if (! defined('APP_CONSTANT')) {
    die("Direct access not allowed.");
}
12
16. Modular Application
⢠Standalone application ++
⢠Same ďŹle 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
20. Library Collection
⢠SpeciďŹc, 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 ďŹle
system
20
27. Elements of
The One Lesson
⢠Stop using globals
⢠Namespace everything
⢠Class-to-ďŹle naming
27
28. 1. Stop Using Globals
⢠Stop using
register_globals
⢠Stop using $GLOBALS
⢠Stop using global
28
29. 2. Namespace Everything
⢠Automatic deconďŹiction of identiďŹers
⢠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
36. The One Lesson In Practice;
or,
âStep 3: ProďŹt!â
36
37. Extended Effects of
The One Lesson
⢠Can be used anywhere
(app, module, lib, CMS, framework)
⢠Structure for refactoring and additions
⢠Testing, proďŹling, and public ďŹles can
parallel the same structure
⢠Intuitive for new developers
⢠No more include-path woes
37
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 deconďŹiction
⢠Use class-to-ďŹle 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