Skip to content

Commit

Permalink
close #14
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul committed Jun 25, 2020
1 parent 75e5d20 commit 388264b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions .jeeves.phpunit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Mygento:
Banner:
api: true
readonly: true
cache_tag: samp_ban
columns:
id:
type: int
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ go to ```https://github.com/mygento/jeeves/releases/latest``` download phar and
```
sudo mv jeeves.phar /usr/local/bin/jeeves
```


sample

look in ```.jeeves.phpunit.yaml```
6 changes: 4 additions & 2 deletions src/Jeeves/Console/Command/ModelCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ private function genModule($vendor, $module, $entity, $config)

$routepath = $config['route']['admin'];
$fields = $config['columns'];
$entityTag = $config['cache_tag'] ?? strtolower(substr($module, 0, 3) . '_' . substr($entity, 0, 1));

// interface
$interGenerator = new \Mygento\Jeeves\Generators\Crud\Interfaces();
$this->genModelInterface($interGenerator, $entity, $fields);
$this->genModelInterface($interGenerator, $entity, $entityTag, $fields);
$this->genModelRepositoryInterface($interGenerator, $entity);
$this->genModelSearchInterface($interGenerator, $entity);

Expand Down Expand Up @@ -481,7 +482,7 @@ private function genRepo($generator, $entityName)
);
}

private function genModelInterface($generator, $entityName, $fields)
private function genModelInterface($generator, $entityName, $tag, $fields)
{
$filePath = $this->path . '/Api/Data/';
$fileName = ucfirst($entityName) . 'Interface';
Expand All @@ -491,6 +492,7 @@ private function genModelInterface($generator, $entityName, $fields)
$generator->genModelInterface(
$fileName,
$this->getNamespace(),
$tag,
$fields
)
);
Expand Down
5 changes: 4 additions & 1 deletion src/Jeeves/Generators/Crud/Interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

class Interfaces extends Common
{
public function genModelInterface($className, $rootNamespace, $fields = self::DEFAULT_FIELDS)
public function genModelInterface($className, $rootNamespace, $cacheTag, $fields = self::DEFAULT_FIELDS)
{
$namespace = new PhpNamespace($rootNamespace . '\Api\Data');
$interface = $namespace->addInterface($className);
$interface->setExtends('\Magento\Framework\DataObject\IdentityInterface');

$interface->addConstant('CACHE_TAG', $cacheTag);

foreach ($fields as $name => $value) {
$interface->addConstant(strtoupper($name), strtolower($name));
Expand Down
5 changes: 5 additions & 0 deletions src/Jeeves/Generators/Crud/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function genModel($className, $entInterface, $resource, $rootNamespace, $
->setVisibility('protected')
->setBody('$this->_init(' . $resource . '::class);');

$class->addMethod('getIdentities')
->addComment('@return string[]')
->setVisibility('public')
->setBody('return [self::CACHE_TAG . \'_\' . $this->getId()];');

foreach ($fields as $name => $value) {
$method = $this->snakeCaseToUpperCamelCase($name);
$class->addMethod('get' . $method)
Expand Down
3 changes: 2 additions & 1 deletion test/Expectations/Crud/Api/Data/BannerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Mygento\SampleModule\Api\Data;

interface BannerInterface
interface BannerInterface extends \Magento\Framework\DataObject\IdentityInterface
{
const CACHE_TAG = 'samp_ban';
const ID = 'id';
const NAME = 'name';
const SUBNAME = 'subname';
Expand Down
3 changes: 2 additions & 1 deletion test/Expectations/Crud/Api/Data/CustomerAddressInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Mygento\SampleModule\Api\Data;

interface CustomerAddressInterface
interface CustomerAddressInterface extends \Magento\Framework\DataObject\IdentityInterface
{
const CACHE_TAG = 'sam_c';
const ID = 'id';
const CITY = 'city';
const CUSTOMER_GROUP = 'customer_group';
Expand Down
8 changes: 8 additions & 0 deletions test/Expectations/Crud/Model/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

class Banner extends AbstractModel implements \Mygento\SampleModule\Api\Data\BannerInterface
{
/**
* @return string[]
*/
public function getIdentities()
{
return [self::CACHE_TAG . '_' . $this->getId()];
}

/**
* Get id
* @return int|null
Expand Down
8 changes: 8 additions & 0 deletions test/Expectations/Crud/Model/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

class CustomerAddress extends AbstractModel implements \Mygento\SampleModule\Api\Data\CustomerAddressInterface
{
/**
* @return string[]
*/
public function getIdentities()
{
return [self::CACHE_TAG . '_' . $this->getId()];
}

/**
* Get id
* @return int|null
Expand Down

0 comments on commit 388264b

Please sign in to comment.