View
27.312
Download
2
Category
Preview:
DESCRIPTION
Details how and when to integrate Zend Framework components with Symfony, and provides an overview of several components particularly useful to Symfony developers.
Citation preview
2. Matthew Weier O'Phinney
3. Zend Framework contributor since 2006 4. Project Lead since 2009 5. Zend Framework: Some Background 6. Zend Framework is
7. a full-stack framework? 8. Both. 9. 10. Comparing Symfony to Zend Framework 11. Why bother?
12. Both hit different sweet spots for developers 13. You can use them together (with Symfony Components, this goes both ways!) 14. Why use ZF with Symfony? 15. Take advantage of ZF features
16. Support for Lucene indexes 17. PDF generation 18. Queueing 19. Cloud computing (storage, DBs,message queues) 20. Asynchronous Processing
Examples:
21. Interacting with 3 rdparty web services 22. Complex or expensive RDBMS operations May require a console runner or interaction with a message queue 23. Exposing Web Services
24. SOAP 25. JSON-RPC 26. AMF 27. How do I use Zend Framework with Symfony? 28. Methods for integration
29. classProjectConfigurationextendssfProjectConfiguration { static protected $zendAutoloader = false; static public function registerZend() { if (!self:: $zendAutoloader ) { set_include_path( implode ( PATH_SEPARATOR, array ( sfConfig::get( 'sf_lib_dir' ) . '/vendor' , get_include_path(), ))) require_once 'Zend/Loader/Autoloader.php' ; self:: $zendAutoloader = Zend_Loader_Autoloader::getInstance(); } return self:: $zendAutoloader } } 30. Taking it further... classProjectConfigurationextendssfProjectConfiguration { // ... // Autoload PEAR classes, too... static public function registerPear() { self::registerZend()->setFallbackAutoloader(); } } 31. Using Zend components: classreaderReadTaskextendssfBaseTask { // ... public function execute( $arguments = array (), $options = array () ) { // ... ProjectConfiguration::registerZend(); $feed = Zend_Feed_Reader::import( $feed ); // ... } } Just start using classes! 32. Some components you might want to use 33. Service components
Zend_Service_Amazon
Zend_Service_Akismet
Many, many more
34. Feed tools
35. Zend_Feed_Writer the mirror of Zend_Feed_Reader, aiding in construction of feeds 36. Zend_Feed_Pubsubhubbub providing support for interacting with PuSH hubs, automating feed discovery and publication 37. $feed= Zend_Feed_Reader::import( $feedUri ); $metadata = array ( 'title' => $feed ->getTitle(), 'description' => $feed ->getDescription(), ); $entries = array (); foreach ( $feed as $entry ) { $entries [] = array ( 'title' => $entry ->getTitle(), 'link' => $entry ->getLink(), 'timestamp' => $entry ->getDateModified(), ); } 38. $feed= new Zend_Feed_Writer_Feed; $feed ->setTitle( $someTitle ) ->setLink( $url ) ->setDescription( $description ); $entry = $feed ->createEntry(); $entry ->setTitle( $entryTitle ) ->setLink( $entryLink ) ->setDateModified( time ()); $feed ->addEntry( $entry ); echo $feed ->export( 'atom' ); 39. Lucene Indexes
40. Zend_Search_Luceneis binary-compatible with Lucene indexes
41. Supports generation of Lucene indexes 42. if( is_dir ( $indexDir )) { $index = Zend_Search_Lucene::open( $indexDir ); } else { $index = Zend_Search_Lucene::create( $indexDir ); } $doc = new Zend_Search_Lucene_Document(); $doc ->addField(Zend_Search_Lucene_Field::Keyword( 'uri' , $url )); $doc ->addField(Zend_Search_Lucene_Field::UnIndexed( 'timestamp' , $ts )); $doc ->addField(Zend_Search_Lucene_Field::Text( 'synopsis' , $synopsis )); $doc ->addField(Zend_Search_Lucene_Field::Unstored( 'content' , $content )); $index ->addDocument( $doc ); 43. $hits=$index ->find( '+hello -dolly' ); foreach ( $hits as $hit ) { printf ( '%s ... (created %s)' , $hit ->uri, $hit ->synopsis, $hit ->timestamp ); } 44. PDF manipulation
45. Zend_Pdfoffers support for
46. Creating new PDF files 47. $pdf = Zend_Pdf::load( $pdfFile ); $page = $pdf ->pages[0]; $font = Zend_Pdf_Font::fontWithName( Zend_Pdf_Font::FONT_HELVETICA ); $page ->setFont( $font , 36) ->setFillColor( Zend_Pdf_Color_Html::color( '#CCC' )) ->drawText( 'U R H2O-marked' , 60, 500); $pdf ->save( $pdfFile ); 48. Sidetrack: On Domain Models 49. Why?
50. When resource usage needs to be kept minimal 51. When performing processing that is non-web specific (console, RDBMS, communicating with web services, periodic tasks, etc.) 52. More reasons why
53. Typically less complex testing harnesses Reduce dependencies
54. Can be more performant (less bootstrapping and fewer resources often leads to faster code) Use in more environments 55. Domain Model roles
56. AggregatesorCollections of entities 57. Mappers map entities to data persistence, and vice versa. Could be an ORM. Returns entities and aggregates. 58. Service layer objects the public API for your domain model; uses other domain objects and performs business logic. 59. Service Layer in perspective Data Access Objects and Data store(s) Data Mappers Entities Service Layer 60. Considerations
61. Consider returning Zend_Paginator objects
62. Iterable 63. Consumers do not need to understand implementation 64. More Considerations
65. Interactions between entities 66. ACLs 67. Back on track: Asynchronous Processing 68. Queues
69. Use cases
70. Update indexes later 71. Interact with 3rd party APIs later (Salesforce, SugarCRM, etc) 72. $queue= new Zend_Queue( 'MemcacheQ' ,array ( 'name' => 'my-uber-queue' , 'host' => 'queue.host.tld' , )); $queue -> send ( 'Some message' ); $messages=$queue ->receive(5); echo count ( $queue ), " messages registered " ; foreach ( $messages as $message ) { // do something with message, // typically $message->body $queue ->deleteMessage( $message ); }i 73. Exposing Web Services 74. Goals of good web services
75. Respond quickly 76. Correspond to existing service objects 77. Service types offered by ZF
78. JSON-RPC- RPC using JSON as the serialization format; clients in Dojo,YUI and ExtJS 79. XML-RPC- Standard protocol used everywhere 80. SOAP- with support for auto-generationof WSDL and serialization to and from PHP objects 81. Basics
82. Addclasses and/or functions as callbacks 83. Handlethe request 84. $server= new Zend_XmlRpc_Server(); $server ->setClass( 'My_Service_ApiClass' , 'api' ); echo $server ->handle(); if( $_SERVER [ 'REQUEST_METHOD' ] =='GET' ) { $server = new Zend_Soap_AutoDiscover(); } else { $server = new Zend_Soap_Server( $thisScript ); } $server ->setClass( 'My_Service_ApiClass' ); $server ->handle(); 85. Service Layer Objects are King
86. Define your public API in your service layer, and re-use however you need it
87. Exposing Ajax Endpoints
88. JSON-REST is becoming popular; consider exposing an alternate lightweight RESTful MVC that consumes your service objects, or Symfony's REST API. Service layer objects, again, become your friend 89. Takeaways 90.
91. Consider writing a rich domain model separate from your application that draws on components from a variety of sources. 92. Offload processing when you can, and setup service endpoints outside your main web application for performance reasons. 93. Resources
94. My slides on Slideshare http://slideshare.net/weierophinney 95. Rate this talk: http://joind.in/1413 96. Thank you!
Recommended