diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index c6362e8..39418ef 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -74,7 +74,7 @@ protected function configure() { /** * Called by Command */ - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute($input, $output) { $this->_gatherPaths(); $this->_formatDefinitions(); $this->_generateModels(); @@ -112,28 +112,19 @@ private function _generateModels() { } foreach ($this->_definitions as $definition) { - $dir = $modelDir . $definition->namespace . '/'; - $baseDir = $modelDir . '_Base/' . $definition->namespace . '/'; - $baseFile = 'Base' . $definition->name . '.php'; + + //Model files + $filePath = $definition->namespace . '/'; + $dir = $modelDir . $filePath; $file = $definition->name . '.php'; - $basePath = $baseDir . $baseFile; $path = $dir . $file; - if (!is_dir($dir)) { - mkdir($dir, 0777, true); - } - - if (!is_dir($baseDir)) { - mkdir($baseDir, 0777, true); - } + //Base model files + $baseFilePath = '_Base/' . $definition->namespace . '/'; + $baseDir = $modelDir . $baseFilePath; + $baseFile = 'Base' . $definition->name . '.php'; + $basePath = $baseDir . $baseFile; - if (file_exists($path)) { - unlink($path); - } - - if (file_exists($basePath)) { - unlink($basePath); - } if (in_array(strtolower($definition->name), $this->_paths)) { //ApiModel @@ -148,8 +139,34 @@ private function _generateModels() { $content = $this->_mustache->render($model, $definition->getArray()); $baseContent = $this->_mustache->render($baseModel, $definition->getArray()); } - file_put_contents($path, $content); - file_put_contents($basePath, $baseContent); + + $currentFile = null; + @$currentFile = file_get_contents(realpath(dirname(__FILE__) . '/../Models') . '/' . $filePath . $file); + + $currentBaseFile = null; + @$currentBaseFile = file_get_contents(realpath(dirname(__FILE__) . '/../Models') . '/' . $baseFilePath . $baseFile); + + if ($content !== $currentFile) { + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + + if (file_exists($path)) { + unlink($path); + } + + file_put_contents($path, $content); + } + + if ($baseContent !== $currentBaseFile) { + if (!is_dir($baseDir)) { + mkdir($baseDir, 0777, true); + } + if (file_exists($basePath)) { + unlink($basePath); + } + file_put_contents($basePath, $baseContent); + } } } diff --git a/src/Models/Coupons/Coupon.php b/src/Models/Coupons/Coupon.php new file mode 100644 index 0000000..f02d2b5 --- /dev/null +++ b/src/Models/Coupons/Coupon.php @@ -0,0 +1,15 @@ + ['CustomerRel', 'one'], + ]; + } + + /** + * Array with types, rules + * @return array + */ + public function getTypes() { + return [ + ['id, code, ','required'], + ['id, exchange_rate, available, used, label','integer'], + ['is_unlimited','boolean'], + ['exchange_value','number'], + ['expires_at, code','string'], + ]; + } + + /** + * Map model data + * @return array + */ + protected function getMapping() { + return array_merge([], parent::getMapping()); + } +} \ No newline at end of file diff --git a/src/Models/_Base/Coupons/BaseCouponRel.php b/src/Models/_Base/Coupons/BaseCouponRel.php new file mode 100644 index 0000000..0edf500 --- /dev/null +++ b/src/Models/_Base/Coupons/BaseCouponRel.php @@ -0,0 +1,39 @@ + ['ProductRel', 'one'], + ]; + } + + /** + * Array with types, rules + * @return array + */ + public function getTypes() { + return [ + ['id, amount, product','required'], + ['id, amount','integer'], + ]; + } + + /** + * Map model data + * @return array + */ + protected function getMapping() { + return array_merge([], parent::getMapping()); + } +} \ No newline at end of file diff --git a/src/Models/_Base/InternalShipments/BaseInternalShipment.php b/src/Models/_Base/InternalShipments/BaseInternalShipment.php new file mode 100644 index 0000000..7a5e88c --- /dev/null +++ b/src/Models/_Base/InternalShipments/BaseInternalShipment.php @@ -0,0 +1,87 @@ + ['WarehouseRel', 'one'], + 'mediator' => ['WarehouseRel', 'one'], + 'target' => ['WarehouseRel', 'one'], + 'customer' => ['CustomerRel', 'one'], + 'items' => ['InternalShipmentItem', 'many'], + ]; + } + + /** + * Array with types, rules + * @return array + */ + public function getTypes() { + return [ + ['id, source, mediator, target, ','required'], + ['id','integer'], + ['started_at, expected_at','string'], + ]; + } + + /** + * Map model data + * @return array + */ + protected function getMapping() { + return array_merge([], parent::getMapping()); + } +} \ No newline at end of file diff --git a/src/Models/_Base/Products/BaseItem.php b/src/Models/_Base/Products/BaseItem.php index e77bcdf..823ec7e 100644 --- a/src/Models/_Base/Products/BaseItem.php +++ b/src/Models/_Base/Products/BaseItem.php @@ -30,6 +30,7 @@ * @property integer $id * @property string $ean * @property string $sku + * @property string $suffix * @property string $created_at * @property string $updated_at * @@ -48,6 +49,7 @@ public function getAttributes() { 'id', 'ean', 'sku', + 'suffix', 'created_at', 'updated_at', ]; @@ -73,7 +75,7 @@ public function getTypes() { return [ ['ean, created_at, updated_at, inventory, prices, options, ','required'], ['id','integer'], - ['ean, sku, created_at, updated_at','string'], + ['ean, sku, suffix, created_at, updated_at','string'], ]; }