Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

121
A Framework for People Who Hate Frameworks.

description

This is the updated version of Joël and my standard Lithium talk, with a few tweaks and updates since the last time we gave it.

Transcript of Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Page 1: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

A Framework for People Who Hate Frameworks.

Page 2: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

A movement in 3 parts

•Frameworks suck

•Everything you know is wrong

•Lithium tries to suck less

Page 3: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The first part.

Page 4: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Let’s get one thing out of the way:

Page 5: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Lithium sucks.

Page 6: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

But that’s okay.

Page 7: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Because your framework sucks, too.

Page 8: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Page 9: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Why?

Page 10: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Frameworks Suck

•Code you will never use.

•Complexity overhead.

•You didn’t write it.

Page 11: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Martin Fowler.Also,

Page 12: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

His name is the biggest, so it’s his

fault.

Page 13: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

We’re not saying design patterns are bad.

Quite the opposite.

Page 14: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Lithium implements many well known design patterns.

Page 15: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Problem™

Page 16: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Some patterns only treat the symptoms,

instead of the cause.

Page 17: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Some examples:

Page 18: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Object dependencies.“The principle of separating configuration from use.”

Page 19: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Configuration.

Page 20: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Everyone does it differently.

Page 21: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Sometimes in the same framework.

Page 22: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Sometimes in the same class.

Page 23: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Dependency injection.

Page 24: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

A great idea!

Page 25: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

... but you need to understand what you’re doing.

Page 26: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Some patterns were implemented in Java, to

solve language problems that PHP just doesn’t

have.

Page 27: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

“Design Patterns In Dynamic Languages”

Peter Norvig

http://norvig.com/design-patterns/

Page 28: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Try this some time...

Page 29: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Page 30: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The second part.

Page 31: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Everythingyou knowis wrong.

Page 32: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The sun does notrevolve around OOP

Galileo facing the Roman Inquistion- Cristiano Banti (1857)

...nevertheless,it moves.

Page 33: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Dependency injection.

Page 34: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Dependency Injection

•Fixes the problem of static dependencies

•Ignores the problem of static relationships

•Same methods called on injected classes

•No way to introduce new relationships

•Higher overhead, more boilerplate code

Page 35: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Dependency Injection

•Various attempts at making DI work better:

•DI Container

•Using dynamic nature of PHP to your advantage.

Page 36: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Coupling should be in

proportion to domain

relevance.

Page 37: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The problem of

state.

Page 38: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

If...Configure::write('debug', 0);

is evil,$this->debug = 0;

is the

Page 39: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Page 40: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

of evil.

Page 41: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

class Service {

protected $_timeout = 30;

public function send($method, $data = null, array $options = array()) {

// WTF does this do? $this->_prepare();

$response = $this->_connection->send($request, array( 'timeout' => $this->_timeout )); // ... }}

Page 42: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

OO doesn’t make you

think (about state).

Page 43: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Design patterns.

Page 44: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

ActiveRecord

MVC

Value Object

Data Access Object

Front Controller

Dependency InjectionRegistry

Data Mapper Service Layer

Unit of Work

Page 45: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

FALE

Page 46: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Design patterns

•Each pattern is only useful in a limited context

•Layering many design patterns on top of each other often indicates poor design choices

•Mis-application arises from trying to run before you can walk

Page 47: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Tools do not mean...

...you can build a house.

Page 48: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The third part.

Page 49: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Lithium tries to suck less.

Page 50: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Un-broken solutions.

Page 51: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Aspect-Oriented Design• Separation of concerns

• Domain classes should not know or care about cross-cutting concerns

• Examples:

• Caching

• Logging

• Access Control, etc.

Page 52: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Functional Programming

•Only possible when functions are first-class citizens

•Referential transparency

•Functional purity

Page 53: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Referential transparency is not...

$this date()

$_*

Page 54: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Referential transparency is not...

$this date()

$_*

Page 55: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

These Are NotDesign Patterns.

Page 56: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

•Draws on years of experience building web frameworks

•PHP 5.3+ only

•Doesn’t assume you’re stupid

Less Suck

Page 57: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Ways we try to suck less:

Page 58: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Consistency.

Page 59: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

Page 60: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

public function __construct(array $config = array())

Page 61: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

Page 62: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

2

<?php

class Foo extends \lithium\core\Object {

protected function _init() { $or = $some->highOverHead($operation); $or()->otherwise(HARD_TO_TEST)->code(); }}

?>

Page 63: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

2

<?php

class Foo extends \lithium\core\Object {

protected function _init() { $or = $some->highOverHead($operation); $or()->otherwise(HARD_TO_TEST)->code(); }}

?>

$foo = new Foo(array('init' => false));

Page 64: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

Page 65: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

3new application\bar\Foo();// loads app/bar/Foo.php

Page 66: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

4

Page 67: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

5

protected function _init() { $cache = $this->_classes['cache']; $cache::write(__CLASS__, $this->_someGeneratedValue()); }}

?>

Page 68: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

5

protected function _init() { $cache = $this->_classes['cache']; $cache::write(__CLASS__, $this->_someGeneratedValue()); }}

