1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
<?php
/* --------------------------------------------------------------
OrderItemAttributeRepositoryFactory.inc.php 2015-11-17
Gambio GmbH
http://www.gambio.de
Copyright (c) 2015 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
MainFactory::load_class('OrderItemAttributeRepositoryFactoryInterface');
/**
* Class OrderItemAttributeRepositoryFactory
*
* @category System
* @package Order
* @subpackage Factories
*/
class OrderItemAttributeRepositoryFactory implements OrderItemAttributeRepositoryFactoryInterface
{
/**
* Repository array.
* Default: ['attribute' => null, 'property' => null]
*
* @var array
*/
protected $repositoryArray = array('attribute' => null, 'property' => null);
/**
* Instance of query builder which is passed to the reader, writer and deleter.
*
* @var Ci_Db_query_builder
*/
protected $db;
/**
* OrderItemAttributeRepositoryFactory constructor.
*
* @param CI_DB_query_builder $dbQueryBuilder Query builder.
*/
public function __construct(CI_DB_query_builder $dbQueryBuilder)
{
$this->db = $dbQueryBuilder;
}
/**
* Creates an order item attribute repository by the given class name.
*
* @param string $className Name of the attribute class.
*
* @return OrderItemAttributeRepository Order item attribute repository instance.
*
* @throws InvalidArgumentException On invalid argument.
*/
public function createRepositoryByAttributeClass($className)
{
if(strtolower($className) === 'attribute')
{
$this->_setRepositoryArrayAttributeIfNull();
return $this->repositoryArray['attribute'];
}
elseif(strtolower($className) === 'property')
{
$this->_setRepositoryArrayPropertyIfNull();
return $this->repositoryArray['property'];
}
else
{
throw new \InvalidArgumentException('Passed argument ' . $className . ' is not valid!');
}
}
/**
* Creates an order item attribute repository by the given object type.
*
* @param OrderItemAttributeInterface $itemAttribute Order item attribute.
*
* @return OrderItemAttributeRepository Order item attribute repository instance.
* @throws InvalidArgumentException On invalid argument.
*/
public function createRepositoryByAttributeObject(OrderItemAttributeInterface $itemAttribute)
{
if($itemAttribute instanceof OrderItemAttribute)
{
$this->_setRepositoryArrayAttributeIfNull();
return $this->repositoryArray['attribute'];
}
elseif($itemAttribute instanceof OrderItemProperty)
{
$this->_setRepositoryArrayPropertyIfNull();
return $this->repositoryArray['property'];
}
else
{
throw new \InvalidArgumentException('Passed argument is not valid!');
}
}
/**
* Creates an array which contain all repository of type OrderItemAttributeRepositoryInterface.
*
* @return OrderItemAttributeRepository[]
*/
public function createRepositoryArray()
{
$this->_setRepositoryArrayAttributeIfNull();
$this->_setRepositoryArrayPropertyIfNull();
return $this->repositoryArray;
}
/**
* Creates an OrderItemAttributeRepository object and assigns it to the key 'attribute'
* of the $repositoryArray array, when its current value is null.
*/
protected function _setRepositoryArrayAttributeIfNull()
{
if(null === $this->repositoryArray['attribute'])
{
$factory = MainFactory::create('OrderItemAttributeFactory');
$reader = MainFactory::create('OrderItemAttributeRepositoryReader', $this->db,
$factory);
$writer = MainFactory::create('OrderItemAttributeRepositoryWriter', $this->db);
$deleter = MainFactory::create('OrderItemAttributeRepositoryDeleter', $this->db);
$this->repositoryArray['attribute'] = MainFactory::create('OrderItemAttributeRepository', $reader, $writer,
$deleter);
}
}
/**
* Creates an OrderItemPropertyRepository object and assigns it to the key 'property'
* of the $repositoryArray array, when its current value is null.
*/
protected function _setRepositoryArrayPropertyIfNull()
{
if(null === $this->repositoryArray['property'])
{
$factory = MainFactory::create('OrderItemPropertyFactory');
$reader = MainFactory::create('OrderItemPropertyRepositoryReader', $this->db,
$factory);
$writer = MainFactory::create('OrderItemPropertyRepositoryWriter', $this->db);
$deleter = MainFactory::create('OrderItemPropertyRepositoryDeleter', $this->db);
$this->repositoryArray['property'] = MainFactory::create('OrderItemPropertyRepository', $reader, $writer,
$deleter);
}
}
}