Overview

Namespaces

  • Composer
    • Autoload
  • Illuminate
    • Support
      • Contracts
      • Facades
  • Laravella
    • Cart
      • Facades
  • None
  • PHP

Classes

  • App
  • Artisan
  • Auth
  • Blade
  • Cache
  • Config
  • Cookie
  • Crypt
  • DB
  • Event
  • Facade
  • File
  • Form
  • Hash
  • HTML
  • Input
  • Lang
  • Log
  • Mail
  • Paginator
  • Password
  • Queue
  • Redirect
  • Redis
  • Request
  • Response
  • Route
  • Schema
  • Session
  • URL
  • Validator
  • View
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php namespace Illuminate\Support\Facades;
  2: 
  3: use Mockery\MockInterface;
  4: 
  5: abstract class Facade {
  6: 
  7:     /**
  8:      * The application instance being facaded.
  9:      *
 10:      * @var \Illuminate\Foundation\Application
 11:      */
 12:     protected static $app;
 13: 
 14:     /**
 15:      * The resolved object instances.
 16:      *
 17:      * @var array
 18:      */
 19:     protected static $resolvedInstance;
 20: 
 21:     /**
 22:      * Hotswap the underlying instance behind the facade.
 23:      *
 24:      * @param  mixed  $instance
 25:      * @return void
 26:      */
 27:     public static function swap($instance)
 28:     {
 29:         static::$resolvedInstance[static::getFacadeAccessor()] = $instance;
 30: 
 31:         static::$app->instance(static::getFacadeAccessor(), $instance);
 32:     }
 33: 
 34:     /**
 35:      * Initiate a mock expectation on the facade.
 36:      *
 37:      * @param  dynamic
 38:      * @return \Mockery\Expectation
 39:      */
 40:     public static function shouldReceive()
 41:     {
 42:         $name = static::getFacadeAccessor();
 43: 
 44:         if (static::isMock())
 45:         {
 46:             $mock = static::$resolvedInstance[$name];
 47:         }
 48:         else
 49:         {
 50:             static::$resolvedInstance[$name] = $mock = \Mockery::mock(static::getMockableClass($name));
 51: 
 52:             static::$app->instance($name, $mock);
 53:         }
 54: 
 55:         return call_user_func_array(array($mock, 'shouldReceive'), func_get_args());
 56:     }
 57: 
 58:     /**
 59:      * Determines whether a mock is set as the instance of the facade.
 60:      *
 61:      * @return bool
 62:      */
 63:     protected static function isMock()
 64:     {
 65:         $name = static::getFacadeAccessor();
 66: 
 67:         return isset(static::$resolvedInstance[$name]) and static::$resolvedInstance[$name] instanceof MockInterface;
 68:     }
 69: 
 70:     /**
 71:      * Get the mockable class for the bound instance.
 72:      *
 73:      * @return string
 74:      */
 75:     protected static function getMockableClass()
 76:     {
 77:         return get_class(static::getFacadeRoot());
 78:     }
 79: 
 80:     /**
 81:      * Get the root object behind the facade.
 82:      *
 83:      * @return mixed
 84:      */
 85:     public static function getFacadeRoot()
 86:     {
 87:         return static::resolveFacadeInstance(static::getFacadeAccessor());
 88:     }
 89: 
 90:     /**
 91:      * Get the registered name of the component.
 92:      *
 93:      * @return string
 94:      */
 95:     protected static function getFacadeAccessor()
 96:     {
 97:         throw new \RuntimeException("Facade does not implement getFacadeAccessor method.");
 98:     }
 99: 
100:     /**
101:      * Resolve the facade root instance from the container.
102:      *
103:      * @param  string  $name
104:      * @return mixed
105:      */
106:     protected static function resolveFacadeInstance($name)
107:     {
108:         if (is_object($name)) return $name;
109: 
110:         if (isset(static::$resolvedInstance[$name]))
111:         {
112:             return static::$resolvedInstance[$name];
113:         }
114: 
115:         return static::$resolvedInstance[$name] = static::$app[$name];
116:     }
117: 
118:     /**
119:      * Clear a resolved facade instance.
120:      *
121:      * @param  string  $name
122:      * @return void
123:      */
124:     public static function clearResolvedInstance($name)
125:     {
126:         unset(static::$resolvedInstance[$name]);
127:     }
128: 
129:     /**
130:      * Clear all of the resolved instances.
131:      *
132:      * @return void
133:      */
134:     public static function clearResolvedInstances()
135:     {
136:         static::$resolvedInstance = array();
137:     }
138: 
139:     /**
140:      * Get the application instance behind the facade.
141:      *
142:      * @return \Illuminate\Foundation\Application
143:      */
144:     public static function getFacadeApplication()
145:     {
146:         return static::$app;
147:     }
148: 
149:     /**
150:      * Set the application instance.
151:      *
152:      * @param  \Illuminate\Foundation\Application  $app
153:      * @return void
154:      */
155:     public static function setFacadeApplication($app)
156:     {
157:         static::$app = $app;
158:     }
159: 
160:     /**
161:      * Handle dynamic, static calls to the object.
162:      *
163:      * @param  string  $method
164:      * @param  array   $args
165:      * @return mixed
166:      */
167:     public static function __callStatic($method, $args)
168:     {
169:         $instance = static::resolveFacadeInstance(static::getFacadeAccessor());
170: 
171:         switch (count($args))
172:         {
173:             case 0:
174:                 return $instance->$method();
175: 
176:             case 1:
177:                 return $instance->$method($args[0]);
178: 
179:             case 2:
180:                 return $instance->$method($args[0], $args[1]);
181: 
182:             case 3:
183:                 return $instance->$method($args[0], $args[1], $args[2]);
184: 
185:             case 4:
186:                 return $instance->$method($args[0], $args[1], $args[2], $args[3]);
187: 
188:             default:
189:                 return call_user_func_array(array($instance, $method), $args);
190:         }
191:     }
192: 
193: }
cart API documentation generated by ApiGen 2.8.0