?>

$foo = new Foo(array('classes' => array( 'cache' => 'application\extensions\Cache')));

Page 69: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

namespace application\bar;

use \lithium\util\String;use \lithium\util\Collection;

class Foo extends \lithium\core\Object {

protected $_classes = array( 'cache' => '\lithium\storage\Cache', 'logger' => '\lithium\analysis\Logger' );

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

protected function _init() { // ... }}

?>

protected function _init() { $cache = $this->_classes['cache']; $cache::write(__CLASS__, $this->_someGeneratedValue()); }}

?>

Page 70: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

$options = array()

Page 71: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Keeps parameter lists short

Makes class APIs more extensible

&

Page 72: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

$config = array()

Page 73: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Same idea.Modifies class / object state.

But...!

Page 74: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Adaptable

Auth

Cache

Catalog

Connections

Logger

Session

Page 75: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\security\Auth;

Auth::config(array( 'customer' => array( 'adapter' => 'Form', 'model' => 'Customer', 'fields' => array('email', 'password') )));

Page 76: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Cache;

Cache::config(array( 'local' => array('adapter' => 'Apc'), 'distributed' => array( 'adapter' => 'Memcached', 'servers' => array('127.0.0.1', 11211), ), 'default' => array('adapter' => 'File')));

Page 77: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\data\Connections;

Connections::config(array( 'old' => array( 'type' => 'database', 'adapter' => 'MySql', 'user' => 'bobby_tables', 'password' => '******', 'database' => 'my_app' ), 'new' => array( 'type' => 'MongoDb', 'database' => 'my_app' )));

Page 78: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Session;

Session::config(array( 'cookie' => array( 'adapter' => 'Cookie', 'expire' => '+2 days' ), 'default' => array('adapter' => 'Php')));

Page 79: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Also fun:

Page 80: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Session;

Session::config(array( 'default' => array( 'adapter' => 'MyCustomAdapter', 'expires' => '+2 days', 'custom' => 'Whatever!' )));

Page 81: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Session;

Session::config(array( 'default' => array( 'adapter' => 'MyCustomAdapter', 'expires' => '+2 days', 'custom' => 'Whatever!' )));

public function __construct(array $config = array())

Page 82: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Multiple environments?

Page 83: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Cache;

Cache::config(array( 'default' => array( 'development' => array( 'adapter' => 'Apc' ), 'production' => array( 'adapter' => 'Memcached', 'servers' => array('127.0.0.1', 11211) ) )));

Page 84: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\storage\Cache;

Cache::config(array( 'default' => array( 'development' => array( 'adapter' => 'Apc' ), 'production' => array( 'adapter' => 'Memcached', 'servers' => array('127.0.0.1', 11211) ) )));

Page 85: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Works identically for all adapters.

Page 86: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

If you remember nothing else about configuration state...

Page 87: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Immutability.

Set it and forget it.

Page 88: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Performance.

Page 89: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Zoom?

•Performance vs. speed of development is a series of trade-offs

• Large-scale apps don’t use stock framework infrastructure, and that’s a good thing

•A generalized framework will never be as fast as hand-tuned code

Page 90: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Zoom!

•Choice is good

•Use native extensions (PECL) whenever possible.

•Don’t like a class? Change it. At runtime.

•Profiled at every step of the way with XHProf and XDebug cachegrinds.

Page 91: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Example: Resource Routing

Page 92: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use app\models\Post;use lithium\action\Response;use lithium\net\http\Router;

Router::connect('/frequent_api_call.json', array(), function($request) { return new Response(array( 'type' => 'application/json', 'body' => Post::recent()->to('json') ));});

Page 93: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

PlatformRackspace Cloud

• 256MB ram• Ubuntu Karmic• Apache 2.2.12• PHP 5.3.1• Xcache• Siege 2.68

2009-11-26

Page 94: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Flexibility.

Page 95: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Lithium is a highly flexible framework.

Page 96: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Most class dependencies are dynamic.(Our implementation of dependency injection)

Page 97: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

class Service extends \lithium\core\Object {

protected $_classes = array( 'request' => 'lithium\net\http\Request', 'response' => 'lithium\net\http\Response', 'socket' => 'lithium\net\socket\Context' );}

$service = new Service(array('classes' => array( 'socket' => 'my\custom\Socket')));

Page 98: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Filter System:

Aspect-Oriented Design

for PHP.

Page 99: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Caching

Logging

Example: Caching & Logging

Post::find()

Page 100: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Caching

Logging

Post::find()

Example: Caching & Logging

Page 101: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\analysis\Logger;

Post::applyFilter('find', function($self, $params, $chain) { // Generate the log message $conditions = $params['options']['conditions']; $message = 'Post query with constraint ' . var_export($conditions, true);

Logger::write('info', $message); return $chain->next($self, $params, $chain);});

Page 102: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

use lithium\analysis\Logger;

Post::applyFilter('find', function($self, $params, $chain) { // Generate the log message $conditions = $params['options']['conditions']; $message = 'Post query with constraint ' . var_export($conditions, true);

Logger::write('info', $message); return $chain->next($self, $params, $chain);});

Post Logger

Page 103: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

What about Observer?

•Dependent on a centralized publish/subscribe system

•Extra layer of abstraction

•Fewer possibilities

Page 104: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

What about Observer?

•Filters are self-contained and attach directly to objects

•Direct and intuitive

Page 105: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Features: Everything is an adapter.

(well, almost)

Page 106: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Databases

•1st-class support for document-oriented databases

•MongoDB & CouchDB: production ready

•Relational databases in beta

•Cassandra/Redis/Riak in the works, too

Page 107: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

<?php

$post = Post::create(array( 'title' => 'ビール2本', 'body' => 'クレジットカードは使えますか?'));$post->save();

$post = Post::find($id);

?>

<h2><?=$post->title; ?></h2><p><?=$post->body; ?></p>

Page 108: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

This works on...

Page 109: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

This works on...

•MongoDB

•CouchDB

•MySQL

•SQLite

Page 110: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

MongoDB + CouchDB:

$post = Post::create(array( 'title' => 'ビール2本', 'body' => 'クレジットカードは使えますか?', 'tags' => array('PHP', 'Japan'), 'author' => array('name' => 'Nate')));

$post->save();

Page 111: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

MongoDB:

$posts = Post::all(array('conditions' => array( 'tags' => array('PHP', 'Japan'), 'author.name' => 'Nate')));

// Translates to...db.posts.find({ tags : { $in : ['PHP', 'Japan'] }, 'author.name' : 'Nate'})

Page 112: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Databases

•Adapter based, plugin aware

•Will ship with MySQL, SQLite & PostgreSQL

•SQL Server support via plugin

•Query API

Page 113: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Query API

•Flexible data container

•Allows each backend data store to only worry about features it implements

•Keeps model API separate from backend data sources

Page 114: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Query API

$ages = User::all(array( 'group' => 'age', 'reduce' => 'function(obj, prev) { prev.count++; }', 'initial' => array('count' => 0)));

Page 115: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Query API

$query = new Query(array( 'type' => 'read', 'model' => 'app\models\Post', 'fields' => array('Post.title', 'Post.body'), 'conditions' => array('Post.id' => new Query(array( 'type' => 'read', 'fields' => array('post_id'), 'model' => 'app\models\Tagging', 'conditions' => array('Tag.name' => array('foo', 'bar', 'baz')), )))));

Page 116: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

The Query API

•Run simple queries via the Model API

•Build your own complex queries with the Query API

•Create your own adapter, or drop in a custom query optimizer

Page 117: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Btw, li3_doctrine

Page 118: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

Plays nice with others

•Easily load & use libraries from other frameworks:

•Zend Framework, Solar, Symfony, PEAR, etc.

•PSR-0 Class-loading standard

Page 119: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

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

/* add the incubator */Libraries::add("Zend_Incubator", array( "prefix" => "Zend_", "includePath" => '/htdocs/libraries/Zend/incubator/library', "transform" => function($class) { return str_replace("_", "/", $class) . ".php"; }));

Page 120: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

namespace app\controllers;

use \Zend_Mail_Storage_Pop3;

class EmailController extends \lithium\action\Controller {

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

}

Page 121: Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition

This has been a presentation by:

Nate Abele (@nateabele)

Joël Perras (@jperras)

http://lithify.me Sucks. But check it out anyway.