Assert\Assertion::methodExists PHP Method

methodExists() public static method

Determines that the named method is defined in the provided object.
public static methodExists ( string $value, mixed $object, null $message = null, null $propertyPath = null ) : boolean
$value string
$object mixed
$message null
$propertyPath null
return boolean
    public static function methodExists($value, $object, $message = null, $propertyPath = null)
    {
        self::isObject($object, $message, $propertyPath);
        if (!method_exists($object, $value)) {
            $message = sprintf($message ?: 'Expected "%s" does not exist in provided object.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_METHOD, $propertyPath);
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Puzzle constructor.
  *
  * @param string   $name  The puzzle name
  * @param string[] $parts The different puzzle parts in a 'method' => 'output format' array
  */
 public function __construct(string $name, array $parts)
 {
     $this->name = $name;
     foreach ($parts as $method => $format) {
         Assertion::methodExists($method, $this, sprintf("Could not find part '%s' method in %s", $method, get_called_class()));
         Assertion::string($format);
     }
     $this->parts = $parts;
 }
All Usage Examples Of Assert\Assertion::methodExists