Back to WebAssetManager class

Method __call

public mixed
__call
(mixed $method, mixed $arguments)
Adds support for magic method calls
Parameters
  • string $method A method name
  • array $arguments Arguments for a method
Returns
  • mixed
Since
  • 4.0.0
-
  • \BadMethodCallException

Method __call - Source code

/**
 * Adds support for magic method calls
 *
 * @param   string  $method     A method name
 * @param   array   $arguments  Arguments for a method
 *
 * @return mixed
 *
 * @throws  \BadMethodCallException
 *
 * @since  4.0.0
 */
public function __call($method, $arguments)
{
    $method = strtolower($method);
    if (0 === strpos($method, 'use')) {
        $type = substr($method, 3);
        if (empty($arguments[0])) {
            throw new \BadMethodCallException('An asset name is required');
        }
        return $this->useAsset($type, $arguments[0]);
    }
    if (0 === strpos($method, 'addinline')) {
        $type = substr($method, 9);
        if (empty($arguments[0])) {
            throw new \BadMethodCallException('Content is required');
        }
        return $this->addInline($type, ...$arguments);
    }
    if (0 === strpos($method, 'disable')) {
        $type = substr($method, 7);
        if (empty($arguments[0])) {
            throw new \BadMethodCallException('An asset name is required');
        }
        return $this->disableAsset($type, $arguments[0]);
    }
    if (0 === strpos($method, 'register')) {
        // Check for registerAndUse<Type>
        $andUse = substr($method, 8, 6) === 'anduse';
        // Extract the type
        $type = $andUse ? substr($method, 14) : substr($method, 8);
        if (empty($arguments[0])) {
            throw new \BadMethodCallException('An asset instance or an asset name is required');
        }
        if ($andUse) {
            $name = $arguments[0] instanceof WebAssetItemInterface ? $arguments[0]->getName() : $arguments[0];
            return $this->registerAsset($type, ...$arguments)->useAsset($type, $name);
        } else {
            return $this->registerAsset($type, ...$arguments);
        }
    }
    throw new \BadMethodCallException(sprintf('Undefined method %s in class %s', $method, get_class($this)));
}