本文整理汇总了PHP中ReflectionProperty::getDocComment方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::getDocComment方法的具体用法?PHP ReflectionProperty::getDocComment怎么用?PHP ReflectionProperty::getDocComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::getDocComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startReflection
protected function startReflection()
{
$this->class = get_class($this);
$refClass = new ReflectionClass($this->class);
$this->properties = $refClass->getProperties();
//set table name
$tableNameArr = array();
preg_match("/(@Tablename )(.*)/", $refClass->getDocComment(), $tableNameArr);
if (isset($tableNameArr[0])) {
$this->table = $tableNameArr[2];
} else {
$this->table = strtolower($this->class);
}
//set columns
$cont = 0;
foreach ($this->properties as $prop) {
if ($prop->class != "DAO") {
$columnNamesArr = array();
$refProp = new ReflectionProperty($this->class, $prop->name);
preg_match("/(@Columnname )(.*)/", $refProp->getDocComment(), $columnNamesArr);
preg_match("/(@Columntype )(.*)/", $refProp->getDocComment(), $columnTypesArr);
$this->columns[$cont]['name'] = $prop->name;
if (isset($columnNamesArr[0])) {
$this->columns[$cont]['column'] = $columnNamesArr[2];
} else {
$this->columns[$cont]['column'] = strtolower($prop->name);
}
$this->columns[$cont]['type'] = isset($columnTypesArr[2]) ? $columnTypesArr[2] : 'string';
$cont++;
}
}
//reflection object
$this->refObj = new ReflectionObject($this);
}
示例2: match
/**
* @param $pattern
* @return null|string
*/
private function match($pattern)
{
$matches = array();
$found = preg_match($pattern, $this->property->getDocComment(), $matches);
if (!$found) {
return null;
}
return $matches[1];
}
示例3: __construct
public function __construct(\ReflectionClass $reflectionClass, \ReflectionProperty $reflectionProperty)
{
$reflectionProperty->setAccessible(true);
if (strpos($reflectionProperty->getDocComment(), "@skipSerialization") !== false) {
$this->isSkipped = true;
}
if (strpos($reflectionProperty->getDocComment(), "@var") === false) {
throw new PropertyTypeWasNotDefined($reflectionClass->getName(), $reflectionProperty->getName());
}
if (preg_match('/@var\\s+([^\\s]+)/', $reflectionProperty->getDocComment(), $matches)) {
list(, $type) = $matches;
$types = explode("|", $type);
if (!empty($types)) {
foreach ($types as $type) {
if ($pos = strpos($type, '[]')) {
$this->isArray = true;
$type = substr($type, 0, $pos);
}
if (class_exists($type)) {
// Object
$this->types[] = $type;
$typeReflectionClass = new \ReflectionClass($type);
if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
$this->isObject = $type;
}
} else {
$typeCheck = $reflectionClass->getNamespaceName() . '\\' . $type;
if (class_exists($typeCheck)) {
// Object
$this->types[] = $typeCheck;
$typeReflectionClass = new \ReflectionClass($typeCheck);
if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
$this->isObject = $typeCheck;
}
} else {
$aliases = $this->getAliases($reflectionClass->getFileName());
if (array_key_exists($type, $aliases) && class_exists($aliases[$type])) {
$type = $aliases[$type];
// Object
$this->types[] = $type;
$typeReflectionClass = new \ReflectionClass($type);
if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
$this->isObject = $type;
}
} else {
$this->types[] = $type = null;
}
}
}
}
array_unique($this->types);
}
}
$this->reflectionClass = $reflectionClass;
$this->reflectionProperty = $reflectionProperty;
}
开发者ID:simensen,项目名称:monii-reflection-properties-serializer,代码行数:56,代码来源:ReflectionPropertyHelper.php
示例4: from
/**
* @return self
*/
public static function from(\ReflectionProperty $from)
{
$prop = new static($from->getName());
$defaults = $from->getDeclaringClass()->getDefaultProperties();
$prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
$prop->static = $from->isStatic();
$prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
$prop->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
return $prop;
}
示例5: resolvePropertyMetadata
/**
* Generic class property resolver.
*
* @param \ReflectionProperty $property
* @param ClassMetadata $classMetadata
*
* @return PropertyMetadata Resolved property metadata
*/
protected function resolvePropertyMetadata(\ReflectionProperty $property, ClassMetadata $classMetadata) : PropertyMetadata
{
// Create method metadata instance
$propertyMetadata = $classMetadata->propertiesMetadata[$property->getName()] ?? new PropertyMetadata($classMetadata);
$propertyMetadata->name = $property->getName();
$propertyMetadata->modifiers = $property->getModifiers();
$propertyMetadata->isPublic = $property->isPublic();
$propertyMetadata->typeHint = $this->getCommentTypeHint(is_string($property->getDocComment()) ? $property->getDocComment() : '');
// Store property metadata to class metadata
return $classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata;
}
示例6: __construct
public function __construct(\ReflectionProperty $property, array $classConfig, \rg\injektor\Configuration $config, \rg\injektor\DependencyInjectionContainer $dic)
{
$this->property = $property;
$this->classConfig = $classConfig;
$this->config = $config;
$this->dic = $dic;
$this->name = $property->name;
$this->docComment = $this->property->getDocComment();
$this->additionalArguments = $this->dic->getParamsFromPropertyTypeHint($this->property, 'var');
$this->analyze();
}
示例7: getPropertyClass
/**
* Parse the docblock of the property to get the class of the var annotation.
*
* @param \ReflectionProperty $property
*
* @throws AnnotationException Non exists class.
*
* @return null|ObjectDefinition
*/
public function getPropertyClass(\ReflectionProperty $property)
{
$propertyComment = $property->getDocComment();
if (!preg_match('/@var\\s+([^\\s\\(\\*\\/]+)/', $propertyComment, $matches)) {
return;
}
$className = end($matches);
if (!is_string($className) || in_array($className, static::$ignoredTypes)) {
return;
}
$classWithNamespace = $className;
if ($this->namespaceExists($classWithNamespace) === false) {
$classWithNamespace = $this->namespace . '\\' . $className;
}
if (!$this->classExists($classWithNamespace)) {
$declaringClass = $property->getDeclaringClass();
throw new AnnotationException(sprintf('The @var annotation on %s::%s contains a non existent class "%s"', $declaringClass->name, $property->getName(), $className));
}
$createNewObject = function ($propertyComment, $className, $classWithNamespace) {
$classParameters = $this->propertyClassParameters($propertyComment, $className);
if (is_array($classParameters)) {
$values = [];
foreach ($classParameters as $value) {
$values[] = static::parseValue($value);
}
$object = new ObjectDefinition($classWithNamespace, $className);
$object->setConstructorInjection($values);
return $object;
}
return new $classWithNamespace();
};
return $createNewObject($propertyComment, $className, $classWithNamespace);
}
示例8: getDocumentation
/**
* <p>
* Polymorphic method that allows you to retreive both Object, Attributes and Methods documentation
* from the current object.
* </p>
*
* @param String $method
*/
public function getDocumentation($target = NULL, $type = self::OBJECT)
{
if ($target == NULL && $type != self::OBJECT) {
return FALSE;
}
switch ($type) {
case self::OBJECT:
$target = $target == NULL ? $this->obj : $target;
$reflection = new ReflectionClass($target);
break;
case self::METHOD:
$reflection = new ReflectionMethod($this->obj, $target);
break;
case self::ATTR:
$reflection = new ReflectionProperty($this->obj, $target);
break;
default:
return FALSE;
break;
}
if (is_object($target)) {
$target = get_class($target);
}
return $this->cacheComment[@get_class($this->obj)][$target] = $reflection->getDocComment();
}
示例9: startReflection
protected function startReflection()
{
$this->class = get_class($this);
$refClass = new ReflectionClass($this->class);
$this->properties = $refClass->getProperties();
//set table name
$tableNameArr = array();
preg_match("/(@Tablename )(.*)/", $refClass->getDocComment(), $tableNameArr);
if (isset($tableNameArr[0])) {
$this->table = $tableNameArr[2];
} else {
$this->table = strtolower($this->class);
}
$this->getTableRows();
//set columns
$cont = 0;
foreach ($this->properties as $k => $prop) {
if ($prop->class != "DAO") {
$columnNamesArr = array();
$refProp = new ReflectionProperty($this->class, $prop->name);
preg_match("/(@Columnname )(.*)/", $refProp->getDocComment(), $columnNamesArr);
foreach ($this->columns as $id => $column) {
if ($column['name'] == $prop->name || isset($columnNamesArr[0]) && $column['name'] == $columnNamesArr[2]) {
$this->fieldsMap[$prop->name] = $id;
}
}
$cont++;
} else {
unset($this->properties[$k]);
}
}
//reflection object
$this->refObj = new ReflectionObject($this);
}
示例10: parseAttribute
private function parseAttribute($class, $attribute)
{
$attr = new ReflectionProperty($class, $attribute);
$annotations = array('validate' => $attr->isProtected(), 'mandatory' => true);
$comment = $attr->getDocComment();
if (!$comment) {
return $annotations;
}
if (!preg_match_all('/\\s*\\* @(\\w+) ([^\\n\\r]*)/', $comment, $matches)) {
return $annotations;
}
foreach ($matches[1] as $index => $match) {
$value = $matches[2][$index];
switch ($value) {
case 'false':
$value = false;
break;
case 'true':
$value = true;
break;
}
$annotations[$match] = $value;
}
return $annotations;
}
示例11: getTypeOfProperty
private function getTypeOfProperty(\ReflectionProperty $prop)
{
if (preg_match('/^[\\s\\/*]*@var\\s+(\\S+)/m', $prop->getDocComment(), $matches)) {
return $this->getFullNameOfType($matches[1], $prop->getDeclaringClass());
}
return;
}
示例12: validate
/**
* Method to validate the value object with the madatory fields
* Uses the reflections to read the annotated objects
* and set error message based on the text
*/
function validate()
{
$invalidProperties = array();
foreach (array_keys(get_class_vars(get_class($this))) as $key) {
$value = $this->{$key};
$ref = new ReflectionProperty(get_class($this), $key);
$docTagValue = $ref->getDocComment();
if (strpos($docTagValue, 'mandatory') != false) {
if (!$this->checkIfNull($value, $key)) {
array_push($invalidProperties, $this->getMessage($docTagValue, $key));
}
}
}
print_r($this->containsDynamicField);
if ($this->containsDynamicField) {
foreach ($this->dynamicFields as $key) {
$value = $this->{$key};
if (!$this->checkIfNull($value, $key)) {
$messageValue = $this->dynamicFieldsValidation[$key];
if (!isset($messageValue) || $messageValue == null) {
$messageValue = "Enter Value for " . $key;
}
array_push($invalidProperties, $messageValue);
}
}
}
return $invalidProperties;
}
示例13: getNativePropertyType
/**
* @param ReflectionProperty
* @param array (string => string)
* @param string
* @return string
*/
public function getNativePropertyType(ReflectionProperty $prop, &$defaults, &$type)
{
$name = $prop->getName();
if ($doc = trim($prop->getDocComment(), " \t\r\n*/")) {
if (preg_match('/@var[ \\t]+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\s*(:?\\[[\\s0-9]*\\]|)/', $doc, $m)) {
if ($m[2]) {
$type = 'arr';
} else {
$type = substr(strtolower($m[1]), 0, 3);
if ($type == 'mix') {
$type = 'str';
} elseif (!in_array($type, self::$phpTypes)) {
$type = 'obj';
}
}
}
}
if (!$type) {
$type = substr(gettype(self::referenceObj($prop->getDeclaringClass()->getName())->{$name}), 0, 3);
}
$nativeType = $this->nativeTypes[$type == 'str' ? strlen('' . $defaults[$name]) > 255 ? 'tex' : 'str' : $type];
if (!$nativeType) {
throw new IllegalTypeException('Unstorable type: ' . $type . ' for property: ' . $name);
}
return $nativeType;
}
示例14: __construct
public function __construct($class, $property)
{
$property = new ReflectionProperty($class, $property);
list($description, $tags) = Kodoc::parse($property->getDocComment());
$this->description = $description;
if ($modifiers = $property->getModifiers()) {
$this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
}
if (isset($tags['var'])) {
if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
$this->type = $matches[1];
if (isset($matches[2])) {
$this->description = Markdown($matches[2]);
}
}
}
$this->property = $property;
// Show the value of static properties, but only if they are public or we are php 5.3 or higher and can force them to be accessible
if ($property->isStatic() and ($property->isPublic() or version_compare(PHP_VERSION, '5.3', '>='))) {
// Force the property to be accessible
if (version_compare(PHP_VERSION, '5.3', '>=')) {
$property->setAccessible(TRUE);
}
// Don't debug the entire object, just say what kind of object it is
if (is_object($property->getValue($class))) {
$this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>';
} else {
$this->value = Kohana::debug($property->getValue($class));
}
}
}
示例15: __construct
public function __construct(\ReflectionProperty $property)
{
$this->_property = $property;
$comment = $property->getDocComment();
$comment = new DocBloc($comment);
$this->_annotations = $comment->getAnnotations();
}