SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
Wednesday, February 24, 2010
PHP 5.3



Wednesday, February 24, 2010
Why?
                   •      Speed & Memory        •   Phar

                   •      Namespaces            •   ext/intl

                   •      Anonymous Functions   •   ext/fileinfo

                   •      Late Static Binding   •   ext/sqlite3

                   •      Syntax enhancements   •   mysqlnd

                   •      SPL



Wednesday, February 24, 2010
Speed & Memory
                                                                                                                        Drupal 20% faster
                                                                                                                        Qdig 2% faster
                                                                                                                        typo3 30% faster
                                                                                                                        wordpress 15% faster
                                                                                                                        xoops 10% faster
                                                                                                                        http://news.php.net/php.internals/36484




                         http://sebastian-bergmann.de/archives/745-Benchmark-of-PHP-Branches-3.0-through-5.3-CVS.html




                               gc_enable() : New Garbage Collector




Wednesday, February 24, 2010
Namespaces
                      http://php.net/manual/en/language.namespaces.php


                   • Autoloading made easy
                   • lithiumcoreLibraries
                   • li3_docscontrollersBrowserController
                   • http://groups.google.com/group/php-
                           standards/web/psr-0-final-proposal



Wednesday, February 24, 2010
Namespaces Example
                               <?php

                               namespace app;

                               use appmodelsPost;

                               class PostsController extends lithiumactionController {

                                    public function index() {
                                        $posts = Post::all();
                                        return compact(‘posts’);
                                    }
                               }

                               ?>




