本文整理汇总了PHP中Reflection::getReflectionClass方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflection::getReflectionClass方法的具体用法?PHP Reflection::getReflectionClass怎么用?PHP Reflection::getReflectionClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reflection
的用法示例。
在下文中一共展示了Reflection::getReflectionClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: launch
/**
* @param null $instance
* @param array $parameters
* @param Manager $manager
* @return mixed
* @throws Exception
*/
function launch($instance = null, $parameters, Manager $manager)
{
$arguments = array();
foreach ($this->arguments as $index => $argument) {
if (is_string($argument) && isset($parameters[$argument])) {
$arguments[] = $parameters[$argument];
} elseif ($argument instanceof Reference) {
// find parameter by class
$foundInParams = false;
foreach ($parameters as $param) {
if (is_a($param, $argument->getClass())) {
$arguments[] = $param;
$foundInParams = true;
break;
}
}
if (!$foundInParams) {
$arguments[] = $argument->getInstance($manager);
}
} else {
if (count(array_filter(array_keys($parameters), 'is_int')) > 0) {
$arguments[] = array_shift($parameters);
} else {
if ($index < $this->requiredCount) {
throw new Exception(sprintf("Key %s for method %s::%s not found!", $argument, $this->class, $this->method));
}
}
}
}
if ($this->method == '__construct') {
if (!count($arguments)) {
return new $this->class();
}
return Reflection::getReflectionClass($this->class)->newInstanceArgs($arguments);
}
if (in_array($this->method, $manager->getInspector()->getPublicMethods($this->class))) {
return call_user_func_array(array($instance, $this->method), $arguments);
}
return Reflection::getReflectionMethod($this->class, $this->method)->invokeArgs($instance, $arguments);
}
示例2: getClassInjection
/**
* @param $class
* @return array
*/
public function getClassInjection($class)
{
if ($this->getCache()->contains(__METHOD__, func_get_args())) {
return $this->getCache()->get(__METHOD__, func_get_args());
}
$injection = array();
$reflectionClass = Reflection::getReflectionClass($class);
foreach ($reflectionClass->getProperties() as $property) {
if (stristr($property->getDocComment(), '@inject') || stristr($property->getDocComment(), '@new')) {
foreach (explode("\n", $property->getDocComment()) as $line) {
if (!stristr($line, '@var')) {
continue;
}
foreach (explode(' ', substr($line, stripos($line, '@var') + 4)) as $item) {
if (strlen($item) > 0) {
$global = false;
if ($item[0] == '\\') {
$global = true;
$item = substr($item, 1);
}
$injected_class = trim(str_replace("\r", '', $item));
if (!$global) {
$aliases = array();
foreach (file($property->getDeclaringClass()->getFileName()) as $line) {
if (strpos($line, 'use ') === 0) {
$line = substr($line, 0, strpos($line, ';'));
$chain = array_filter(explode(' ', $line), 'strlen');
if (strpos($line, ' as ')) {
$destination = $chain[1];
$alias = $chain[3];
} else {
$destination = $chain[1];
list($alias) = array_reverse(explode("\\", $chain[1]));
}
$aliases[$alias] = $destination;
}
if (strpos($line, 'class ') === 0) {
break;
}
}
if (isset($aliases[$injected_class])) {
// imported with use statement
$injected_class = $aliases[$injected_class];
} elseif (!strstr($injected_class, '\\')) {
$injected_class = $reflectionClass->getNamespaceName() . '\\' . $injected_class;
} else {
list($ns) = explode('\\', $injected_class);
if (isset($aliases[$ns])) {
$injected_class = $aliases[$ns] . substr($injected_class, strlen($ns));
}
}
}
$injection[$property->getName()] = array('class' => $injected_class, 'new' => stristr($property->getDocComment(), '@new'));
break;
}
}
}
}
}
$this->getCache()->set(__METHOD__, func_get_args(), $injection);
return $injection;
}
示例3: __construct
public function __construct($model)
{
$this->_model = $model;
$reflectionClass = Reflection::getReflectionClass($model);
$properties = $reflectionClass->getStaticProperties();
foreach (self::$_VALIDATION_TYPES as $type) {
if (!empty($properties[$type])) {
foreach ($properties[$type] as $validate) {
$validate['type'] = $type;
if (empty($validate['on']) || $validate['on'] === 'save') {
array_push($this->_registeredValidates['create'], $validate);
array_push($this->_registeredValidates['update'], $validate);
continue;
}
if ($validate['on'] === 'create') {
array_push($this->_registeredValidates['create'], $validate);
continue;
}
if ($validate['on'] === 'update') {
array_push($this->_registeredValidates['update'], $validate);
continue;
}
}
}
}
}