Your SlideShare is downloading. ×
0
Reusable Bootstrap Resources
Hector Virgen
ZendCon 2010
About Me
• Average, everyday PHP developer.
• Zend PHP5 Certified Engineer
• Used ZF since 1.0.2 (December 2007)
• Develop...
Or “What does footwear have to do with the interwebs?”
Typical Bootstrap Tasks
• Define constants
• Set up include path
• Set up autoloader
• Initialize resources
▫ Database con...
Or “Bootstrapping with Style”
Start with Zend_Tool
$ zf create project quickstart
Creating project at /Users/hevirgen/Web/projects/quickstart
Note: This...
Your App’s Configuration
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.l...
Bootstrap
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}
Or “Loading up your application’s dependencies”
Choose Your Path Wisely, Grasshopper
Bootstrap resources by:
• Providing protected _init*() methods.
• Using resource plug...
_init*() Methods
• Coded directly in the application’s Bootstrap
class.
• Return value is stored in bootstrap registry.
_init*() Methods
class Bootstrap extends
Zend_Application_Bootstrap_Bootstrap
{
protected function _initFoo()
{
$foo = new...
Resource Plugin
• Each resource is initialized in its own class.
• Plugins are loaded in LIFO order.
• Return value is sto...
Resource Plugin
class MyResource_Foo extends
Zend_Application_Resource_Abstract
{
public function init()
{
$foo = new Foo(...
Ensure Resource Plugin is Loaded
[production]
pluginPaths.My_Resource = APPLICATION_PATH “/resources”
resources.foo[] =
; ...
Or “Gimme gimme gimme!”
Within an Action Controller
$bootstrap = $this->getInvokeArg(‘bootstrap’);
$foo = $bootstrap->getResource(‘foo’);
Within a Bootstrap Resource
$bootstrap = $this->getBootstrap();
$bootstrap->init(‘bar’);
$bar = $bootstrap->getResource(‘b...
Statically AKA “Globally”
$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam(‘bootstrap’);
$foo ...
Which is better?
The Most Perfectest Bootstrap
class Bootstrap extends
Zend_Application_Bootstrap_Bootstrap
{
// Empty!!
}
Or Use ZF Bootstrap
[production]
bootstrap.path = APPLICATION_PATH
"/../library/Zend/Application/Bootstrap/Bootstrap.php"
...
Or “How to avoid hard-coding values”
_init*()
[production]
foo.bar = “bar”
[development : production]
foo.bar = “derp”
_init*()
protected function _initFoo()
{
$options = $this->getOptions();
assert($options[‘foo’][‘bar’] == ‘derp’); // true...
Resource Plugin
[production]
resources.foo.bar = “bar”
[development : production]
resources.foo.bar = “derp”
Resource Plugin
Class MyResource_Foo extends Zend_Application_Resource_Abstract
{
public function init()
{
$options = $thi...
Resource Plugin
Class MyResource_Foo extends Zend_Application_Resource_Abstract
{
protected $_bar;
public function setBar(...
Why Plugins Are Awesomesauce
• Reusable between projects
• Easily unit-tested
• Can be packaged with resource libraries
• ...
When Plugins Can Be Weaksauce
• Performance concerns with loading a class file
for each resource plugin
• Some editors (No...
print(“all done!”);
http://www.virgentech.com
djvirgen@gmail.com
Upcoming SlideShare
Loading in...5
×

Reusable bootstrap resources zend con 2010

5,268

Published on

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.

Published in: Technology, Art & Photos
3 Comments
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,268
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
128
Comments
3
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Reusable bootstrap resources zend con 2010"

  1. 1. Reusable Bootstrap Resources Hector Virgen ZendCon 2010
  2. 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. 3. Or “What does footwear have to do with the interwebs?”
  4. 4. Typical Bootstrap Tasks • Define constants • Set up include path • Set up autoloader • Initialize resources ▫ Database connections ▫ Session ▫ Web service clients
  5. 5. Or “Bootstrapping with Style”
  6. 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
  7. 7. Your App’s Configuration [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1
  8. 8. Bootstrap <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { }
  9. 9. Or “Loading up your application’s dependencies”
  10. 10. Choose Your Path Wisely, Grasshopper Bootstrap resources by: • Providing protected _init*() methods. • Using resource plugins.
  11. 11. _init*() Methods • Coded directly in the application’s Bootstrap class. • Return value is stored in bootstrap registry.
  12. 12. _init*() Methods class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initFoo() { $foo = new Foo(); return $foo; } }
  13. 13. Resource Plugin • Each resource is initialized in its own class. • Plugins are loaded in LIFO order. • Return value is stored in bootstrap registry.
  14. 14. Resource Plugin class MyResource_Foo extends Zend_Application_Resource_Abstract { public function init() { $foo = new Foo(); return $foo; } }
  15. 15. Ensure Resource Plugin is Loaded [production] pluginPaths.My_Resource = APPLICATION_PATH “/resources” resources.foo[] = ; or resources.foo.key = “value”
  16. 16. Or “Gimme gimme gimme!”
  17. 17. Within an Action Controller $bootstrap = $this->getInvokeArg(‘bootstrap’); $foo = $bootstrap->getResource(‘foo’);
  18. 18. Within a Bootstrap Resource $bootstrap = $this->getBootstrap(); $bootstrap->init(‘bar’); $bar = $bootstrap->getResource(‘bar’);
  19. 19. Statically AKA “Globally” $front = Zend_Controller_Front::getInstance(); $bootstrap = $front->getParam(‘bootstrap’); $foo = $bootstrap->getResource(‘foo’);
  20. 20. Which is better?
  21. 21. The Most Perfectest Bootstrap class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { // Empty!! }
  22. 22. Or Use ZF Bootstrap [production] bootstrap.path = APPLICATION_PATH "/../library/Zend/Application/Bootstrap/Bootstrap.php" bootstrap.class = ”Zend_Application_Bootstrap_Bootstrap”
  23. 23. Or “How to avoid hard-coding values”
  24. 24. _init*() [production] foo.bar = “bar” [development : production] foo.bar = “derp”
  25. 25. _init*() protected function _initFoo() { $options = $this->getOptions(); assert($options[‘foo’][‘bar’] == ‘derp’); // true }
  26. 26. Resource Plugin [production] resources.foo.bar = “bar” [development : production] resources.foo.bar = “derp”
  27. 27. Resource Plugin Class MyResource_Foo extends Zend_Application_Resource_Abstract { public function init() { $options = $this->getOptions(); assert($options[‘bar’] == ‘derp’); // true } }
  28. 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. 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. 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
  31. 31. print(“all done!”); http://www.virgentech.com djvirgen@gmail.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×