object() public static method

public static object ( $value, $message = '' )
Example #1
0
File: NSA.php Project: nyholm/nsa
 /**
  * Get an reflection property that you can access directly.
  *
  * @param object|string $objectOrClass
  * @param string        $propertyName
  *
  * @return \ReflectionProperty
  *
  * @throws \InvalidArgumentException
  * @throws \LogicException           if the property is not found on the object
  */
 protected static function getAccessibleReflectionProperty($objectOrClass, $propertyName)
 {
     Assert::string($propertyName, 'Property name must be a string. Variable of type "%s" was given.');
     $class = $objectOrClass;
     if (!is_string($objectOrClass)) {
         Assert::object($objectOrClass, 'Can not get a property of a non object. Variable of type "%s" was given.');
         Assert::notInstanceOf($objectOrClass, '\\stdClass', 'Can not get a property of \\stdClass.');
         $class = get_class($objectOrClass);
     }
     if (null === ($refl = static::getReflectionClassWithProperty($class, $propertyName))) {
         throw new \LogicException(sprintf('The property %s does not exist on %s or any of its parents.', $propertyName, $class));
     }
     $property = $refl->getProperty($propertyName);
     $property->setAccessible(true);
     if (!$property->isStatic()) {
         Assert::object($objectOrClass, 'Can not access non-static property without an object.');
     }
     return $property;
 }