LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • Docoflow\Docoflow
  • Docoflow\Entity\Group
  • Docoflow\Entity\Step
  • Docoflow\Entity\Verificator
  • Docoflow\Facades\Action
  • Docoflow\Facades\Activity
  • Docoflow\Facades\Flo
  • Docoflow\Facades\StateActivity
  • Docoflow\Flo
  • Docoflow\Models\Workflow
  • Docoflow\Models\WorkflowAction
  • Docoflow\Models\WorkflowActivity
  • Docoflow\Models\WorkflowGroups
  • Docoflow\Models\WorkflowNotification
  • Docoflow\Models\WorkflowState
  • Docoflow\Models\WorkflowStateActivity
  • Docoflow\Models\WorkflowStep
  • Docoflow\Models\WorkflowVerificator
  • Docolight
  • Docolight\Agno\AgnoModule
  • Docolight\Container\Container
  • Docolight\Http\Headers
  • Docolight\Http\JsonResponse
  • Docolight\Http\MimeResponse
  • Docolight\Http\Response
  • Docolight\Http\ResponseFactory
  • Docolight\Rest\Handler\RestfulErrorHandler
  • Docolight\Rest\Http\RestFulController
  • Docolight\Support\ActiveRecordWrapper
  • Docolight\Support\Arr
  • Docolight\Support\Carbonate
  • Docolight\Support\ClassLoader
  • Docolight\Support\Collection
  • Docolight\Support\CollectionDataProvider
  • Docolight\Support\Debug\Dumper
  • Docolight\Support\Debug\HtmlDumper
  • Docolight\Support\Facade
  • Docolight\Support\Factory
  • Docolight\Support\Fluent
  • Docolight\Support\Html
  • Docolight\Support\IterablePager
  • Docolight\Support\Repository
  • Docolight\Support\Set
  • Docolight\Support\Str
  • Docotory\Factory

Interfaces

  • Docoflow\Contracts\DocoflowContract
  • Docoflow\Contracts\ValidationStatus
  • Docolight\Http\Contracts\Arrayable

Traits

  • Docoflow\Traits\BulkValidator
  • Docoflow\Traits\Entity
  • Docoflow\Traits\HasMutator
  • Docoflow\Traits\Validable
  • Docolight\Agno\Traits\HasAssetsUrl
  • Docolight\Agno\Traits\HasAutoload
  • Docolight\Support\Traits\Macroable
  • Docotory\Traits\HasFactories

Exceptions

  • Docolight\Container\BindingResolutionException
  • Docotory\ResolvingTypeException

Functions

  • array_add
  • array_build
  • array_collapse
  • array_divide
  • array_dot
  • array_except
  • array_first
  • array_flatten
  • array_forget
  • array_get
  • array_has
  • array_last
  • array_only
  • array_pluck
  • array_pull
  • array_replace_value
  • array_set
  • array_sort
  • array_sort_recursive
  • array_where
  • cache
  • camel_case
  • class_basename
  • class_uses_recursive
  • collect
  • container
  • data_get
  • dd
  • def
  • dump
  • e
  • ends_with
  • fluent
  • get
  • head
  • input
  • last
  • object_get
  • preg_replace_sub
  • request
  • response
  • session
  • snake_case
  • starts_with
  • str_contains
  • str_finish
  • str_is
  • str_limit
  • str_random
  • str_replace_array
  • str_slug
  • studly_case
  • title_case
  • trait_uses_recursive
  • transaction
  • trimtolower
  • value
  • with
  1 <?php
  2 
  3 namespace Docoflow\Traits;
  4 
  5 use Carbon\Carbon;
  6 
  7 /**
  8  * Any class use this trait is can be validated. Means, you can determine if the verification is not expired.
  9  * You can also change the status, check the status, etc.
 10  *
 11  * @author Krisan Alfa Timur <krisanalfa@docotel.co.id>
 12  */
 13 trait Validable
 14 {
 15     /**
 16      * Date validity.
 17      *
 18      * @var \Carbon\Carbon
 19      */
 20     protected $validUntil;
 21 
 22     /**
 23      * Get workflow date validity.
 24      *
 25      * @return null|\Carbon\Carbon
 26      */
 27     public function validUntil()
 28     {
 29         if ($validUntil = $this->getAttribute('expired_at')) {
 30             if ($this->validUntil) {
 31                 return $this->validUntil;
 32             }
 33 
 34             $this->validUntil = new Carbon($validUntil);
 35 
 36             return $this->validUntil;
 37         }
 38     }
 39 
 40     /**
 41      * Determine if workflow stil valid to be validated.
 42      *
 43      * @return bool
 44      */
 45     public function valid()
 46     {
 47         if ($validUntil = $this->validUntil()) {
 48             return !$validUntil->isPast();
 49         }
 50 
 51         return true;
 52     }
 53 
 54     /**
 55      * Get current status
 56      *
 57      * @return int
 58      */
 59     public function status()
 60     {
 61         if (is_null($status = (int) $this->getAttribute('status'))) {
 62             $status = 0;
 63         }
 64 
 65         switch ($status) {
 66             case 0:
 67                 return static::UNPROCESSED;
 68                 break;
 69             case 1:
 70                 return static::APPROVED;
 71                 break;
 72             case 2:
 73                 return static::PARTIAL;
 74                 break;
 75             case 3:
 76                 return static::REJECTED;
 77                 break;
 78             default:
 79                 return static::INVALID;
 80                 break;
 81         }
 82     }
 83 
 84     /**
 85      * Approve
 86      *
 87      * @return mixed
 88      */
 89     public function approve()
 90     {
 91         $this->setAttribute('status', static::APPROVED);
 92 
 93         return $this;
 94     }
 95 
 96     /**
 97      * Approve if only it's not expired.
 98      *
 99      * @return mixed
100      */
101     public function approveIf()
102     {
103         if (! $this->valid()) {
104             throw new LogicException('Cannot be approved, because validation process is expired.');
105         }
106 
107         return $this->approve();
108     }
109 
110     /**
111      * Reject.
112      *
113      * @return mixed
114      */
115     public function reject()
116     {
117         $this->setAttribute('status', static::REJECTED);
118 
119         return $this;
120     }
121 
122     /**
123      * Reject if only it's not expired.
124      *
125      * @return mixed
126      */
127     public function rejectIf()
128     {
129         if (! $this->valid()) {
130             throw new LogicException('Cannot be rejected, because validation process is expired.');
131         }
132 
133         return $this->reject();
134     }
135 
136     /**
137      * Reset.
138      *
139      * @return mixed
140      */
141     public function reset()
142     {
143         $this->setAttribute('status', static::UNPROCESSED);
144 
145         return $this;
146     }
147 
148     /**
149      * Reset if only it's not expired.
150      *
151      * @return mixed
152      */
153     public function resetIf()
154     {
155         if (! $this->valid()) {
156             throw new LogicException('Cannot be reseted, because validation process is expired.');
157         }
158 
159         return $this->resetIf();
160     }
161 }
162 
LFT API documentation generated by ApiGen