Skip to content

Commit

Permalink
* #79. fix config gen on bit mask
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 26, 2017
1 parent 9de483d commit 974053f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 75 deletions.
80 changes: 9 additions & 71 deletions src/blocks/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use rjapi\types\PhpInterface;
use rjapi\types\RamlInterface;

/**
* Class Config
*
* @package rjapi\blocks
*/
class Config implements ConfigInterface
{
use ContentManager, ConfigTrait;
Expand Down Expand Up @@ -69,8 +74,6 @@ private function setContent()
$this->setQueryParams();
$this->setTrees();
$this->setJwtContent();
// $this->setFsmContent();
// $this->setSpellCheck();
$this->setConfigEntities();
$this->closeRoot();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/blocks/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ 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)
{
if(is_array($propVal))
{
$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);
}
}
}
Expand Down

0 comments on commit 974053f

Please sign in to comment.