Exemplo n.º 1
0
 /**
  * Add a child to the object.
  *
  * @param  mixed $c
  * @throws Exception
  * @return mixed
  */
 public function addChild($c)
 {
     if ($c instanceof Child) {
         $this->childNodes[] = $c;
     } else {
         if (is_array($c)) {
             $this->childNodes[] = Child::factory($c);
         } else {
             throw new Exception('The argument passed is not valid.');
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Add a child to the object.
  *
  * @param  mixed $c
  * @throws \InvalidArgumentException
  * @return mixed
  */
 public function addChild($c)
 {
     if ($c instanceof Child) {
         $this->childNodes[] = $c;
     } else {
         if (is_array($c)) {
             $this->childNodes[] = Child::factory($c);
         } else {
             throw new \InvalidArgumentException('The argument passed must be an instance of Pop\\Dom\\Child or a child configuration array.');
         }
     }
     return $this;
 }
    {
        return new Base();
    }
}
var_dump(Base::factory());
//
// parent
//
class Child extends Base
{
    public static function factory() : parent
    {
        return new Child();
    }
}
var_dump(Child::factory());
//
// interface name, array, scalar types
//
interface Product
{
    public function name() : string;
    public function ammount() : int;
    public function isAvailable() : bool;
    public function warehouses() : array;
}
class Foo implements Product
{
    public function name() : string
    {
        return 'FooProduct';