Пример #1
0
 /**
  * @covers ::get
  */
 public function testGet()
 {
     $class1 = 'Harp\\Harp\\Test\\TestModel\\Country';
     $actual1 = 'Harp\\Harp\\Test\\TestModel\\City';
     $class2 = 'Harp\\Harp\\Test\\TestModel\\User';
     $actual2 = 'Harp\\Harp\\Test\\TestModel\\Profile';
     Container::setActualClass($class1, $actual1);
     Container::setActualClass($class2, $actual2);
     $this->assertSame(Container::get($class1), Container::get($actual1));
     $this->assertSame(Container::get($actual2), Container::get($class2));
 }
Пример #2
0
 /**
  * @return Repo
  */
 public function getRepo()
 {
     return Container::get($this->foreignModelClass);
 }
Пример #3
0
 /**
  * Enables Repo "inheritance" allowing multiple repos to share one storage table
  * You will need to call setRootRepo on all the child repos.
  *
  * @param  boolean      $inherited
  * @return Config $this
  */
 public function setInherited($inherited)
 {
     $this->inherited = (bool) $inherited;
     if ($inherited) {
         if (!$this->reflectionModel->isRoot()) {
             $rootRepo = Container::get($this->reflectionModel->getRoot()->getName());
             $this->rootConfig = $rootRepo->getConfig();
         }
         $this->table = $this->rootConfig->getTable();
     }
     return $this;
 }
Пример #4
0
 /**
  * @return Repo
  */
 public static function getRepo()
 {
     return Container::get(get_called_class());
 }
Пример #5
0
 /**
  * Add a ProductItem for the given product / quantity.
  * If product item exists, increase the quantity
  *
  * @param  Product $product
  * @param  integer $quantity
  * @return static
  */
 public function addProduct(Product $product, $quantity = 1)
 {
     foreach ($this->getProductItems() as $item) {
         if ($item->getProduct() === $product) {
             $item->quantity += $quantity;
             return $this;
         }
     }
     $item = Container::get('CL\\Purchases\\ProductItem')->newModel(['quantity' => $quantity]);
     $item->setProduct($product);
     $this->addPurchaseItem($product->getStore(), $item);
     return $this;
 }