ZendCon 2010
This session demonstrates how to build configurable and reusable bootstrap resources powered entirely by application.ini. Covers basic and advanced bootstrapping techniques, sharing bootstrap resources between applications, and accessing resources from within your applications.
2. About Me
• Average, everyday PHP developer.
• Zend PHP5 Certified Engineer
• Used ZF since 1.0.2 (December 2007)
• Developed web applications for
▫ RealTown 2004-2008
▫ Houghton Mifflin 2008-2010
▫ Disney 2010-current
3. Or “What does footwear have to do with the interwebs?”
4. Typical Bootstrap Tasks
• Define constants
• Set up include path
• Set up autoloader
• Initialize resources
▫ Database connections
▫ Session
▫ Web service clients
6. Start with Zend_Tool
$ zf create project quickstart
Creating project at /Users/hevirgen/Web/projects/quickstart
Note: This command created a web project, for more information
setting up your VHOST, please see docs/README
10. Choose Your Path Wisely, Grasshopper
Bootstrap resources by:
• Providing protected _init*() methods.
• Using resource plugins.
11. _init*() Methods
• Coded directly in the application’s Bootstrap
class.
• Return value is stored in bootstrap registry.
12. _init*() Methods
class Bootstrap extends
Zend_Application_Bootstrap_Bootstrap
{
protected function _initFoo()
{
$foo = new Foo();
return $foo;
}
}
13. Resource Plugin
• Each resource is initialized in its own class.
• Plugins are loaded in LIFO order.
• Return value is stored in bootstrap registry.
27. Resource Plugin
Class MyResource_Foo extends Zend_Application_Resource_Abstract
{
public function init()
{
$options = $this->getOptions();
assert($options[‘bar’] == ‘derp’); // true
}
}
28. Resource Plugin
Class MyResource_Foo extends Zend_Application_Resource_Abstract
{
protected $_bar;
public function setBar($bar)
{
$this->_bar = $bar;
}
public function init()
{
assert($this->_bar == ‘derp’); // true
}
}
29. Why Plugins Are Awesomesauce
• Reusable between projects
• Easily unit-tested
• Can be packaged with resource libraries
• Can provide sane defaults
• Loaded in LIFO order allows for extending
plugins
30. When Plugins Can Be Weaksauce
• Performance concerns with loading a class file
for each resource plugin
• Some editors (Notepad.exe) don’t support
opening multiple files