assessmentee.com

Home | Start test | Contact
 

Activerecord | Adapter | Decorator | DependencyInjectionContainer | Facade | Factory | Hydration | Inheritance | Iterator | Mapper | MVC | Observer | Prototype | Proxy | Registry | ServiceLocator | Singleton | Specification | Strategy | TableGateway | ZF1_TableGateway | ZF2_TableGateway |




    <?php

/*
 * Dependency injection container
 *
 *
 */

class Shop {

    public $stock;
    public $staff;

    public function stock(stock $stock) {
        $this->stock = $stock;
    }

    public function staff(staff $staff) {
        $this->staff = $staff;
    }
}

class Stock {

    public function getStockCount() {
        return 10;
    }
}

class Staff {
}

class Container {

    public function getStock() {
        return new Stock();
    }
    public function getStaff() {
        return new Staff();
    }
}

$shop = new Shop();
$container = new Container();
$shop->stock($container->getStock());
$shop->staff($container->getStaff());
echo $shop->stock->getStockCount();
?>


    

Outputs:


10



 

© 2018 assessmentee.com