diff --git a/.jeeves.phpunit.yaml b/.jeeves.phpunit.yaml index 061ddab..a61240e 100644 --- a/.jeeves.phpunit.yaml +++ b/.jeeves.phpunit.yaml @@ -41,6 +41,7 @@ Mygento: Banner: api: true readonly: true + cache_tag: samp_ban columns: id: type: int diff --git a/README.md b/README.md index fa08656..b0d4c01 100644 --- a/README.md +++ b/README.md @@ -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``` diff --git a/src/Jeeves/Console/Command/ModelCrud.php b/src/Jeeves/Console/Command/ModelCrud.php index 412ed84..ee4d89d 100644 --- a/src/Jeeves/Console/Command/ModelCrud.php +++ b/src/Jeeves/Console/Command/ModelCrud.php @@ -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); @@ -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'; @@ -491,6 +492,7 @@ private function genModelInterface($generator, $entityName, $fields) $generator->genModelInterface( $fileName, $this->getNamespace(), + $tag, $fields ) ); diff --git a/src/Jeeves/Generators/Crud/Interfaces.php b/src/Jeeves/Generators/Crud/Interfaces.php index 8eafe4b..e161c9c 100644 --- a/src/Jeeves/Generators/Crud/Interfaces.php +++ b/src/Jeeves/Generators/Crud/Interfaces.php @@ -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)); diff --git a/src/Jeeves/Generators/Crud/Model.php b/src/Jeeves/Generators/Crud/Model.php index 36e458e..3a712cb 100644 --- a/src/Jeeves/Generators/Crud/Model.php +++ b/src/Jeeves/Generators/Crud/Model.php @@ -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) diff --git a/test/Expectations/Crud/Api/Data/BannerInterface.php b/test/Expectations/Crud/Api/Data/BannerInterface.php index 9df03b4..d25f8e6 100644 --- a/test/Expectations/Crud/Api/Data/BannerInterface.php +++ b/test/Expectations/Crud/Api/Data/BannerInterface.php @@ -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'; diff --git a/test/Expectations/Crud/Api/Data/CustomerAddressInterface.php b/test/Expectations/Crud/Api/Data/CustomerAddressInterface.php index e7ac92a..58069a1 100644 --- a/test/Expectations/Crud/Api/Data/CustomerAddressInterface.php +++ b/test/Expectations/Crud/Api/Data/CustomerAddressInterface.php @@ -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'; diff --git a/test/Expectations/Crud/Model/Banner.php b/test/Expectations/Crud/Model/Banner.php index 1f8aa70..34904b5 100644 --- a/test/Expectations/Crud/Model/Banner.php +++ b/test/Expectations/Crud/Model/Banner.php @@ -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 diff --git a/test/Expectations/Crud/Model/CustomerAddress.php b/test/Expectations/Crud/Model/CustomerAddress.php index c8c480d..301ab78 100644 --- a/test/Expectations/Crud/Model/CustomerAddress.php +++ b/test/Expectations/Crud/Model/CustomerAddress.php @@ -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