| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace pastuhov\ymlcatalog; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use pastuhov\ymlcatalog\models\BaseModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use pastuhov\ymlcatalog\models\Category; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use pastuhov\ymlcatalog\models\Currency; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use pastuhov\ymlcatalog\models\LocalDeliveryCost; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use pastuhov\ymlcatalog\models\Shop; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use pastuhov\ymlcatalog\models\SimpleOffer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use pastuhov\ymlcatalog\models\DeliveryOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Yii; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use pastuhov\FileStream\BaseFileStream; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use yii\base\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use yii\data\ActiveDataProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use yii\db\ActiveQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Yml генератор каталога. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package pastuhov\ymlcatalog | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class YmlCatalog | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var BaseFileStream | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected $handle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $shopClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     protected $currencyClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected $categoryClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @var null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     protected $localDeliveryCostClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     protected $offerClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     protected $date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @var null|callable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     protected $onValidationError; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @var null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     protected $customOfferClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     protected $deliveryOptionClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param BaseFileStream $handle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param string $shopClass class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 9 |  |      * @param string $currencyClass class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param string $categoryClass class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $localDeliveryCostClass class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 2 |  |      * @param array $offerClasses | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param null|string $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param null|callable $onValidationError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param null|string $customOfferClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         BaseFileStream $handle, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $shopClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 9 |  |         $currencyClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 9 |  |         $categoryClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 9 |  |         $localDeliveryCostClass = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 9 |  |         Array $offerClasses, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 9 |  |         $date = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 9 |  |         $onValidationError = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 9 |  |         $customOfferClass = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 9 |  |         $deliveryOptionClass = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 9 |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 9 |  |         $this->handle = $handle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->shopClass = $shopClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->currencyClass = $currencyClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->categoryClass = $categoryClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->localDeliveryCostClass = $localDeliveryCostClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 9 |  |         $this->offerClasses = $offerClasses; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->date = $date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 9 |  |         $this->onValidationError = $onValidationError; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $this->customOfferClass = $customOfferClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 9 |  |         $this->deliveryOptionClass = $deliveryOptionClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 9 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 6 |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 9 |  |     public function generate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 9 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 9 |  |         $date = $this->getDate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 9 |  |         $this->write( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 9 |  |             '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 9 |  |             '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . PHP_EOL . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 9 |  |             '<yml_catalog date="' . $date . '">' . PHP_EOL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 9 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 9 |  |         $this->writeTag('shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 9 |  |         $this->writeModel(new Shop(), new $this->shopClass()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 4 |  |         $this->writeTag('currencies'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 6 |  |         $this->writeEachModel($this->currencyClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 8 |  |         $this->writeTag('/currencies'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->writeTag('categories'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 6 |  |         $this->writeEachModel($this->categoryClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 6 |  |         $this->writeTag('/categories'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         if($this->deliveryOptionClass) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             $this->writeTag('delivery-options'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             $this->writeModel(new DeliveryOption(), \Yii::createObject($this->deliveryOptionClass)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             $this->writeTag('/delivery-options'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 9 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         if($this->localDeliveryCostClass) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 9 |  |             $this->writeModel(new LocalDeliveryCost(), \Yii::createObject($this->localDeliveryCostClass)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 9 |  |         $this->writeTag('offers'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 3 |  |         foreach ($this->offerClasses as $offerClass) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 2 |  |             $this->writeEachModel($offerClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 9 |  |         $this->writeTag('/offers'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->writeTag('/shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $this->write('</yml_catalog>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 9 |  |      * @return null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 6 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 9 |  |     protected function getDate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 9 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $date = $this->date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         if ($date === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             $date = Yii::$app->formatter->asDatetime(new \DateTime(), 'php:Y-m-d H:i'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 9 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 9 |  |         return $date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * @param string $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * @throws \Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     protected function write($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 9 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $this->handle->write($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 9 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 9 |  |      * @param string $string tag name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 | 9 |  |     protected function writeTag($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 6 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $this->write('<' . $string . '>' . PHP_EOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 6 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 4 |  |      * @param BaseModel $model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 9 |  |      * @param $valuesModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 6 |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 4 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     protected function writeModel(BaseModel $model, $valuesModel) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 9 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 9 |  |         if (method_exists($valuesModel, 'getParams')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 9 |  |             $model->setParams($valuesModel->getParams()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 6 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 | 3 |  |         if (method_exists($valuesModel, 'getPictures')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             $model->setPictures($valuesModel->getPictures()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 6 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 | 9 |  |         if(method_exists($valuesModel, 'getDeliveryOptions')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             $model->setDeliveryOptions($valuesModel->getDeliveryOptions()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 | 9 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 | 9 |  |         if($model->loadModel($valuesModel, $this->onValidationError)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             $string = $model->getYml(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             $this->write($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 9 |  |      * @param string|array $modelClass class name or yii configuration array. You can also set params: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 | 9 |  |      *      `findParams`:   array of additional find params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      *      `query`:        ActiveQuery object to generate yml use already created object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 | 9 |  |      *      `dataProvider`: ActiveDataProvider or true to generate yml with pagination; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     protected function writeEachModel($modelClass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 9 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 | 9 |  |          * @var mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 9 |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 | 9 |  |         $findParams = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 | 6 |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 | 9 |  |          * @var ActiveQuery | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         $query = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |          * @var ActiveDataProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 | 9 |  |         $dataProvider = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 9 |  |         if (is_array($modelClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |             foreach (['findParams', 'query', 'dataProvider'] as $name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 | 9 |  |                 if (array_key_exists($name, $modelClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 9 |  |                     $$name = $modelClass[$name]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 6 |  |                     unset($modelClass[$name]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 9 |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 | 9 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 3 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 | 3 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 | 6 |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 | 6 |  |          * @var BaseFindYmlInterface $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 | 4 |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $class = \Yii::createObject($modelClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 | 9 |  |          * @var ReaderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         $reader = ReaderFactory::build( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |             $class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             $dataProvider, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             $query, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |             $findParams | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         $newModel = $this->getNewModel($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         foreach ($reader as $models) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             foreach ($models as $model) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |                 $this->writeModel($newModel, $model); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |             $this->gc(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |      * @param $modelClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |      * @return Category|Currency|SimpleOffer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |      * @throws Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 257 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 258 |  |  |     protected function getNewModel($modelClass) | 
            
                                                                        
                            
            
                                    
            
            
                | 259 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 260 |  |  |         $obj = is_object($modelClass) ? $modelClass : \Yii::createObject($modelClass); | 
            
                                                                        
                            
            
                                    
            
            
                | 261 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 262 |  |  |         if ($obj instanceof CurrencyInterface) { | 
            
                                                                        
                            
            
                                    
            
            
                | 263 |  |  |             $model = new Currency(); | 
            
                                                                        
                            
            
                                    
            
            
                | 264 |  |  |         } elseif ($obj instanceof CategoryInterface) { | 
            
                                                                        
                            
            
                                    
            
            
                | 265 |  |  |             $model = new Category(); | 
            
                                                                        
                            
            
                                    
            
            
                | 266 |  |  |         } elseif ($obj instanceof CustomOfferInterface && $this->customOfferClass !== null && class_exists($this->customOfferClass)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 267 |  |  |             $model = \Yii::createObject($this->customOfferClass); | 
            
                                                                        
                            
            
                                    
            
            
                | 268 |  |  |         } elseif ($obj instanceof SimpleOfferInterface) { | 
            
                                                                        
                            
            
                                    
            
            
                | 269 |  |  |             $model = new SimpleOffer(); | 
            
                                                                        
                            
            
                                    
            
            
                | 270 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 271 |  |  |             throw new Exception('Model ' . get_class($obj) . ' has unknown interface'); | 
            
                                                                        
                            
            
                                    
            
            
                | 272 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 274 |  |  |         return $model; | 
            
                                                                        
                            
            
                                    
            
            
                | 275 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |      * Performs PHP memory garbage collection. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |     protected function gc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         if (!gc_enabled()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             gc_enable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         gc_collect_cycles(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 287 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 288 |  |  |  | 
            
                        
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.