本文整理汇总了PHP中ReflectionClass::getShortname方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getShortname方法的具体用法?PHP ReflectionClass::getShortname怎么用?PHP ReflectionClass::getShortname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getShortname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: arrayValuesCheck
/**
* Simple test to see if array values are of specified type.
*
* @param array $array Array of values.
* @param string $type Type to check
* @param string $className Named class, if type == 'class'
* @return boolean Returns true is all values match type, otherwise false.
*/
public static function arrayValuesCheck($array, $type, $className = '')
{
$status = true;
if (is_array($array) && is_string($type)) {
if ($type === 'class' && is_string($className) && !empty($className)) {
foreach ($array as $item) {
if (!is_null($item)) {
if (!is_object($item)) {
$status = false;
} else {
$class = new \ReflectionClass($item);
if (!preg_match("/{$className}/", $class->getShortname())) {
$status = false;
}
}
}
}
} else {
foreach ($array as $item) {
$function = 'is_' . $type;
if (function_exists($function)) {
if ($function($item) === false) {
$status = false;
}
} else {
$status = false;
}
}
}
} else {
$status = false;
}
return $status;
}
示例2: normalize
/**
* {@inheritdoc}
*/
public function normalize($violationList, $format = null, array $context = [])
{
if ($violationList instanceof \Exception) {
if ($this->debug) {
$trace = $violationList->getTrace();
}
}
$data = ['@context' => '/api/contexts/ConstraintViolationList', '@type' => 'ConstraintViolationList', 'title' => 'An error occurred', 'violations' => []];
foreach ($violationList as $violation) {
$key = $violation->getPropertyPath();
$invalidValue = $violation->getInvalidValue();
if (method_exists($violation->getRoot(), '__toString')) {
$invalidValue = $this->propertyAccessor->getValue($violation->getRoot(), $violation->getPropertyPath());
}
if ($violation->getConstraint() instanceof UniqueEntity) {
$class = method_exists($violation->getRoot(), 'getConfig') ? $violation->getRoot()->getConfig() : $violation->getRoot();
$reflexion = new \ReflectionClass($class);
$key = strtolower($reflexion->getShortname());
}
$data['violations'][$key][] = ['property' => $violation->getPropertyPath(), 'invalidValue' => $invalidValue, 'message' => $violation->getMessage()];
}
if (isset($trace)) {
$data['trace'] = $trace;
}
return $data;
}
示例3: __construct
/**
* Builds the ConfigOptions object.
*
* Passing an array of key value pairs will set the configuration for each
* child object created from this parent object.
*
* @param mixed $child Child ConfigOption object.
* @param array $config Array of options.
* @throws InvalidConfigValue
* @throws InvalidConfigProperty
* @return mixed
*/
public function __construct($child, $config)
{
$class = new \ReflectionClass($child);
$this->type = $class->getShortname();
$this->options = array_map(function ($prop) {
return $prop->name;
}, $class->getProperties(\ReflectionProperty::IS_PUBLIC));
if (is_array($config)) {
foreach ($config as $option => $value) {
if (in_array($option, $this->options)) {
$this->{$option}($value);
} else {
throw new InvalidConfigProperty($this->type, __FUNCTION__, $option, $this->options);
}
}
} else {
throw new InvalidConfigValue(__FUNCTION__, 'array', 'with valid keys as ' . Utils::arrayToPipedString($this->options));
}
}