2016-10-13 13:11:22 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-08-04 14:55:37 -04:00
|
|
|
/**
|
|
|
|
* Ion
|
|
|
|
*
|
|
|
|
* Building blocks for web development
|
|
|
|
*
|
2016-10-13 13:11:22 -04:00
|
|
|
* PHP version 7
|
2016-08-26 23:10:20 -04:00
|
|
|
*
|
2016-08-04 14:55:37 -04:00
|
|
|
* @package Ion
|
2016-08-26 23:10:20 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 1.0.0
|
|
|
|
* @link https://git.timshomepage.net/timw4mail/ion
|
2016-08-04 14:55:37 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\Ion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trait to allow calling a method statically,
|
|
|
|
* as well as with an instance
|
|
|
|
*/
|
|
|
|
trait StaticInstance {
|
|
|
|
/**
|
|
|
|
* Instance for 'faking' static methods
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
private static $instance = [];
|
|
|
|
|
|
|
|
/**
|
2016-08-26 23:10:20 -04:00
|
|
|
* Call protected methods to allow for
|
2016-08-04 14:55:37 -04:00
|
|
|
* static and instance calling
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
* @param string $method
|
2016-08-26 17:21:50 -04:00
|
|
|
* @param array $args
|
2016-08-26 23:10:20 -04:00
|
|
|
* @return mixed
|
2016-08-04 14:55:37 -04:00
|
|
|
*/
|
2016-10-20 20:08:11 -04:00
|
|
|
public function __call(string $method, array $args)
|
2016-08-04 14:55:37 -04:00
|
|
|
{
|
2017-02-22 15:41:30 -05:00
|
|
|
$class = \get_called_class();
|
2016-08-04 14:55:37 -04:00
|
|
|
if (method_exists($this, $method))
|
|
|
|
{
|
|
|
|
return call_user_func_array([$this, $method], $args);
|
|
|
|
}
|
2017-02-22 15:41:30 -05:00
|
|
|
else if(method_exists($class, $method))
|
|
|
|
{
|
|
|
|
return static::__callStatic($method, $args);
|
|
|
|
}
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call non-static methods statically, so that
|
|
|
|
* an instance of the class isn't required
|
|
|
|
*
|
|
|
|
* @param string $method
|
2016-08-26 17:21:50 -04:00
|
|
|
* @param array $args
|
2016-08-04 14:55:37 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-10-20 20:08:11 -04:00
|
|
|
public static function __callStatic(string $method, array $args)
|
2016-08-04 14:55:37 -04:00
|
|
|
{
|
2017-02-22 15:41:30 -05:00
|
|
|
return call_user_func_array([\get_called_class(), $method], $args);
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of StaticInstance.php
|