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 Docotory;
  4 
  5 use ArrayAccess;
  6 
  7 /**
  8  * Base factory class. It can produce many type of a product, you can also bind them on the fly.
  9  *
 10  * @author Krisan Alfa Timur <krisanalfa@docotel.co.id>
 11  */
 12 abstract class Factory implements ArrayAccess
 13 {
 14     /**
 15      * Resolved types stack
 16      *
 17      * @var array
 18      */
 19     protected static $resolved = [];
 20 
 21     /**
 22      * Registered custom creator
 23      *
 24      * @var array
 25      */
 26     protected static $customCreator = [];
 27 
 28     /**
 29      * Register new custom creator
 30      *
 31      * @param string   $type
 32      * @param callable $callable
 33      *
 34      * @return void
 35      */
 36     public static function extend($type, callable $callable)
 37     {
 38         static::$customCreator[$type] = $callable;
 39     }
 40 
 41     /**
 42      * Register a custom creator if it has not been registered yet
 43      *
 44      * @param string   $type
 45      * @param callable $callable
 46      *
 47      * @return void
 48      */
 49     public static function extendIf($type, callable $callable)
 50     {
 51         if (! static::hasCustomCreator($type)) {
 52             static::extend($type, $callable);
 53         }
 54     }
 55 
 56     /**
 57      * Register a new instance of a given type
 58      *
 59      * @param string $type
 60      * @param mixed  $instance
 61      *
 62      * @return void
 63      */
 64     public static function instance($type, $instance)
 65     {
 66         static::$resolved[$type] = $instance;
 67     }
 68 
 69     /**
 70      * Determine if a custom creator has been registered or not
 71      *
 72      * @param string $type
 73      *
 74      * @return boolean
 75      */
 76     public static function hasCustomCreator($type)
 77     {
 78         return isset(static::$customCreator[$type]);
 79     }
 80 
 81     /**
 82      * Determine if a type has been resolved
 83      *
 84      * @param string $type
 85      *
 86      * @return boolean
 87      */
 88     public static function resolved($type)
 89     {
 90         return isset(static::$resolved[$type]);
 91     }
 92 
 93     /**
 94      * Call custom creator
 95      *
 96      * @param string $type
 97      *
 98      * @return mixed
 99      */
100     protected static function callCustomCreator($type)
101     {
102         return call_user_func_array(static::$customCreator[$type], [container()]);
103     }
104 
105     /**
106      * Get type
107      *
108      * @param string $type
109      *
110      * @throws ResolvingTypeException
111      *
112      * @return mixed
113      */
114     public function __get($type)
115     {
116         if (static::resolved($type)) {
117             return static::$resolved[$type];
118         }
119 
120         if (static::hasCustomCreator($type)) {
121             $instance = static::callCustomCreator($type);
122         } else {
123             if (!method_exists($this, $methodName = 'create'.ucfirst($type))) {
124                 throw new ResolvingTypeException("Type [$type] is not supported!");
125             }
126 
127             $instance = $this->{$methodName}();
128         }
129 
130         return static::$resolved[$type] = $instance;
131     }
132 
133     /**
134      * Set instance of a type
135      *
136      * @param string $type
137      * @param mixed  $instance
138      */
139     public function __set($type, $instance)
140     {
141         static::instance($type, $instance);
142     }
143 
144     /**
145      * Determine if an item exists at an offset.
146      *
147      * @param mixed $type
148      *
149      * @return bool
150      */
151     public function offsetExists($type)
152     {
153         return static::resolved($type);
154     }
155 
156     /**
157      * Get an item at a given offset.
158      *
159      * @param mixed $type
160      *
161      * @return mixed
162      */
163     public function offsetGet($type)
164     {
165         return static::$resolved[$type];
166     }
167 
168     /**
169      * Set the item at a given offset.
170      *
171      * @param mixed $type
172      * @param mixed $instance
173      */
174     public function offsetSet($type, $instance)
175     {
176         static::instance($type, $instance);
177     }
178 
179     /**
180      * Unset the item at a given offset.
181      *
182      * @param string $type
183      */
184     public function offsetUnset($type)
185     {
186         unset(static::$resolved[$type]);
187     }
188 }
189 
LFT API documentation generated by ApiGen