本文整理汇总了PHP中ReflectionClass::getParentClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getParentClass方法的具体用法?PHP ReflectionClass::getParentClass怎么用?PHP ReflectionClass::getParentClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getParentClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateRoute
/**
* Add all the routes in the router in parameter
* @param $router Router
*/
public function generateRoute(Router $router)
{
foreach ($this->classes as $class) {
$classMethods = get_class_methods($this->namespace . $class . 'Controller');
$rc = new \ReflectionClass($this->namespace . $class . 'Controller');
$parent = $rc->getParentClass();
$parent = get_class_methods($parent->name);
$className = $this->namespace . $class . 'Controller';
foreach ($classMethods as $methodName) {
if (in_array($methodName, $parent) || $methodName == 'index') {
continue;
} else {
foreach (Router::getSupportedHttpMethods() as $httpMethod) {
if (strstr($methodName, $httpMethod)) {
continue 2;
}
if (in_array($methodName . $httpMethod, $classMethods)) {
$router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName . $httpMethod, $httpMethod);
unset($classMethods[$methodName . $httpMethod]);
}
}
$router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName);
}
}
$router->add('/' . strtolower($class), new $className(), 'index');
}
}
示例2: writeMethods
function writeMethods(ReflectionClass $class, $fp)
{
if ($class->getParentClass()) {
writeMethods($class->getParentClass(), $fp);
}
foreach ($class->getMethods() as $method) {
if (!$method->isPublic() || $method->getName() === '__construct' || substr($method->getName(), 0, 3) === 'set' || substr($method->getName(), 0, 3) === 'add') {
continue;
}
$return = '';
$description = '';
foreach (explode("\n", $method->getDocComment()) as $line) {
$line = ltrim(trim(trim(trim($line), '*')), '/');
if (strpos($line, '@return') === 0) {
$return = trim(substr($line, 7));
$return = preg_replace_callback('~[A-Z][a-zA-Z]+~', function ($match) {
if ($match[0] === '\\DateTime' || $match[0] === 'DateTime') {
return $match[0];
}
return '[' . $match[0] . '](#' . strtolower($match[0]) . ')';
}, $return);
$return = str_replace('|', '|', $return);
} elseif (strpos($line, '@') !== 0 && !empty($line)) {
$description = $line;
}
}
$parameters = [];
foreach ($method->getParameters() as $parameter) {
$parameters[] = $parameter->getName();
}
fwrite($fp, '| ' . $method->getName() . " | {$return} | " . implode(', ', $parameters) . " | {$description} |\n");
}
}
示例3: getParentClass
/**
* @return bool|\PHPStan\Reflection\ClassReflection
*/
public function getParentClass()
{
if ($this->reflection->getParentClass() === false) {
return false;
}
return $this->broker->getClass($this->reflection->getParentClass()->getName());
}
示例4: getContexts
/**
* Get a hierarchy of contexts for the given class as an array
*
* @param string $class
* @return array
*/
private function getContexts($class)
{
if ($class == Wires_Locator_Interface::GLOBAL_CONTEXT) {
return array($class);
}
$ref = new ReflectionClass($class);
$contexts = array($class);
// collect interfaces
if (is_array($ref->getInterfaceNames())) {
foreach ($ref->getInterfaceNames() as $interface) {
$contexts[] = $interface;
}
}
// add parent class
if ($ref->getParentClass()) {
$parent_contexts = $this->getContexts($ref->getParentClass()->getName());
foreach ($parent_contexts as $pc) {
if ($pc != Wires_Locator_Interface::GLOBAL_CONTEXT && !in_array($pc, $contexts)) {
$contexts[] = $pc;
}
}
}
$contexts[] = Wires_Locator_Interface::GLOBAL_CONTEXT;
return $contexts;
}
示例5: create_controller
public function create_controller($request)
{
$loaded = false;
foreach ($this->context->load_paths() as $path) {
if (list($controller_file, $controller_class) = $this->load_controller($request->parameter('controller'), $path)) {
$loaded = true;
break;
}
}
if ($loaded === false) {
throw new Exception('Cannot load controller `' . $request->parameter('controller') . '`, searched in `' . join(', ', $this->context->load_paths()) . '`');
}
// load ApplicationController if any.
foreach ($this->context->load_paths() as $load_path) {
if (file_exists($load_path . 'app/controllers/application.php')) {
require $load_path . 'app/controllers/application.php';
if (class_exists('ApplicationController')) {
break;
}
}
}
require $controller_file;
if (false === class_exists($controller_class)) {
throw new Exception('Expected `' . $controller_file . '` to define `' . $controller_class . '`');
}
$rclass = new ReflectionClass($controller_class);
if (false === ($rclass->getParentClass() || $rclass->getParentClass() == 'ApplicationController' || $rclass->getParentClass() == 'ActionController')) {
throw new Exception('Expected `' . $controller_class . '` to extend ApplicationController(recommended) or ActionControler');
}
// XXX: the $path
$this->context->logger()->debug(str_replace($path, '${' . $this->context->config()->application_name() . '}/', $controller_file) . ' --> ' . $controller_class);
return $rclass->newInstance($this->context);
}
示例6: load
/**
* Loads from annotations from a directory.
*
* @param string $path A directory path
* @param string $type The resource type
*
* @return EventsMap A event map
*
* @throws \InvalidArgumentException When annotations can't be parsed
*/
public function load($path, $type = null)
{
$dir = $this->locator->locate($path);
$map = new EventsMap();
$map->addResource(new DirectoryResource($dir, '/Event\\.php$/'));
$files = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY));
usort($files, function (\SplFileInfo $a, \SplFileInfo $b) {
return (string) $a > (string) $b ? 1 : -1;
});
foreach ($files as $file) {
if (!$file->isFile() || 'Event.php' !== substr($file->getFilename(), -9)) {
continue;
}
if ($class = $this->findClass($file)) {
$refl = new \ReflectionClass($class);
if ($refl->isAbstract()) {
continue;
}
if (!$refl->getParentClass() || $refl->getParentClass()->getName() != 'Symfony\\Component\\EventDispatcher\\Event') {
continue;
}
$map->merge($this->loader->load($class, $type));
}
}
return $map;
}
示例7: from
/**
* @param \ReflectionClass|string
* @return self
*/
public static function from($from)
{
$from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
$class = new static('anonymous');
} else {
$class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
}
$class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
$class->final = $from->isFinal() && $class->type === 'class';
$class->abstract = $from->isAbstract() && $class->type === 'class';
$class->implements = $from->getInterfaceNames();
$class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
if ($from->getParentClass()) {
$class->extends = $from->getParentClass()->getName();
$class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
}
foreach ($from->getProperties() as $prop) {
if ($prop->getDeclaringClass()->getName() === $from->getName()) {
$class->properties[$prop->getName()] = Property::from($prop);
}
}
foreach ($from->getMethods() as $method) {
if ($method->getDeclaringClass()->getName() === $from->getName()) {
$class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
}
}
return $class;
}
示例8: extractProperties
/**
*
* Recursive properties extraction. Returns properties of the $reflectedClass and parents.
*
* @param \ReflectionClass $reflectedClass
* @param int $filter
* @return \ReflectionProperty[]
*/
private function extractProperties(\ReflectionClass $reflectedClass, $filter)
{
$result = $reflectedClass->getProperties($filter);
if ($reflectedClass->getParentClass()) {
$result = array_merge($result, $this->extractProperties($reflectedClass->getParentClass(), $filter));
}
return $result;
}
示例9: getTraitNames
private function getTraitNames(\ReflectionClass $class) : array
{
$traitNames = $class->getTraitNames();
while ($class->getParentClass() !== false) {
$traitNames = array_values(array_unique(array_merge($traitNames, $class->getParentClass()->getTraitNames())));
$class = $class->getParentClass();
}
return $traitNames;
}
示例10: injectTestCaseHierarchy
protected function injectTestCaseHierarchy(AbstractTestCase $testCase)
{
$rc = new \ReflectionClass($testCase);
while ($rc->getParentClass()) {
$class = $rc->getParentClass()->getName();
$testCase->getDi()->instanceManager()->addSharedInstance($testCase, $class);
$rc = new \ReflectionClass($class);
}
}
示例11: getClassParents
/**
* @param \ReflectionClass $class
* @return \ReflectionClass[]
*/
public function getClassParents(\ReflectionClass $class)
{
if ($class->getParentClass()) {
$parents = $this->getClassParents($class->getParentClass());
$p = array($class->getParentClass());
return array_merge($p, $parents);
} else {
return array();
}
}
示例12: traitsUsedRecursive
protected function traitsUsedRecursive($class, $traitNames = [])
{
if (!$class instanceof ReflectionClass) {
$class = new ReflectionClass($class);
}
$traitNames = array_merge($traitNames, $class->getTraitNames());
if ($class->getParentClass() != false) {
return array_merge($traitNames, $this->traitsUsedRecursive($class->getParentClass()));
}
return $traitNames;
}
示例13: getClassProperties
/**
* Method that extract all the properties of a class
* @param string $class
* @return array
*/
public static function getClassProperties($class)
{
$properties = [];
Logger::log('Extracting annotations properties from class ' . $class);
$selfReflector = new \ReflectionClass($class);
if (false !== $selfReflector->getParentClass()) {
$properties = self::getClassProperties($selfReflector->getParentClass()->getName());
}
$properties = array_merge($properties, self::extractProperties($selfReflector));
return $properties;
}
示例14: addDependency
protected function addDependency(array &$loadPaths, \ReflectionClass $dep)
{
if ($dep->getFileName() !== false) {
$loadPaths[$dep->getName()] = $dep->getFileName();
}
if ($dep->getParentClass() instanceof \ReflectionClass) {
$this->addDependency($loadPaths, $dep->getParentClass());
}
foreach ($dep->getInterfaces() as $interface) {
$this->addDependency($loadPaths, $interface);
}
}
示例15: _getClassProperties
/**
* @param \ReflectionClass $class
*
* @return array
*/
private function _getClassProperties(\ReflectionClass $class)
{
$props = [];
if ($class->getParentClass()) {
$props = $this->_getClassProperties($class->getParentClass());
}
foreach ($class->getProperties() as $property) {
if (!in_array($property->getName(), $props)) {
$props[] = $property->getName();
}
}
return $props;
}