Assert\Assertion::classExists PHP Метод

classExists() публичный статический Метод

Assert that the class exists.
public static classExists ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
Результат boolean
    public static function classExists($value, $message = null, $propertyPath = null)
    {
        if (!class_exists($value)) {
            $message = sprintf($message ?: 'Class "%s" does not exist.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_CLASS, $propertyPath);
        }
        return true;
    }

Usage Example

Пример #1
0
 /**
  * @param MappingInterface[] $mappings
  */
 public function __construct(array $mappings, string $className, callable $apply = null, callable $unapply = null)
 {
     foreach ($mappings as $mappingKey => $mapping) {
         Assertion::string($mappingKey);
         Assertion::isInstanceOf($mapping, MappingInterface::class);
         $this->mappings[$mappingKey] = $mapping->withPrefixAndRelativeKey($this->key, $mappingKey);
     }
     Assertion::classExists($className);
     if (null === $apply) {
         $apply = function (...$arguments) {
             return new $this->className(...array_values($arguments));
         };
     }
     if (null === $unapply) {
         $unapply = function ($value) {
             Assertion::isInstanceOf($value, $this->className);
             $values = [];
             $reflectionClass = new ReflectionClass($this->className);
             foreach ($reflectionClass->getProperties() as $property) {
                 /* @var $property ReflectionProperty */
                 $property->setAccessible(true);
                 $values[$property->getName()] = $property->getValue($value);
             }
             return $values;
         };
     }
     $this->className = $className;
     $this->apply = $apply;
     $this->unapply = $unapply;
 }
All Usage Examples Of Assert\Assertion::classExists