Wednesday, February 24, 2010
Autoloading
                http://groups.google.com/group/php-standards/web/psr-0-final-proposal

                  <?php

                  function __autoload($className)
                  {
                      $className = ltrim($className, '');
                      $fileName = '';
                      $namespace = '';
                      if ($lastNsPos = strripos($className, '')) {
                          $namespace = substr($className, 0, $lastNsPos);
                          $className = substr($className, $lastNsPos + 1);
                          $fileName = str_replace('', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
                      }
                      $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

                       require $fileName;
                  }

                  ?>




Wednesday, February 24, 2010
Anonymous Functions
                       http://php.net/manual/en/functions.anonymous.php


                   • Lambda
                         •     assigned to a variable

                         •     useful for recursion and multiple calls

                   • Closure
                         •     added as a method parameter

                         •     use() the parent scope




Wednesday, February 24, 2010
Lambda Example
                                 <?php

                                 $cube = function ($value) {
                                      return ($value * $value * $value);
                                 };
                                 $result = array_map($cube, array(1, 2, 3));
                                 var_dump($result);
                                 /*
                                 array
                                    0 => int 1
                                    1 => int 8
                                    2 => int 27
                                 */

                                 ?>




Wednesday, February 24, 2010
Another Lambda
                               $multiply = function ($value, $times) use (&$multiply) {
                                   return ($times > 0) ? $multiply($value * $value, --$times) : $value;
                               };
                               var_dump($multiply(2, 3));
                               /*
                               int 256
                               */




Wednesday, February 24, 2010
Closure Example
                      <?php
                      $data = 'string';
                      $result = array_filter(array(1, 2, 'string'), function ($value) use ($data) {
                           return ($value !== $data);
                      });
                      var_dump($result);
                      /*
                      array
                         0 => int 1
                         1 => int 2
                      */

                      ?>




Wednesday, February 24, 2010
Crazy Example
                         <?php

                         function Y($F) {
                             return current(array(function($f) { return $f($f); }))->__invoke(function($f) use ($F) {
                                 return $F(function($x) use ($f) {
                                     return $f($f)->__invoke($x);
                                 });
                             });
                         }

                         $factorial = Y(function($fact) {
                             return function($n) use ($fact) {
                                 return ($n <= 1) ? 1 : $n * $fact($n - 1);
                             };
                         });

                         var_dump($factorial(6));
                         /*
                         int 720
                         */

                         ?>




Wednesday, February 24, 2010
Why Static?
                               • Promotes proper
                                 application design

                               • Stateless
                               • Easier to access



Wednesday, February 24, 2010
Late Static Binding
                                      http://php.net/lsb
                               <?php
                               class A {
                                   public static function who() {
                                       return __CLASS__;
                                   }
                                   public static function test() {
                                       return static::who();
                                   }
                               }
                               class B extends A {
                                   public static function who() {
                                       return __CLASS__;
                                   }
                               }

                               $result = B::test();
                               var_dump($result);
                               /*
                               string 'B' (length=1)
                               */




Wednesday, February 24, 2010
Standard PHP Library (SPL)
                               http://us.php.net/manual/en/book.spl.php


                               •   spl_autoload_register()

                               •   Iterators

                               •   Exceptions

                               •   File Handling

                               •   Observer/Subject

                               •   Stack, Queue, Heap, ObjectStorage




Wednesday, February 24, 2010
Syntax Enhancements
                               http://php.net/manual/en/language.oop5.magic.php


                   •      PHP 5 < 5.3                     •   PHP 5.3

                         •      __set()/__get()               •   __callStatic()

                         •      __isset()/__unset()           •   __invoke()

                         •      __call()                      •   ?:




Wednesday, February 24, 2010
Phar
                               • PHP archives
                               • includable
                                 (include 'phar:///path/to/myphar.phar/file.php')


                               • stream accessible
                               • distributable


Wednesday, February 24, 2010
ext/intl
                               • Collator
                               • Locale
                               • IntlDateFormatter
                               • NumberFormatter


Wednesday, February 24, 2010
ext/fileinfo
                               <?php

                               $info = new finfo(FILEINFO_MIME);
                               $result = $info->file(__FILE__);
                               var_dump($result);
                               /*
                               string 'text/x-php; charset=us-ascii' (length=28)
                               */

                               $result = finfo_file(finfo_open(FILEINFO_MIME), __FILE__);
                               var_dump($result);
                               /*
                               string 'text/x-php; charset=us-ascii' (length=28)
                               */
                               ?>




Wednesday, February 24, 2010
ext/sqlite3
                   •       SQLite is a in-process library that implements a
                           self-contained, serverless, zero-configuration,
                           transactional SQL database engine (http://www.sqlite.org/
                           about.html)



                   •       A more compact format for database files.

                   •       Support for both UTF-8 and UTF-16 text.

                   •       Manifest typing and BLOB support.

                   •       New API via Sqlite3 class or sqlite3 functions



Wednesday, February 24, 2010
mysqlnd
                  • mysql native driver
                  • faster
                  • easier to compile
                  • transparent client, same old mysql/mysqli


Wednesday, February 24, 2010
Lithium
                               the most rad php framework




Wednesday, February 24, 2010
In Lithium
                               • Namespaces
                               • Anonymous Functions
                               • Late Static Binding
                               • Syntax Enhancements
                               • SPL
                               • Phar
                               • Sqlite3
Wednesday, February 24, 2010
Lithium Namespaces
                               •   action     •   security

                               •   analysis   •   storage

                               •   console    •   template

                               •   core       •   test

                               •   g11n       •   tests

                               •   net        •   util



Wednesday, February 24, 2010
Namespace Example
                   <?php

                   namespace appextensionshelper;

                   class Form extends lithiumtemplatehelperForm {

                           public function config(array $config = array()) {
                               ....
                           }
                   }




Wednesday, February 24, 2010
Anonymous Functions
                   Example
                               <?php

                               Validator::add('role', function ($value, $format, $options) {
                                   return (in_array($value, array('admin', 'editor', 'user')));
                               });

                               ?>




Wednesday, February 24, 2010
LSB Example
                   <?php

                   namespace lithiumcore;

                   class StaticObject {
                       ...
                   }
                                 <?php
                   ?>
                                 namespace lithiumdata;

                                 class Model extends lithiumcoreStaticObject {
                                     ...
                                 }

                                 ?>              <?php

                                                 namespace appmodels;

                                                 class Post extends lithiumdataModel {

                                                 }

                                                 ?>




Wednesday, February 24, 2010
__callStatic
                   <?php

                   namespace lithiumdata;

                   class Model extends lithiumcoreStaticObject {

                        public static function __callStatic($method, $params) {
                            ...
                        }

                   ?>
                                                 <?php

                                                 namespace appcontrollers

                                                 use appmodelsPost;

                                                 class PostsController extends lithiumactionController {

                                                      public function index() {
                                                          $posts = Post::all();
                                                          return compact('posts')
                                                      }
                                                 }

                                                 ?>




Wednesday, February 24, 2010
__invoke
           <?php

           namespace lithiumaction;

           class Controller extends lithiumcoreObject {

                public function __invoke($request, $dispatchParams, array $options = array()) {
                    ...
                }

           }                             <?php
           ?>
                                         namespace lithiumaction;

                                         class Dispatcher extends lithiumcoreStaticObject {

                                              protected static function _call($callable, $request, $params) {
                                                  ...
                                                      if (is_callable($callable = $params['callable'])) {
                                                          return $callable($params['request'], $params['params']);
                                                      }
                                                      throw new Exception('Result not callable');
                                                  ...
                                              }
                                         }
                                         ?>




Wednesday, February 24, 2010
SPL Iterators
                  <?php

                  protected function _cleanUp($path = null) {
                      $path = $path ?: LITHIUM_APP_PATH . '/resources/tmp/tests';
                      $path = $path[0] !== '/' ? LITHIUM_APP_PATH . '/resources/tmp/' . $path : $path;
                      if (!is_dir($path)) {
                          return;
                      }
                      $dirs = new RecursiveDirectoryIterator($path);
                      $iterator = new RecursiveIteratorIterator($dirs, RecursiveIteratorIterator::CHILD_FIRST);
                      foreach ($iterator as $item) {
                          if ($item->getPathname() === "{$path}/empty") continue;
                          ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
                      }
                  }

                  ?>




Wednesday, February 24, 2010
SPL Interfaces
                           <?php
                           /*
                             * @link http://us.php.net/manual/en/class.arrayaccess.php
                             * @link http://us.php.net/manual/en/class.iterator.php
                             * @link http://us.php.net/manual/en/class.countable.php
                             */
                           class Collection extends lithiumcoreObject implements ArrayAccess, Iterator, Countable {
                                ...
                           }

                           ?>




Wednesday, February 24, 2010
SPL autoloader
                               <?php

                               namespace lithiumcore;

                               class Libraries {
                                   ...
                                   public static function add($name, $config = array()) {
                                       ...
                                       if (!empty($config['loader'])) {
                                           spl_autoload_register($config['loader']);
                                       }
                                       ...
                                   }
                                   ...
                               }
                               ?>




Wednesday, February 24, 2010
Phar
                               <?php

                               namespace lithiumconsolecommand;

                               use Phar;

                               class Library extends lithiumconsoleCommand {

                                    public function archive() {
                                        ....

                                        $archive = new Phar("{$path}.phar");
                                        $from = $this->_toPath($from);
                                        $result = (boolean) $archive->buildFromDirectory($from, $this->filter);
                                        ...

                                        $archive->compress(Phar::GZ);
                                        return true;
                                    }
                               }

                               ?>




Wednesday, February 24, 2010
Sqlite3
                               <?php

                               Connections::add('default', array(
                                   'type' => 'database',
                                   'adapter' => 'Sqlite3',
                                   'database' => LITHIUM_APP_PATH . '/resources/db/sqlite.db'
                               ));

                               ?>




Wednesday, February 24, 2010
By Lithium
                   • Simple, Uniform API
                   • Unified Constructor
                   • Adaptable
                   • Filters (Aspect Oriented Programming)
                   • $_classes (Dependency Injection)
                   • Collections
Wednesday, February 24, 2010
Simple Uniform API
                   • logical namespaces and classes
                   • simple method names
                   • <= 3 params per method
                   • $config
                   • $options

Wednesday, February 24, 2010
Unified Constructor
                   • $config
                   • always an array
                   • check for $_autoConfig
                   • _init() and __init()


Wednesday, February 24, 2010
Adaptable
                               • securityAuth
                               • storageSession
                               • storageCache
                               • g11nCatalog
                               • dataConnections
                               • analysisLogger

Wednesday, February 24, 2010
Filters
                • Aspect Oriented Programming
                       secondary or supporting functions are isolated from the main
                       program's business logic...increase modularity by allowing the
                       separation of cross-cutting concerns...
                       (http://en.wikipedia.org/wiki/Aspect-oriented_programming)



                • modify core functionality without
                       extending a class

                • define your own callbacks
                • @filter

Wednesday, February 24, 2010
Routes Filter
                               <?php

                               use lithiumactionDispatcher;

                               Dispatcher::applyFilter('run', function($self, $params, $chain) {
                                   include __DIR__ . '/routes.php';
                                   return $chain->next($self, $params, $chain);
                               });

                               ?>




Wednesday, February 24, 2010
Asset Filter
                        <?php

                        use lithiumactionDispatcher;
                        use lithiumcoreLibraries;
                        use lithiumnethttpMedia;

                        Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
                            list($plugin, $asset) = explode('/', $params['request']->url, 2) + array("", "");
                            if ($asset && $library = Libraries::get($plugin)) {
                                $asset = "{$library['path']}/webroot/{$asset}";

                                   if (file_exists($asset)) {
                                       return function () use ($asset) {
                                           $info = pathinfo($asset);
                                           $type = Media::type($info['extension']);
                                           header("Content-type: {$type['content']}");
                                           return file_get_contents($asset);
                                       };
                                   }
                               }
                               return $chain->next($self, $params, $chain);
                        });

                        ?>




Wednesday, February 24, 2010
Xhprof Filter
                               <?php

                               use lithiumactionDispatcher;

                               Dispatcher::applyFilter('run', function($self, $params, $chain) {
                                   xhprof_enable();
                                   $data = $chain->next($self, $params, $chain);
                                   $xhprof_data = xhprof_disable();

                                     $XHPROF_ROOT = '/usr/local/php/5.3.1/lib/xhprof';
                                     include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
                                     include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

                                     $xhprof_runs = new XHProfRuns_Default();
                                     $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_lithium");

                                     return $data;
                               });

                               ?>




Wednesday, February 24, 2010
Save Filter
                       <?php

                       namespace appmodels;

                       class Paste extends lithiumdataModel {

                               public static function __init(array $options = array()) {
                                   parent::__init($options);
                                   static::applyFilter('save', function($self, $params, $chain) {
                                       $document = $params['record'];
                                       if (!$document->id) {
                                           $document->created = date('Y-m-d h:i:s');
                                       }
                                       if (!empty($params['data'])) {
                                           $document->set($params['data']);
                                       }
                                       $document->parsed = $self::parse($document->content, $document->language);
                                       $document->preview = substr($document->content, 0, 100);
                                       $document->modified = date('Y-m-d h:i:s');
                                       $params['record'] = $document;
                                       return $chain->next($self, $params, $chain);
                                   });
                               }
                       }

                       ?>




Wednesday, February 24, 2010
$_classes
                • Dependency Injection
                       a technique for supplying an external dependency (i.e. a
                       reference) to a software component - that is, indicating to a part
                       of a program which other parts it can use...
                       (http://en.wikipedia.org/wiki/Dependency_injection)



                • modify core functionality without
                       extending a class




Wednesday, February 24, 2010
$_classes Example
                               <?php

                               namespace lithiumconsole;

                               class Library extends lithiumconsoleCommand {
                                   ...
                                   protected $_classes = array(
                                       'service' => 'lithiumnethttpService',
                                       'response' => 'lithiumconsoleResponse'
                                   );
                                   ...
                               }
                               ?>




Wednesday, February 24, 2010
$_classes Example
                               <?php
                               namespace lithiumtestscasesconsole;

                               use lithiumconsoleRequest;

                               class LibraryTest extends lithiumtestUnit {
                                   ...
                                   public function setUp() {
                                       ...
                                       $this->classes = array(
                                           'service' => 'lithiumtestsmocksconsolecommandMockLibraryService',
                                           'response' => 'lithiumtestsmocksconsoleMockResponse'
                                       );
                                       ...
                                   }
                                   ...
                                   public function testArchiveNoLibrary() {
                                       ...
                                       $app = new Library(array(
                                           'request' => new Request(), 'classes' => $this->classes
                                       ));
                                       $expected = true;
                                       $result = $app->archive();
                                       $this->assertEqual($expected, $result);
                                   }
                                   ...
                               }
                               ?>




Wednesday, February 24, 2010
Collections
                         • lithiumutilCollection
                         • lithiumdataCollection
                          • lithiumdatacollectionRecordSet
                          • lithiumdatacollectionDocument
                         • lithiumtestGroup

Wednesday, February 24, 2010
Collections Example
            <?php

            use lithiumutilCollection;

            $coll = new Collection(array('items' => array(0, 1, 2, 3, 4)));
            $coll->first();   // 1 (the first non-empty value)
            $coll->current(); // 0
            $coll->next();    // 1
            $coll->next();    // 2
            $coll->next();    // 3
                                                                       <?php
            $coll->prev();    // 2
            $coll->rewind(); // 0
                                                                       use lithiumtestGroup;
            $coll->each(function($value) {
                return $value + 1;
                                                                       $group = new Group(array('items' => array(
            });
                                                                           'lithiumtestscasescoreLibraries',
            $coll->to('array'); // array(1, 2, 3, 4, 5)
                                                                           'lithiumtestscasescoreObject',
                                                                       ))
            ?>
                                                                       $resul = $group->tests()->run();

                                                                      ?>




Wednesday, February 24, 2010
More Lithium
                   • Integrated Test Suite for fast TDD
                   • Command Line Framework
                   • Document Based Data Sources
                   • Object based Record Sets with access
                           to non static model methods

                   • Transparent content type rendering

Wednesday, February 24, 2010
Still More Lithium
                   • Automatic output escaping
                   • Http Services
                   • g11n for internationalized applications
                   • Authentication
                   • Session/Cookie Handling
                   • Authorization (1.0)
Wednesday, February 24, 2010
Even More Lithium
                               • Validator
                               • Logging
                               • Debugger
                               • Parser
                               • Inspector
                               • Sockets
Wednesday, February 24, 2010
Lithium Integrations
                   • Use 3rd party libraries
                   • Easy to add with Libraries class
                   • Especially simple when PSR-0 is
                           followed

                   • Access classes in a standard way


Wednesday, February 24, 2010
Using Zend
                               http://rad-dev.org/lithium/wiki/guides/using/zend
                 <?php

                 Libraries::add("Zend", array(
                     "prefix" => "Zend_",
                     'path' => '/htdocs/libraries/Zend/trunk/library/Zend',
                     "includePath" => '/htdocs/libraries/Zend/trunk/library',
                     "bootstrap" => "Loader/Autoloader.php",
                     "loader" => array("Zend_Loader_Autoloader", "autoload"),
                     "transform" => function($class) { return str_replace("_", "/", $class) . ".php"; }
                 ));

                 ?>
                                            <?php

                                            namespace appcontrollers;

                                            use Zend_Mail_Storage_Pop3;

                                            class EmailController extends lithiumactionController {

                                                 public function index() {
                                                     $mail = new Zend_Mail_Storage_Pop3(array(
                                                         'host' => 'localhost', 'user' => 'test', 'password' => 'test'
                                                     ));
                                                     return compact('mail');
                                                 }
                                            }

                                            ?>



Wednesday, February 24, 2010
Plugins
                   • namespaces allow for a true plugin
                           system

                   • modify application with filters
                   • add extensions
                   • share your handy work


Wednesday, February 24, 2010
Some Plugins
                                 • li3_docs
                                 • li3_oauth
                                 • li3_bot
                                 • li3_doctrine
                                 • li3_lab

Wednesday, February 24, 2010
Wednesday, February 24, 2010
lithium_qa
                   • http://rad-dev.org/lithium/wiki/standards
                   • Check syntax of your code
                   • Shows rules violations in your code
                   • Automate the process with SCM hooks


Wednesday, February 24, 2010
Lithium
                               the most rad php framework

               • http://lithify.me
               • http://rad-dev.org/lithium/wiki
               • http://www.ohloh.net/p/lithium
               • http://twitter.com/UnionOfRAD
               • irc://irc.freenode.net/#li3
               •       http://search.twitter.com/search?q=%23li3


Wednesday, February 24, 2010

Weitere ähnliche Inhalte

Was ist angesagt?

The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Fabien Potencier
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Fabien Potencier
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Fabien Potencier
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixturesBill Chang
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Fabien Potencier
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mockingKonstantin Kudryashov
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 

Was ist angesagt? (20)

The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 

Ähnlich wie PHP 5.3 and Lithium: the most rad php framework

IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpen Gurukul
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Jason Lotito
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2Elizabeth Smith
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...James Titcumb
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 

Ähnlich wie PHP 5.3 and Lithium: the most rad php framework (20)

IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Solid principles
Solid principlesSolid principles
Solid principles
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Magento code audit
Magento code auditMagento code audit
Magento code audit
 

Kürzlich hochgeladen

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

PHP 5.3 and Lithium: the most rad php framework

  • 3. Why? • Speed & Memory • Phar • Namespaces • ext/intl • Anonymous Functions • ext/fileinfo • Late Static Binding • ext/sqlite3 • Syntax enhancements • mysqlnd • SPL Wednesday, February 24, 2010
  • 4. Speed & Memory Drupal 20% faster Qdig 2% faster typo3 30% faster wordpress 15% faster xoops 10% faster http://news.php.net/php.internals/36484 http://sebastian-bergmann.de/archives/745-Benchmark-of-PHP-Branches-3.0-through-5.3-CVS.html gc_enable() : New Garbage Collector Wednesday, February 24, 2010
  • 5. Namespaces http://php.net/manual/en/language.namespaces.php • Autoloading made easy • lithiumcoreLibraries • li3_docscontrollersBrowserController • http://groups.google.com/group/php- standards/web/psr-0-final-proposal Wednesday, February 24, 2010
  • 6. Namespaces Example <?php namespace app; use appmodelsPost; class PostsController extends lithiumactionController { public function index() { $posts = Post::all(); return compact(‘posts’); } } ?> Wednesday, February 24, 2010
  • 7. Autoloading http://groups.google.com/group/php-standards/web/psr-0-final-proposal <?php function __autoload($className) { $className = ltrim($className, ''); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; } ?> Wednesday, February 24, 2010
  • 8. Anonymous Functions http://php.net/manual/en/functions.anonymous.php • Lambda • assigned to a variable • useful for recursion and multiple calls • Closure • added as a method parameter • use() the parent scope Wednesday, February 24, 2010
  • 9. Lambda Example <?php $cube = function ($value) { return ($value * $value * $value); }; $result = array_map($cube, array(1, 2, 3)); var_dump($result); /* array 0 => int 1 1 => int 8 2 => int 27 */ ?> Wednesday, February 24, 2010
  • 10. Another Lambda $multiply = function ($value, $times) use (&$multiply) { return ($times > 0) ? $multiply($value * $value, --$times) : $value; }; var_dump($multiply(2, 3)); /* int 256 */ Wednesday, February 24, 2010
  • 11. Closure Example <?php $data = 'string'; $result = array_filter(array(1, 2, 'string'), function ($value) use ($data) { return ($value !== $data); }); var_dump($result); /* array 0 => int 1 1 => int 2 */ ?> Wednesday, February 24, 2010
  • 12. Crazy Example <?php function Y($F) { return current(array(function($f) { return $f($f); }))->__invoke(function($f) use ($F) { return $F(function($x) use ($f) { return $f($f)->__invoke($x); }); }); } $factorial = Y(function($fact) { return function($n) use ($fact) { return ($n <= 1) ? 1 : $n * $fact($n - 1); }; }); var_dump($factorial(6)); /* int 720 */ ?> Wednesday, February 24, 2010
  • 13. Why Static? • Promotes proper application design • Stateless • Easier to access Wednesday, February 24, 2010
  • 14. Late Static Binding http://php.net/lsb <?php class A { public static function who() { return __CLASS__; } public static function test() { return static::who(); } } class B extends A { public static function who() { return __CLASS__; } } $result = B::test(); var_dump($result); /* string 'B' (length=1) */ Wednesday, February 24, 2010
  • 15. Standard PHP Library (SPL) http://us.php.net/manual/en/book.spl.php • spl_autoload_register() • Iterators • Exceptions • File Handling • Observer/Subject • Stack, Queue, Heap, ObjectStorage Wednesday, February 24, 2010
  • 16. Syntax Enhancements http://php.net/manual/en/language.oop5.magic.php • PHP 5 < 5.3 • PHP 5.3 • __set()/__get() • __callStatic() • __isset()/__unset() • __invoke() • __call() • ?: Wednesday, February 24, 2010
  • 17. Phar • PHP archives • includable (include 'phar:///path/to/myphar.phar/file.php') • stream accessible • distributable Wednesday, February 24, 2010
  • 18. ext/intl • Collator • Locale • IntlDateFormatter • NumberFormatter Wednesday, February 24, 2010
  • 19. ext/fileinfo <?php $info = new finfo(FILEINFO_MIME); $result = $info->file(__FILE__); var_dump($result); /* string 'text/x-php; charset=us-ascii' (length=28) */ $result = finfo_file(finfo_open(FILEINFO_MIME), __FILE__); var_dump($result); /* string 'text/x-php; charset=us-ascii' (length=28) */ ?> Wednesday, February 24, 2010
  • 20. ext/sqlite3 • SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine (http://www.sqlite.org/ about.html) • A more compact format for database files. • Support for both UTF-8 and UTF-16 text. • Manifest typing and BLOB support. • New API via Sqlite3 class or sqlite3 functions Wednesday, February 24, 2010
  • 21. mysqlnd • mysql native driver • faster • easier to compile • transparent client, same old mysql/mysqli Wednesday, February 24, 2010
  • 22. Lithium the most rad php framework Wednesday, February 24, 2010
  • 23. In Lithium • Namespaces • Anonymous Functions • Late Static Binding • Syntax Enhancements • SPL • Phar • Sqlite3 Wednesday, February 24, 2010
  • 24. Lithium Namespaces • action • security • analysis • storage • console • template • core • test • g11n • tests • net • util Wednesday, February 24, 2010
  • 25. Namespace Example <?php namespace appextensionshelper; class Form extends lithiumtemplatehelperForm { public function config(array $config = array()) { .... } } Wednesday, February 24, 2010
  • 26. Anonymous Functions Example <?php Validator::add('role', function ($value, $format, $options) { return (in_array($value, array('admin', 'editor', 'user'))); }); ?> Wednesday, February 24, 2010
  • 27. LSB Example <?php namespace lithiumcore; class StaticObject { ... } <?php ?> namespace lithiumdata; class Model extends lithiumcoreStaticObject { ... } ?> <?php namespace appmodels; class Post extends lithiumdataModel { } ?> Wednesday, February 24, 2010
  • 28. __callStatic <?php namespace lithiumdata; class Model extends lithiumcoreStaticObject { public static function __callStatic($method, $params) { ... } ?> <?php namespace appcontrollers use appmodelsPost; class PostsController extends lithiumactionController { public function index() { $posts = Post::all(); return compact('posts') } } ?> Wednesday, February 24, 2010
  • 29. __invoke <?php namespace lithiumaction; class Controller extends lithiumcoreObject { public function __invoke($request, $dispatchParams, array $options = array()) { ... } } <?php ?> namespace lithiumaction; class Dispatcher extends lithiumcoreStaticObject { protected static function _call($callable, $request, $params) { ... if (is_callable($callable = $params['callable'])) { return $callable($params['request'], $params['params']); } throw new Exception('Result not callable'); ... } } ?> Wednesday, February 24, 2010
  • 30. SPL Iterators <?php protected function _cleanUp($path = null) { $path = $path ?: LITHIUM_APP_PATH . '/resources/tmp/tests'; $path = $path[0] !== '/' ? LITHIUM_APP_PATH . '/resources/tmp/' . $path : $path; if (!is_dir($path)) { return; } $dirs = new RecursiveDirectoryIterator($path); $iterator = new RecursiveIteratorIterator($dirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $item) { if ($item->getPathname() === "{$path}/empty") continue; ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname()); } } ?> Wednesday, February 24, 2010
  • 31. SPL Interfaces <?php /* * @link http://us.php.net/manual/en/class.arrayaccess.php * @link http://us.php.net/manual/en/class.iterator.php * @link http://us.php.net/manual/en/class.countable.php */ class Collection extends lithiumcoreObject implements ArrayAccess, Iterator, Countable { ... } ?> Wednesday, February 24, 2010
  • 32. SPL autoloader <?php namespace lithiumcore; class Libraries { ... public static function add($name, $config = array()) { ... if (!empty($config['loader'])) { spl_autoload_register($config['loader']); } ... } ... } ?> Wednesday, February 24, 2010
  • 33. Phar <?php namespace lithiumconsolecommand; use Phar; class Library extends lithiumconsoleCommand { public function archive() { .... $archive = new Phar("{$path}.phar"); $from = $this->_toPath($from); $result = (boolean) $archive->buildFromDirectory($from, $this->filter); ... $archive->compress(Phar::GZ); return true; } } ?> Wednesday, February 24, 2010
  • 34. Sqlite3 <?php Connections::add('default', array( 'type' => 'database', 'adapter' => 'Sqlite3', 'database' => LITHIUM_APP_PATH . '/resources/db/sqlite.db' )); ?> Wednesday, February 24, 2010
  • 35. By Lithium • Simple, Uniform API • Unified Constructor • Adaptable • Filters (Aspect Oriented Programming) • $_classes (Dependency Injection) • Collections Wednesday, February 24, 2010
  • 36. Simple Uniform API • logical namespaces and classes • simple method names • <= 3 params per method • $config • $options Wednesday, February 24, 2010
  • 37. Unified Constructor • $config • always an array • check for $_autoConfig • _init() and __init() Wednesday, February 24, 2010
  • 38. Adaptable • securityAuth • storageSession • storageCache • g11nCatalog • dataConnections • analysisLogger Wednesday, February 24, 2010
  • 39. Filters • Aspect Oriented Programming secondary or supporting functions are isolated from the main program's business logic...increase modularity by allowing the separation of cross-cutting concerns... (http://en.wikipedia.org/wiki/Aspect-oriented_programming) • modify core functionality without extending a class • define your own callbacks • @filter Wednesday, February 24, 2010
  • 40. Routes Filter <?php use lithiumactionDispatcher; Dispatcher::applyFilter('run', function($self, $params, $chain) { include __DIR__ . '/routes.php'; return $chain->next($self, $params, $chain); }); ?> Wednesday, February 24, 2010
  • 41. Asset Filter <?php use lithiumactionDispatcher; use lithiumcoreLibraries; use lithiumnethttpMedia; Dispatcher::applyFilter('_callable', function($self, $params, $chain) { list($plugin, $asset) = explode('/', $params['request']->url, 2) + array("", ""); if ($asset && $library = Libraries::get($plugin)) { $asset = "{$library['path']}/webroot/{$asset}"; if (file_exists($asset)) { return function () use ($asset) { $info = pathinfo($asset); $type = Media::type($info['extension']); header("Content-type: {$type['content']}"); return file_get_contents($asset); }; } } return $chain->next($self, $params, $chain); }); ?> Wednesday, February 24, 2010
  • 42. Xhprof Filter <?php use lithiumactionDispatcher; Dispatcher::applyFilter('run', function($self, $params, $chain) { xhprof_enable(); $data = $chain->next($self, $params, $chain); $xhprof_data = xhprof_disable(); $XHPROF_ROOT = '/usr/local/php/5.3.1/lib/xhprof'; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_lithium"); return $data; }); ?> Wednesday, February 24, 2010
  • 43. Save Filter <?php namespace appmodels; class Paste extends lithiumdataModel { public static function __init(array $options = array()) { parent::__init($options); static::applyFilter('save', function($self, $params, $chain) { $document = $params['record']; if (!$document->id) { $document->created = date('Y-m-d h:i:s'); } if (!empty($params['data'])) { $document->set($params['data']); } $document->parsed = $self::parse($document->content, $document->language); $document->preview = substr($document->content, 0, 100); $document->modified = date('Y-m-d h:i:s'); $params['record'] = $document; return $chain->next($self, $params, $chain); }); } } ?> Wednesday, February 24, 2010
  • 44. $_classes • Dependency Injection a technique for supplying an external dependency (i.e. a reference) to a software component - that is, indicating to a part of a program which other parts it can use... (http://en.wikipedia.org/wiki/Dependency_injection) • modify core functionality without extending a class Wednesday, February 24, 2010
  • 45. $_classes Example <?php namespace lithiumconsole; class Library extends lithiumconsoleCommand { ... protected $_classes = array( 'service' => 'lithiumnethttpService', 'response' => 'lithiumconsoleResponse' ); ... } ?> Wednesday, February 24, 2010
  • 46. $_classes Example <?php namespace lithiumtestscasesconsole; use lithiumconsoleRequest; class LibraryTest extends lithiumtestUnit { ... public function setUp() { ... $this->classes = array( 'service' => 'lithiumtestsmocksconsolecommandMockLibraryService', 'response' => 'lithiumtestsmocksconsoleMockResponse' ); ... } ... public function testArchiveNoLibrary() { ... $app = new Library(array( 'request' => new Request(), 'classes' => $this->classes )); $expected = true; $result = $app->archive(); $this->assertEqual($expected, $result); } ... } ?> Wednesday, February 24, 2010
  • 47. Collections • lithiumutilCollection • lithiumdataCollection • lithiumdatacollectionRecordSet • lithiumdatacollectionDocument • lithiumtestGroup Wednesday, February 24, 2010
  • 48. Collections Example <?php use lithiumutilCollection; $coll = new Collection(array('items' => array(0, 1, 2, 3, 4))); $coll->first(); // 1 (the first non-empty value) $coll->current(); // 0 $coll->next(); // 1 $coll->next(); // 2 $coll->next(); // 3 <?php $coll->prev(); // 2 $coll->rewind(); // 0 use lithiumtestGroup; $coll->each(function($value) { return $value + 1; $group = new Group(array('items' => array( }); 'lithiumtestscasescoreLibraries', $coll->to('array'); // array(1, 2, 3, 4, 5) 'lithiumtestscasescoreObject', )) ?> $resul = $group->tests()->run(); ?> Wednesday, February 24, 2010
  • 49. More Lithium • Integrated Test Suite for fast TDD • Command Line Framework • Document Based Data Sources • Object based Record Sets with access to non static model methods • Transparent content type rendering Wednesday, February 24, 2010
  • 50. Still More Lithium • Automatic output escaping • Http Services • g11n for internationalized applications • Authentication • Session/Cookie Handling • Authorization (1.0) Wednesday, February 24, 2010
  • 51. Even More Lithium • Validator • Logging • Debugger • Parser • Inspector • Sockets Wednesday, February 24, 2010
  • 52. Lithium Integrations • Use 3rd party libraries • Easy to add with Libraries class • Especially simple when PSR-0 is followed • Access classes in a standard way Wednesday, February 24, 2010
  • 53. Using Zend http://rad-dev.org/lithium/wiki/guides/using/zend <?php Libraries::add("Zend", array( "prefix" => "Zend_", 'path' => '/htdocs/libraries/Zend/trunk/library/Zend', "includePath" => '/htdocs/libraries/Zend/trunk/library', "bootstrap" => "Loader/Autoloader.php", "loader" => array("Zend_Loader_Autoloader", "autoload"), "transform" => function($class) { return str_replace("_", "/", $class) . ".php"; } )); ?> <?php namespace appcontrollers; use Zend_Mail_Storage_Pop3; class EmailController extends lithiumactionController { public function index() { $mail = new Zend_Mail_Storage_Pop3(array( 'host' => 'localhost', 'user' => 'test', 'password' => 'test' )); return compact('mail'); } } ?> Wednesday, February 24, 2010
  • 54. Plugins • namespaces allow for a true plugin system • modify application with filters • add extensions • share your handy work Wednesday, February 24, 2010
  • 55. Some Plugins • li3_docs • li3_oauth • li3_bot • li3_doctrine • li3_lab Wednesday, February 24, 2010
  • 57. lithium_qa • http://rad-dev.org/lithium/wiki/standards • Check syntax of your code • Shows rules violations in your code • Automate the process with SCM hooks Wednesday, February 24, 2010
  • 58. Lithium the most rad php framework • http://lithify.me • http://rad-dev.org/lithium/wiki • http://www.ohloh.net/p/lithium • http://twitter.com/UnionOfRAD • irc://irc.freenode.net/#li3 • http://search.twitter.com/search?q=%23li3 Wednesday, February 24, 2010