Beispiel #1
0
     * @param   callable  $function
     * @throws  \InvalidArgumentException
     */
    public static function defineCheck(string $method, callable $function)
    {
        if (function_exists($method)) {
            throw new \InvalidArgumentException('Can not overwrite internal PHP function ' . $method . '().');
        }
        self::$checks[$method] = $function;
    }
    /**
     * intercept calls to dynamicly added methods
     *
     * @param   string  $method     name of method
     * @param   array   $arguments  list of additional arguments for method
     * @return  bool
     * @throws  \BadMethodCallException  in case called method does not exist
     */
    public function __call(string $method, array $arguments) : bool
    {
        if (!isset(self::$checks[$method]) && !function_exists($method)) {
            throw new \BadMethodCallException('Method ' . __CLASS__ . '::' . $method . '() does not exist.');
        } elseif (!isset(self::$checks[$method]) && function_exists($method)) {
            return $method($this->value, ...$arguments);
        }
        $function = self::$checks[$method];
        return $function($this->value, ...$arguments);
    }
}
Value::__static();