Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System;
- /**
- * ILLI System Abstract Prototype Fluent Interface Handler
- *
- * returns the instance of object when the object::method() returns NULL
- *
- * dummy-class
- *
- * <code>
- * <?PHP
- * use \ILLI\System\Collection\TFluent AS TFluent;
- *
- * class test
- * {
- * private $__foo = 0;
- * public function add2()
- * {
- * $this->__foo += 2;
- * }
- *
- * public function add10()
- * {
- * $this->__foo += 10;
- * }
- * }
- * ?>
- * </code>
- *
- * as instance:
- * - store the wrapped object permanent
- *
- * <code>
- * <?PHP
- * $k = new TFluent(new test);
- *
- * $k->add2()
- * ->add2()
- * ->add2()
- * ->add10();
- *
- * var_dump($k); // __foo = 16
- * ?>
- * </code>
- *
- * static is implemented bt not useful:
- * - stores the wrapped object temporary
- * - this will create a new instance of ProtoFluent
- * on every ::fluent(obj)-call
- *
- * <code>
- * <?PHP
- * $l = new test;
- *
- * TFluent::fluent($l)
- * ->add2()
- * ->add2()
- * ->add2()
- * ->add2()
- * ->add2()
- * ->add10();
- *
- * var_dump($l); // __foo = 20
- * ?>
- * </code>
- *
- * nested has no effect:
- * <code>
- * <?PHP
- * $z = TFluent::fluent(new test)->add2()->add2()->add2()->add2()->add2();
- * var_dump($z);
- * $y = TFluent::fluent($z)->add10();
- * var_dump($y);
- * var_dump($z === $y);
- * ?>
- * </code>
- *
- * output:
- * <code>
- * object(ILLI\System\Collection\TFluent)#10 (1) {
- * ["__object":"ILLI\System\ProtoFluent":private]=>
- * object(localhost\illiFW\dev\test)#9 (1) {
- * ["__foo":"localhost\illiFW\dev\test":private]=>
- * int(10)
- * }
- * }
- * object(ILLI\System\Collection\TFluent)#10 (1) {
- * ["__object":"ILLI\System\ProtoFluent":private]=>
- * object(localhost\illiFW\dev\test)#9 (1) {
- * ["__foo":"localhost\illiFW\dev\test":private]=>
- * int(20)
- * }
- * }
- * bool(true)
- * </code>
- *
- * To resign this Proto, write your classes fluent:
- * <code>
- * <?PHP
- * class Fluent
- * {
- * private $__order = array();
- * public function hello()
- * {
- * $this->__order[] = 'hello';
- * return $this;
- * }
- *
- * public function world()
- * {
- * $this->__order[] = 'world';
- * return $this;
- * }
- *
- * public function __toString()
- * {
- * return implode(' ', $this->__order);
- * }
- * }
- *
- * $fluent = new Fluent;
- * print $fluent->hello()->world();
- * ?>
- * </code>
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @namespace ILLI\System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- * @abstract
- */
- ABSTRACT CLASS ProtoFluent EXTENDS Proto
- {
- private $__object = NULL;
- public function __construct($object)
- {
- if($object instanceOf ProtoFluent)
- return $this->__object = $object();
- $this->__object = $object;
- }
- private function __invoke()
- {
- return $this->__object;
- }
- public static function fluent($object)
- {
- if($object instanceOf ProtoFluent)
- return $object;
- $class = get_called_class();
- return new $class($object);
- }
- public function __call($method, $args)
- {
- return (NULL === ($result = call_user_func_array([$this->__object, $method], $args)))
- ? $this : $result;
- }
- }
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_System_Collection
- * @package ILLI
- * @subpackage SystemCollection
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System\Collection;
- USE ILLI\System as System;
- /**
- * ILLI System Collection Datatype Fluent Interface Handler
- *
- * @category ILLI_System_Collection
- * @package ILLI
- * @subpackage SystemCollection
- * @namespace ILLI\System\Collection
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- * @abstract
- */
- CLASS TFluent EXTENDS System\ProtoFluent
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement