Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/Models/Coupons/Coupon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Afosto\ApiClient\Models\Coupons;

use Afosto\ApiClient\Models\_Base\Coupons\BaseCoupon;

/**
* Use this class for custom methods that extend the default functionality for
* the Coupon
*
* This class can interact with api, through methods like find and save.
*/
class Coupon extends BaseCoupon {

}
16 changes: 16 additions & 0 deletions src/Models/Coupons/CouponRel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Afosto\ApiClient\Models\Coupons;

use Afosto\ApiClient\Models\_Base\Coupons\BaseCouponRel;

/**
* Use this class for custom methods that extend the default functionality for
* the CouponRel
*
* This class acts as a relation handler and makes it possible to traverse
* between objects
*/
class CouponRel extends BaseCouponRel {

}
7 changes: 3 additions & 4 deletions src/Models/Images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use Afosto\ApiClient\Models\_Base\Images\BaseImage;

/**
* Use this class for custom methods that extend the default functionality for
* Use this class for custom methods that extend the default functionality for
* the Image
*
* This object cannot be called directly from the api and has therefore no api
* operations. It is only used to format and maintain the data.
*
* This class can interact with api, through methods like find and save.
*/
class Image extends BaseImage {

Expand Down
16 changes: 16 additions & 0 deletions src/Models/InternalShipmentItems/InternalShipmentItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Afosto\ApiClient\Models\InternalShipmentItems;

use Afosto\ApiClient\Models\_Base\InternalShipmentItems\BaseInternalShipmentItem;

/**
* Use this class for custom methods that extend the default functionality for
* the InternalShipmentItem
*
* This object cannot be called directly from the api and has therefore no api
* operations. It is only used to format and maintain the data.
*/
class InternalShipmentItem extends BaseInternalShipmentItem {

}
16 changes: 16 additions & 0 deletions src/Models/InternalShipments/InternalShipment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Afosto\ApiClient\Models\InternalShipments;

use Afosto\ApiClient\Models\_Base\InternalShipments\BaseInternalShipment;

/**
* Use this class for custom methods that extend the default functionality for
* the InternalShipment
*
* This object cannot be called directly from the api and has therefore no api
* operations. It is only used to format and maintain the data.
*/
class InternalShipment extends BaseInternalShipment {

}
7 changes: 3 additions & 4 deletions src/Models/MetaGroups/MetaGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use Afosto\ApiClient\Models\_Base\MetaGroups\BaseMetaGroup;

/**
* Use this class for custom methods that extend the default functionality for
* Use this class for custom methods that extend the default functionality for
* the MetaGroup
*
* This object cannot be called directly from the api and has therefore no api
* operations. It is only used to format and maintain the data.
*
* This class can interact with api, through methods like find and save.
*/
class MetaGroup extends BaseMetaGroup {

Expand Down
5 changes: 2 additions & 3 deletions src/Models/PriceGroups/PriceGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
* Use this class for custom methods that extend the default functionality for
* the PriceGroup
*
* This object cannot be called directly from the api and has therefore no api
* operations. It is only used to format and maintain the data.
* This class can interact with api, through methods like find and save.
*/
class PriceGroup extends BasePriceGroup {

}
96 changes: 96 additions & 0 deletions src/Models/_Base/Coupons/BaseCoupon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Afosto\ApiClient\Models\_Base\Coupons;

use Afosto\ApiClient\Components\Models\Model;
use Afosto\ApiClient\Components\ModelTrait;

/**
* NOTE: Do not overwrite this model, as it is the base class and auto-generated
* by the generator in the dev folder, based on the SwaggerJSON for the Afosto
* API V2 (https://api.afosto.com/v2).
*
* @category Class
* @package Afosto\ApiClient
* @author https://afosto.com
*
* Copyright 2016 Afosto SaaS BV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @property integer $id
* @property boolean $is_unlimited
* @property integer $exchange_rate
* @property number $exchange_value
* @property integer $available
* @property integer $used
* @property string $expires_at
* @property string $code
* @property integer $label
*
* @property \Afosto\ApiClient\Models\Customers\Customer $customer
**/
class BaseCoupon extends Model {

use ModelTrait;

/**
* Array of attributes where the key is the local name, and the value is the original name
* @return array
*/
public function getAttributes() {
return [
'id',
'is_unlimited',
'exchange_rate',
'exchange_value',
'available',
'used',
'expires_at',
'code',
'label',
];
}

/**
* Array with relations
* @return array
*/
public function getRelations() {
return [
'customer' => ['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());
}
}
39 changes: 39 additions & 0 deletions src/Models/_Base/Coupons/BaseCouponRel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Afosto\ApiClient\Models\_Base\Coupons;

use Afosto\ApiClient\Components\Models\Link;
use Afosto\ApiClient\Models\Coupons\Coupon;

/**
* NOTE: Do not overwrite this model, as it is the base class and auto-generated
* by the generator in the dev folder, based on the SwaggerJSON for the Afosto
* API V2 (https://api.afosto.com/v2).
*
* @category Class
* @package Afosto\ApiClient
* @author https://afosto.com
*
* Copyright 2016 Afosto SaaS BV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class BaseCouponRel extends Link {

/**
* @return Coupon
*/
public function getModel() {
return new Coupon();
}
}
Loading