/** * Shows the methods represented by the given security privilege target * * If the privilege target has parameters those can be specified separated by a colon * for example "parameter1:value1" "parameter2:value2". * But be aware that this only works for parameters that have been specified in the policy * * @param string $privilegeTarget The name of the privilegeTarget as stated in the policy * @return void */ public function showMethodsForPrivilegeTargetCommand($privilegeTarget) { $privilegeTargetInstance = $this->policyService->getPrivilegeTargetByIdentifier($privilegeTarget); if ($privilegeTargetInstance === null) { $this->outputLine('The privilegeTarget "%s" is not defined', array($privilegeTarget)); $this->quit(1); } $privilegeParameters = array(); foreach ($this->request->getExceedingArguments() as $argument) { list($argumentName, $argumentValue) = explode(':', $argument, 2); $privilegeParameters[$argumentName] = $argumentValue; } $privilege = $privilegeTargetInstance->createPrivilege(PrivilegeInterface::GRANT, $privilegeParameters); if (!$privilege instanceof MethodPrivilegeInterface) { $this->outputLine('The privilegeTarget "%s" does not refer to a MethodPrivilege but to a privilege of type "%s"', array($privilegeTarget, $privilege->getPrivilegeTarget()->getPrivilegeClassName())); $this->quit(1); } $matchedClassesAndMethods = array(); foreach ($this->reflectionService->getAllClassNames() as $className) { try { $reflectionClass = new \ReflectionClass($className); } catch (\ReflectionException $exception) { continue; } foreach ($reflectionClass->getMethods() as $reflectionMethod) { $methodName = $reflectionMethod->getName(); if ($privilege->matchesMethod($className, $methodName)) { $matchedClassesAndMethods[$className][$methodName] = $methodName; } } } if (count($matchedClassesAndMethods) === 0) { $this->outputLine('The given Resource did not match any method or is unknown.'); $this->quit(1); } foreach ($matchedClassesAndMethods as $className => $methods) { $this->outputLine($className); foreach ($methods as $methodName) { $this->outputLine(' ' . $methodName); } $this->outputLine(); } }
/** * @param array $classesSelector * @return array */ protected function getAffectedClassNames(array $classesSelector) { if (isset($classesSelector['parentClassName'])) { $affectedClassNames = $this->reflectionService->getAllSubClassNamesForClass($classesSelector['parentClassName']); } elseif (isset($classesSelector['interface'])) { $affectedClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface($classesSelector['interface']); } elseif (isset($classesSelector['classesContainingMethodsAnnotatedWith'])) { $affectedClassNames = $this->reflectionService->getClassesContainingMethodsAnnotatedWith($classesSelector['classesContainingMethodsAnnotatedWith']); } else { $affectedClassNames = $this->reflectionService->getAllClassNames(); } foreach ($affectedClassNames as $index => $className) { if ($this->reflectionService->isClassAbstract($className) && (!isset($classesSelector['includeAbstractClasses']) || $classesSelector['includeAbstractClasses'] === FALSE)) { unset($affectedClassNames[$index]); } elseif (isset($classesSelector['classNamePattern']) && preg_match($classesSelector['classNamePattern'], $className) === 0) { unset($affectedClassNames[$index]); } } return $affectedClassNames; }