/** * Constructs a new ezcReflectionClass object. * * @param string|object|ReflectionClass $argument * Name, instance or ReflectionClass object of the class to be * reflected * @throws ReflectionException if the specified class doesn't exist */ public function __construct($argument) { if (!$argument instanceof parent) { parent::__construct($argument); } $this->reflectionSource = $argument; // TODO: Parse comment on demand to save CPU time and memory $this->docParser = ezcReflection::getDocCommentParser(); $this->docParser->parse($this->getDocComment()); }
/** * Returns a list of types * * @return ezcReflectionType[] */ public function getTypes() { if (is_null($this->types)) { $typeName = parent::getTypeName(); if ($typeName == ezcReflectionTypeMapper::CANONICAL_NAME_NUMBER) { $this->types = array(ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_INTEGER), ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_FLOAT)); } elseif ($typeName == ezcReflectionTypeMapper::CANONICAL_NAME_CALLBACK) { $this->types = array(ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_STRING), ezcReflection::getTypeByName('mixed[]'), ezcReflection::getTypeByName('Closure')); } else { $this->types = array(); } } return $this->types; }
public function testSetReflectionTypeFactory() { $factory = new ezcReflectionTypeFactoryImpl(); ezcReflection::setReflectionTypeFactory($factory); self::assertEquals($factory, ezcReflection::getReflectionTypeFactory()); }
/** * Internal method for parsing array type names. * * @return void */ protected function _parseTypeName() { //* if (strlen($this->typeName) > 0) { // last two chars are [], thus it should be something like string[] //if ( strlen( $this->typeName ) > 2 and substr( $this->typeName, -2 ) == '[]' ) if (preg_match(ezcReflectionTypeMapper::REGEXP_TYPE_NAME_LIST, $this->typeName, $matches)) { $this->isList = true; $this->isMap = false; $this->keyType = ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_INTEGER); $this->valueType = ezcReflection::getTypeByName($matches[1]); } elseif ($this->typeName == ezcReflectionTypeMapper::CANONICAL_NAME_ARRAY) { $this->isList = false; $this->isMap = true; $this->keyType = ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_MIXED); $this->valueType = ezcReflection::getTypeByName(ezcReflectionTypeMapper::CANONICAL_NAME_MIXED); } elseif (preg_match(ezcReflectionTypeMapper::REGEXP_TYPE_NAME_MAP, $this->typeName, $matches)) { $this->isList = false; $this->isMap = true; $this->keyType = ezcReflection::getTypeByName($matches[1]); $this->valueType = ezcReflection::getTypeByName($matches[2]); } } /*/ $seamsToBeMap = false; $pos = strrpos($this->typeName, '['); //there seams to be an array if ($pos !== false) { //proof there is no array map annotation around $posm = strrpos($this->typeName, ')'); if ($posm !== false) { if ($posm < $pos) { $typeName = substr($this->typeName, 0, $pos); $this->arrayType = ezcReflection::getTypeByName($typeName); } } else { $typeName = substr($this->typeName, 0, $pos); $this->arrayType = ezcReflection::getTypeByName($typeName); } } // TO BE DONE: add support for array(integer => mixed) if (preg_match(self::TYPE_NAME_REGEXP, $this->typeName, $matches)) { $type1 = null; $type2 = null; if (isset($matches[3])) { $type1 = ezcReflection::getTypeByName($matches[3]); } if (isset($matches[5])) { $type2 = ezcReflection::getTypeByName($matches[5]); } if ($type1 == null and $type2 != null) { $this->arrayType = $type2; } elseif ($type1 != null and $type2 == null) { $this->arrayType = $type1; } elseif ($type1 != null and $type2 != null) { $this->mapKeyType = $type1; $this->mapValueType = $type2; } } //*/ }
/** * Returns the type defined in PHPDoc annotations * * @return ezcReflectionType * @since PHP 5.1.0 */ function getReturnType() { $re = $this->docParser->getReturnAnnotations(); if (count($re) == 1 and isset($re[0]) and $re[0] instanceof ezcReflectionAnnotationReturn) { return ezcReflection::getTypeByName($re[0]->getTypeName()); } return null; }
/** * Returns the type of this parameter in form of an ezcReflectionType * * A valid type hint for the parameter will be preferred over a type * annotation. * * @return ezcReflectionType * @throws ReflectionException * if a parameter uses 'self' or 'parent' as type hint, but function * is not a class member, if a parameter uses 'parent' as type hint, * although class does not have a parent, or if the class does not * exist */ public function getType() { $typeHint = $this->getClass(); if ($typeHint instanceof ReflectionClass) { return ezcReflection::getTypeByName($typeHint); } else { return $this->type; } }
public function testGetLongDescription() { $class = new ReflectionClass('TestWebservice'); $doc = $class->getDocComment(); $parser = ezcReflection::getDocCommentParser(); $parser->parse($doc); $desc = $parser->getLongDescription(); $expected = "This is the long description with may be additional infos and much more lines\nof text.\n\nEmpty lines are valid, too.\n\nfoo bar"; self::assertEquals($expected, $desc); }
/** * Determines the type of the property based on source code annotations. * * @return ezcReflectionType Type of the property * @since PHP 5.1.0 */ public function getType() { $vars = $this->docParser->getVarAnnotations(); if (isset($vars[0])) { return ezcReflection::getTypeByName($vars[0]->getTypeName()); } else { return null; } }
/** * Sets the factory used to create type objects * * @param ezcReflectionTypeFactory $factory Factory for type objects * @return void */ public static function setReflectionTypeFactory(ezcReflectionTypeFactory $factory) { self::$reflectionTypeFactory = $factory; }
public function testGetLongDescription() { $class = new ReflectionClass('TestWebservice'); $doc = $class->getDocComment(); $parser = ezcReflection::getDocCommentParser(); $parser->parse($doc); $desc = $parser->getLongDescription(); $expected = <<<ENDDATA This is the long description with may be additional infos and much more lines of text. Empty lines are valid, too. foo bar Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ENDDATA; self::assertEquals($expected, $desc); }