コード例 #1
0
 /**
  * Exports a reflected object.
  *
  * @param \TokenReflection\Broker $broker   Broker instance
  * @param string|object|null      $class    Class name, class instance or null
  * @param string                  $constant Constant name
  * @param boolean                 $return   Return the export instead of outputting it
  *
  * @return string|null
  * @throws \TokenReflection\Exception\RuntimeException If requested parameter doesn't exist.
  */
 public static function export(Broker $broker, $class, $constant, $return = false)
 {
     $className = is_object($class) ? get_class($class) : $class;
     $constantName = $constant;
     if (null === $className) {
         $constant = $broker->getConstant($constantName);
         if (null === $constant) {
             throw new Exception\RuntimeException('Constant does not exist.', Exception\RuntimeException::DOES_NOT_EXIST);
         }
     } else {
         $class = $broker->getClass($className);
         if ($class instanceof Invalid\ReflectionClass) {
             throw new Exception\RuntimeException('Class is invalid.', Exception\RuntimeException::UNSUPPORTED);
         } elseif ($class instanceof Dummy\ReflectionClass) {
             throw new Exception\RuntimeException('Class does not exist.', Exception\RuntimeException::DOES_NOT_EXIST, $class);
         }
         $constant = $class->getConstantReflection($constantName);
     }
     if ($return) {
         return $constant->__toString();
     }
     echo $constant->__toString();
 }