Example #1
0
 /**
  * Rebuild a barely new group to a readable array.
  *
  * @param \Docoflow\Entity\Step &$steps
  *
  * @return \Docoflow\Entity\Group
  */
 public function rebuild(Step &$steps)
 {
     $groups = new static();
     foreach ($this as $group) {
         $group = fluent($group);
         if (!($groupId = $group->{'$id'})) {
             throw new Exception("Group doesn't have an id.");
         }
         if (!($assignedStep = $group->{'$step'})) {
             throw new Exception("Group doesn't have any assigned step id.");
         }
         if ($steps->has($assignedStep)) {
             if ($steps->get($assignedStep)->groups->has($groupId)) {
                 throw new Exception("Group id [{$groupId}] has been assigned before and it can't be overriden.");
             }
             $group->verificator = new Verificator();
             $groups->offsetSet($groupId, $group);
             $steps->pushGroup($groupId, $group);
             $steps->get($assignedStep)->groups->offsetSet($groupId, $group);
         } else {
             throw new Exception("Assigned step [{$assignedStep}] doesn't exist.");
         }
     }
     return $groups;
 }
Example #2
0
 /**
  * Rebuild a barely new step to a readable array.
  *
  * @return \Docoflow\Entity\Step
  */
 public function rebuild()
 {
     $steps = new static();
     foreach ($this as $step) {
         $step = fluent($step);
         if (!($stepId = $step->{'$id'})) {
             throw new Exception("Step doesn't have an id.");
         }
         $steps[$stepId] = $step;
         $steps[$stepId]->groups = new Group();
     }
     return $steps;
 }
 /**
  * Hack, handling internal error on user input whenever they want to access any controller in parent module.
  *
  * @param Exception $error
  */
 public function internalHandle(Exception $error)
 {
     $data = ['status' => 500, 'message' => 'Internal Server Error', 'value' => ['error_code' => $error->getCode(), 'error_message' => strip_tags($error->getMessage())]];
     $statusCode = 500;
     if ($error instanceof CHttpException) {
         $data['status'] = 400;
         $data['message'] = 'Bad Request';
         $statusCode = 400;
     }
     if (YII_DEBUG) {
         $data['value']['stack_trace'] = $error->getTrace();
     }
     return response('json', $statusCode, fluent($data), [], true);
 }
Example #4
0
 /**
  * Rebuild a barely new group to a readable array.
  *
  * @param \Docoflow\Entity\Step &$steps
  */
 public function rebuild(Step &$steps)
 {
     foreach ($this as $verificator) {
         $verificator = fluent($verificator);
         if (!($assignedGroup = $verificator->{'$group'})) {
             throw new Exception("Verificator hasn't assigned to any group.");
         }
         if ($steps->hasGroup($assignedGroup)) {
             $verificatorStep = $steps->getGroup($assignedGroup)->{'$step'};
             $steps->get($verificatorStep)->groups->get($assignedGroup)->verificator->push($verificator);
         } else {
             throw new Exception("Assigned group [{$assignedGroup}] doent't exist.");
         }
     }
 }
Example #5
0
 public function testKeyOf()
 {
     $items = ['a' => 'A', 'b' => 'B', 'c' => 'C'];
     $expect = true;
     $actual = fluent('b')->keyOf($items)->call();
     $this->assertEquals($expect, $actual);
 }
 /**
  * Handling 404 error.
  *
  * @param string $action
  */
 public function missingAction($action)
 {
     return response('json', 404, fluent(['status' => 404, 'message' => 'Not Found', 'value' => "Request to [" . Yii::app()->request->getPathInfo() . "] has no resource."]), $this->headers)->send();
 }
Example #7
0
 /**
  * Convert this implementation to a standard PHP array.
  *
  * @param boolean $returnModel Set to true if you want to return an object, instead of array.
  *
  * @return array|\Docolight\Support\Collection
  */
 public function toArray($returnModel = false)
 {
     if ($this->jsonAble) {
         return $this->jsonAble;
     }
     if (!$this->workflow) {
         $this->jsonAble = fluent();
         return;
     }
     $this->jsonAble = fluent($this->workflow->attributes);
     $this->jsonAble->steps = collect();
     foreach ($this->steps as $step) {
         $stepFluent = fluent(array_except($step->attributes, ['workflow_id']));
         $stepFluent->groups = collect();
         foreach ($step->getRelated('groups') as $group) {
             $groupFluent = fluent(array_except($group->attributes, ['workflow_step_id']));
             $groupFluent->verificators = collect();
             foreach ($group->getRelated('verificators') as $verificator) {
                 $fluentVerificator = fluent(array_except($verificator->attributes, ['workflow_groups_id']));
                 if ($verificator->hasMutator('user')) {
                     container()->instance('workflow.verificator', $verificator);
                     unset($fluentVerificator['user_id']);
                     $fluentVerificator->user = $verificator->callMutator('user', [container('workflow.verificator')]);
                 }
                 $groupFluent->verificators->push($fluentVerificator);
             }
             $stepFluent->groups->push($groupFluent);
         }
         $this->jsonAble->steps->push($stepFluent);
     }
     return $returnModel ? $this->jsonAble : $this->jsonAble->toArray();
 }