for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace LaravelDoctrine\Fluent\Builders\Traits;
use InvalidArgumentException;
trait Macroable
{
/**
* @var callable[]
*/
protected static $macros = [];
* @param string $method
* @param callable|null $callback
public static function macro($method, callable $callback = null)
if (!is_callable($callback)) {
throw new InvalidArgumentException('Fluent builder should be extended with a closure argument, none given');
}
self::$macros[$method] = $callback;
*
* @return bool
public function hasMacro($method)
return isset(self::$macros[$method]);
* @return callable
public function getMacro($method)
return self::$macros[$method];
* @param array $params
* @return mixed
public function callMacro($method, array $params = [])
// Add builder as first closure param, append the given params
array_unshift($params, $this);
return call_user_func_array($this->getMacro($method), $params);