From 974053fe021e3bd9503e0d2ab0bf6e79de5e1d12 Mon Sep 17 00:00:00 2001 From: Kushmantsev Arthur Date: Mon, 26 Jun 2017 14:23:04 +0300 Subject: [PATCH] * #79. fix config gen on bit mask --- src/blocks/Config.php | 80 ++++------------------------------- src/blocks/ContentManager.php | 5 ++- src/blocks/Middleware.php | 5 ++- 3 files changed, 15 insertions(+), 75 deletions(-) diff --git a/src/blocks/Config.php b/src/blocks/Config.php index 4560239..bda0efa 100644 --- a/src/blocks/Config.php +++ b/src/blocks/Config.php @@ -14,6 +14,11 @@ use rjapi\types\PhpInterface; use rjapi\types\RamlInterface; +/** + * Class Config + * + * @package rjapi\blocks + */ class Config implements ConfigInterface { use ContentManager, ConfigTrait; @@ -69,8 +74,6 @@ private function setContent() $this->setQueryParams(); $this->setTrees(); $this->setJwtContent(); -// $this->setFsmContent(); -// $this->setSpellCheck(); $this->setConfigEntities(); $this->closeRoot(); } @@ -118,74 +121,6 @@ private function setJwtContent() } } - /** - * Sets Finite State Machine config array - * Ex.: - * 'state_machine' => [ - * 'article' => [ // table - * 'status' => [ // column - * 'enabled' => true, - * 'states' => [ - * 'draft' => [ - * 'initial' => true, - * 'published', - * ], - * 'published' => [ - * 'draft', - * 'postponed', - * ], - * 'postponed' => [ - * 'published', - * 'archived', - * ], - * 'archived' => [], - * ] - * ] - * ] - * ], - */ - private function setFsmContent() - { - $this->openEntity(ConfigInterface::STATE_MACHINE); - foreach($this->generator->types as $objName => $objData) { - if(in_array($objName, $this->generator->customTypes) === false) { // if this is not a custom type generate resources - $excluded = false; - foreach($this->generator->excludedSubtypes as $type) { - if(strpos($objName, $type) !== false) { - $excluded = true; - } - } - // if the type is among excluded - continue - if($excluded === true) { - continue; - } - $this->setFsmOptions($objName); - } - } - $this->closeEntity(); - } - - private function setSpellCheck() - { - $this->openEntity(ConfigInterface::SPELL_CHECK); - foreach($this->generator->types as $objName => $objData) { - if(in_array($objName, $this->generator->customTypes) === false) { // if this is not a custom type generate resources - $excluded = false; - foreach($this->generator->excludedSubtypes as $type) { - if(strpos($objName, $type) !== false) { - $excluded = true; - } - } - // if the type is among excluded - continue - if($excluded === true) { - continue; - } - $this->setSpellOptions($objName); - } - } - $this->closeEntity(); - } - private function setConfigEntities() { foreach($this->entityMethods as $entity => $method) { @@ -251,6 +186,9 @@ private function setFsmOptions(string $objName) } } + /** + * @param string $objName + */ private function setBitMaskOptions(string $objName) { if(empty($this->generator->types[$objName . CustomsInterface::CUSTOM_TYPES_ATTRIBUTES][RamlInterface::RAML_PROPS]) === false) { @@ -260,7 +198,7 @@ private function setBitMaskOptions(string $objName) // found FSM definition $this->openBitMask($objName, $propKey); foreach($propVal[RamlInterface::RAML_FACETS][ConfigInterface::BIT_MASK] as $key => $val) { - $this->setParam($key, (int)$val, 4); + $this->setParam($key, (int)$val, 5); } $this->closeBitMask(); } diff --git a/src/blocks/ContentManager.php b/src/blocks/ContentManager.php index 1d04985..297cacd 100644 --- a/src/blocks/ContentManager.php +++ b/src/blocks/ContentManager.php @@ -143,10 +143,11 @@ protected function createProperty(string $prop, string $modifier, $value = RJApi /** * @param string $comment + * @param int $tabs */ - protected function setComment(string $comment) + protected function setComment(string $comment, int $tabs = 1) { - $this->sourceCode .= PhpInterface::COMMENT + $this->sourceCode .= $this->setTabs($tabs) . PhpInterface::COMMENT . PhpInterface::SPACE . $comment . PHP_EOL; } diff --git a/src/blocks/Middleware.php b/src/blocks/Middleware.php index 0844b60..2604aff 100644 --- a/src/blocks/Middleware.php +++ b/src/blocks/Middleware.php @@ -69,7 +69,7 @@ private function setAdditionalProps() private function setPropsContent() { - $this->sourceCode .= PhpInterface::TAB_PSR4 . PhpInterface::COMMENT . ' Attributes' . PHP_EOL; + $this->setComment(CustomsInterface::CUSTOM_TYPES_ATTRIBUTES); foreach($this->generator->types[$this->generator->objectProps[RamlInterface::RAML_ATTRS]] [RamlInterface::RAML_PROPS] as $propKey => $propVal) { @@ -77,8 +77,9 @@ private function setPropsContent() { $this->createProperty($propKey, PhpInterface::PHP_MODIFIER_PUBLIC); if(empty($propVal[RamlInterface::RAML_FACETS][ConfigInterface::BIT_MASK]) === false) { + $this->setComment(ConfigInterface::BIT_MASK); foreach ($propVal[RamlInterface::RAML_FACETS][ConfigInterface::BIT_MASK] as $flag => $bit) { - $this->createProperty($propKey, PhpInterface::PHP_MODIFIER_PUBLIC, $bit); + $this->createProperty($flag, PhpInterface::PHP_MODIFIER_PUBLIC, $bit); } } }