for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/******************************************************************************
* This file is part of the "andrey-helldar/support" project. *
* *
* @author Andrey Helldar <[email protected]> *
* @copyright 2021 Andrey Helldar *
* @license MIT *
* @see https://github.com/andrey-helldar/support *
* For the full copyright and license information, please view the LICENSE *
* file that was distributed with this source code. *
******************************************************************************/
namespace Helldar\Support\Concerns;
trait Resolvable
{
protected static $resolved = [];
protected static function resolveInstance($instance, ...$parameters)
$class = is_object($instance) ? get_class($instance) : $instance;
if (isset(self::$resolved[$class])) {
return self::$resolved[$class];
}
return self::$resolved[$class] = is_object($instance) ? $instance : new $instance(...$parameters);
protected static function resolveCallback(string $value, callable $callback)
$class = static::getSameClass();
if (isset(static::$resolved[$class][$value])) {
return static::$resolved[$class][$value];
return static::$resolved[$class][$value] = $callback($value);
protected static function getSameClass(): string
return static::class;