getObjectNameByClassName() публичный Метод

Returns the object name corresponding to a given class name.
public getObjectNameByClassName ( string $className ) : string
$className string The class name
Результат string The object name corresponding to the given class name
 /**
  * @test
  */
 public function ifCommandCantBeResolvedTheHelpScreenIsShown()
 {
     // The following call is only made to satisfy PHPUnit. For some weird reason PHPUnit complains that the
     // mocked method ("getObjectNameByClassName") does not exist _if the mock object is not used_.
     $this->mockObjectManager->getObjectNameByClassName('Acme\\Test\\Command\\DefaultCommandController');
     $this->mockCommandManager->getCommandByIdentifier('acme.test:default:list');
     $mockCommandManager = $this->createMock(Cli\CommandManager::class);
     $mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('test:default:list')->will($this->throwException(new NoSuchCommandException()));
     $this->requestBuilder->injectCommandManager($mockCommandManager);
     $request = $this->requestBuilder->build('test:default:list');
     $this->assertSame(HelpCommandController::class, $request->getControllerObjectName());
 }
Пример #2
0
 /**
  * Resumes an existing session, if any.
  *
  * @return integer If a session was resumed, the inactivity of since the last request is returned
  * @api
  */
 public function resume()
 {
     if ($this->started === false && $this->canBeResumed()) {
         $this->sessionIdentifier = $this->sessionCookie->getValue();
         $this->response->setCookie($this->sessionCookie);
         $this->started = true;
         $sessionObjects = $this->storageCache->get($this->storageIdentifier . md5('TYPO3_Flow_Object_ObjectManager'));
         if (is_array($sessionObjects)) {
             foreach ($sessionObjects as $object) {
                 if ($object instanceof ProxyInterface) {
                     $objectName = $this->objectManager->getObjectNameByClassName(get_class($object));
                     if ($this->objectManager->getScope($objectName) === ObjectConfiguration::SCOPE_SESSION) {
                         $this->objectManager->setInstance($objectName, $object);
                         $this->objectManager->get(Aspect\LazyLoadingAspect::class)->registerSessionInstance($objectName, $object);
                     }
                 }
             }
         } else {
             // Fallback for some malformed session data, if it is no array but something else.
             // In this case, we reset all session objects (graceful degradation).
             $this->storageCache->set($this->storageIdentifier . md5('TYPO3_Flow_Object_ObjectManager'), [], [$this->storageIdentifier], 0);
         }
         $lastActivitySecondsAgo = $this->now - $this->lastActivityTimestamp;
         $this->lastActivityTimestamp = $this->now;
         return $lastActivitySecondsAgo;
     }
 }
 /**
  * Checks if the specified class and method matches against the filter
  *
  * @param string $className Name of the class to check against
  * @param string $methodName Name of the method to check against
  * @param string $methodDeclaringClassName Name of the class the method was originally declared in
  * @param mixed $pointcutQueryIdentifier Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection.
  * @return boolean TRUE if the class / method match, otherwise FALSE
  */
 public function matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier)
 {
     if ($methodName === null) {
         return false;
     }
     $objectName = $this->objectManager->getObjectNameByClassName($className);
     if (empty($objectName)) {
         return false;
     }
     if ($this->objectManager->getScope($objectName) !== ObjectConfiguration::SCOPE_SESSION) {
         return false;
     }
     if (preg_match('/^__wakeup|__construct|__destruct|__sleep|__serialize|__unserialize|__clone|shutdownObject|initializeObject|inject.*$/', $methodName) !== 0) {
         return false;
     }
     return true;
 }
 /**
  * Around advice, wrapping every method of a scope session object. It redirects
  * all method calls to the session object once there is one.
  *
  * @param JoinPointInterface $joinPoint The current join point
  * @return mixed
  * @Flow\Around("filter(Neos\Flow\Session\Aspect\SessionObjectMethodsPointcutFilter)")
  */
 public function callMethodOnOriginalSessionObject(JoinPointInterface $joinPoint)
 {
     $objectName = $this->objectManager->getObjectNameByClassName(get_class($joinPoint->getProxy()));
     $methodName = $joinPoint->getMethodName();
     $proxy = $joinPoint->getProxy();
     if (!isset($this->sessionOriginalInstances[$objectName])) {
         $this->sessionOriginalInstances[$objectName] = $this->objectManager->get($objectName);
     }
     if ($this->sessionOriginalInstances[$objectName] === $proxy) {
         return $joinPoint->getAdviceChain()->proceed($joinPoint);
     } else {
         return call_user_func_array([$this->sessionOriginalInstances[$objectName], $methodName], $joinPoint->getMethodArguments());
     }
 }
 /**
  * Builds a CLI request object from a command line.
  *
  * The given command line may be a string (e.g. "mypackage:foo do-that-thing --force") or
  * an array consisting of the individual parts. The array must not include the script
  * name (like in $argv) but start with command right away.
  *
  * @param mixed $commandLine The command line, either as a string or as an array
  * @return Request The CLI request as an object
  * @throws InvalidArgumentMixingException
  * @throws InvalidArgumentNameException
  */
 public function build($commandLine)
 {
     $request = new Request();
     $request->setControllerObjectName(HelpCommandController::class);
     if (is_array($commandLine) === true) {
         $rawCommandLineArguments = $commandLine;
     } else {
         preg_match_all(self::ARGUMENT_MATCHING_EXPRESSION, $commandLine, $commandLineMatchings, PREG_SET_ORDER);
         $rawCommandLineArguments = [];
         foreach ($commandLineMatchings as $match) {
             if (isset($match['NoQuotes'])) {
                 $rawCommandLineArguments[] = str_replace(['\\ ', '\\"', "\\'", '\\\\'], [' ', '"', "'", '\\'], $match['NoQuotes']);
             } elseif (isset($match['DoubleQuotes'])) {
                 $rawCommandLineArguments[] = str_replace('\\"', '"', $match['DoubleQuotes']);
             } elseif (isset($match['SingleQuotes'])) {
                 $rawCommandLineArguments[] = str_replace('\\\'', '\'', $match['SingleQuotes']);
             } else {
                 throw new InvalidArgumentNameException(sprintf('Could not parse the command line "%s" - specifically the part "%s".', $commandLine, $match[0]));
             }
         }
     }
     if (count($rawCommandLineArguments) === 0) {
         $request->setControllerCommandName('helpStub');
         return $request;
     }
     $commandIdentifier = trim(array_shift($rawCommandLineArguments));
     try {
         $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
     } catch (CommandException $exception) {
         $request->setArgument('exception', $exception);
         $request->setControllerCommandName('error');
         return $request;
     }
     $controllerObjectName = $this->objectManager->getObjectNameByClassName($command->getControllerClassName());
     $controllerCommandName = $command->getControllerCommandName();
     $request->setControllerObjectName($controllerObjectName);
     $request->setControllerCommandName($controllerCommandName);
     list($commandLineArguments, $exceedingCommandLineArguments) = $this->parseRawCommandLineArguments($rawCommandLineArguments, $controllerObjectName, $controllerCommandName);
     $request->setArguments($commandLineArguments);
     $request->setExceedingArguments($exceedingCommandLineArguments);
     return $request;
 }
 /**
  * @param ObjectManagerInterface $objectManager
  * @return array Array of method arguments per controller and method.
  * @Flow\CompileStatic
  */
 public static function getCommandControllerMethodArguments($objectManager)
 {
     /** @var ReflectionService $reflectionService */
     $reflectionService = $objectManager->get(ReflectionService::class);
     $commandControllerMethodArgumentMap = [];
     foreach ($reflectionService->getAllSubClassNamesForClass(CommandController::class) as $className) {
         if (!class_exists($className) || $reflectionService->isClassAbstract($className)) {
             continue;
         }
         $controllerObjectName = $objectManager->getObjectNameByClassName($className);
         $commandControllerMethodArgumentMap[$controllerObjectName] = [];
         foreach (get_class_methods($className) as $methodName) {
             if (substr($methodName, -7, 7) === 'Command') {
                 $commandControllerMethodArgumentMap[$className][$methodName] = $reflectionService->getMethodParameters($controllerObjectName, $methodName);
             }
         }
     }
     return $commandControllerMethodArgumentMap;
 }
Пример #7
0
 /**
  * Renders a dump of the given object
  *
  * @param object $object
  * @param integer $level
  * @param boolean $renderProperties
  * @param boolean $plaintext
  * @param boolean $ansiColors
  * @return string
  */
 protected static function renderObjectDump($object, $level, $renderProperties = true, $plaintext = false, $ansiColors = false)
 {
     $dump = '';
     $scope = '';
     $additionalAttributes = '';
     if ($object instanceof \Doctrine\Common\Collections\Collection || $object instanceof \ArrayObject) {
         return self::renderArrayDump(\Doctrine\Common\Util\Debug::export($object, 3), $level, $plaintext, $ansiColors);
     }
     // Objects returned from Doctrine's Debug::export function are stdClass with special properties:
     try {
         $objectIdentifier = ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', true);
     } catch (\Neos\Utility\Exception\PropertyNotAccessibleException $exception) {
         $objectIdentifier = spl_object_hash($object);
     }
     $className = $object instanceof \stdClass && isset($object->__CLASS__) ? $object->__CLASS__ : get_class($object);
     if (isset(self::$renderedObjects[$objectIdentifier]) || preg_match(self::getIgnoredClassesRegex(), $className) !== 0) {
         $renderProperties = false;
     }
     self::$renderedObjects[$objectIdentifier] = true;
     if (self::$objectManager !== null) {
         $objectName = self::$objectManager->getObjectNameByClassName(get_class($object));
         if ($objectName !== false) {
             switch (self::$objectManager->getScope($objectName)) {
                 case Configuration::SCOPE_PROTOTYPE:
                     $scope = 'prototype';
                     break;
                 case Configuration::SCOPE_SINGLETON:
                     $scope = 'singleton';
                     break;
                 case Configuration::SCOPE_SESSION:
                     $scope = 'session';
                     break;
             }
         } else {
             $additionalAttributes .= ' debug-unregistered';
         }
     }
     if ($renderProperties === true && !$plaintext) {
         if ($scope === '') {
             $scope = 'prototype';
         }
         $scope .= '<a id="o' . $objectIdentifier . '"></a>';
     }
     if ($plaintext) {
         $dump .= $className;
         $dump .= $scope !== '' ? ' ' . self::ansiEscapeWrap($scope, '44;37', $ansiColors) : '';
     } else {
         $dump .= '<span class="debug-object' . $additionalAttributes . '" title="' . $objectIdentifier . '">' . $className . '</span>';
         $dump .= $scope !== '' ? '<span class="debug-scope">' . $scope . '</span>' : '';
     }
     if (property_exists($object, 'Persistence_Object_Identifier')) {
         $persistenceIdentifier = $objectIdentifier;
         $persistenceType = 'persistable';
     } elseif ($object instanceof \Closure) {
         $persistenceIdentifier = 'n/a';
         $persistenceType = 'closure';
     } else {
         $persistenceIdentifier = 'unknown';
         $persistenceType = 'object';
     }
     if ($plaintext) {
         $dump .= ' ' . self::ansiEscapeWrap($persistenceType, '42;37', $ansiColors);
     } else {
         $dump .= '<span class="debug-ptype" title="' . $persistenceIdentifier . '">' . $persistenceType . '</span>';
     }
     if ($object instanceof ProxyInterface || property_exists($object, '__IS_PROXY__') && $object->__IS_PROXY__ === true) {
         if ($plaintext) {
             $dump .= ' ' . self::ansiEscapeWrap('proxy', '41;37', $ansiColors);
         } else {
             $dump .= '<span class="debug-proxy" title="' . $className . '">proxy</span>';
         }
     }
     if ($renderProperties === true) {
         if ($object instanceof \SplObjectStorage) {
             $dump .= ' (' . (count($object) ?: 'empty') . ')';
             foreach ($object as $value) {
                 $dump .= chr(10);
                 $dump .= str_repeat(' ', $level);
                 $dump .= self::renderObjectDump($value, 0, false, $plaintext, $ansiColors);
             }
         } else {
             $objectReflection = new \ReflectionObject($object);
             $properties = $objectReflection->getProperties();
             foreach ($properties as $property) {
                 if (preg_match(self::$blacklistedPropertyNames, $property->getName())) {
                     continue;
                 }
                 $dump .= chr(10);
                 $dump .= str_repeat(' ', $level) . ($plaintext ? '' : '<span class="debug-property">') . self::ansiEscapeWrap($property->getName(), '36', $ansiColors) . ($plaintext ? '' : '</span>') . ' => ';
                 $property->setAccessible(true);
                 $value = $property->getValue($object);
                 if (is_array($value)) {
                     $dump .= self::renderDump($value, $level + 1, $plaintext, $ansiColors);
                 } elseif (is_object($value)) {
                     $dump .= self::renderObjectDump($value, $level + 1, true, $plaintext, $ansiColors);
                 } else {
                     $dump .= self::renderDump($value, $level, $plaintext, $ansiColors);
                 }
             }
         }
     } elseif (isset(self::$renderedObjects[$objectIdentifier])) {
         if (!$plaintext) {
             $dump = '<a href="#o' . $objectIdentifier . '" onclick="document.location.hash=\'#o' . $objectIdentifier . '\'; return false;" class="debug-seeabove" title="see above">' . $dump . '</a>';
         }
     }
     return $dump;
 }
 /**
  * Detects plugins for this command controller
  *
  * @param ObjectManagerInterface $objectManager
  * @return array
  */
 protected static function detectPlugins(ObjectManagerInterface $objectManager)
 {
     $pluginConfigurations = array();
     $classNames = $objectManager->get(ReflectionService::class)->getAllImplementationClassNamesForInterface(NodeCommandControllerPluginInterface::class);
     foreach ($classNames as $className) {
         $pluginConfigurations[$className] = array('object' => $objectManager->get($objectManager->getObjectNameByClassName($className)));
     }
     return $pluginConfigurations;
 }
 /**
  * Serializes an object as property array.
  *
  * @param object $object The object to store in the registry
  * @param boolean $isTopLevelItem Internal flag for managing the recursion
  * @return array The property array
  */
 public function serializeObjectAsPropertyArray($object, $isTopLevelItem = true)
 {
     if ($isTopLevelItem) {
         $this->objectReferences = new \SplObjectStorage();
     }
     $this->objectReferences->attach($object);
     $className = get_class($object);
     $propertyArray = [];
     foreach ($this->reflectionService->getClassPropertyNames($className) as $propertyName) {
         if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'transient')) {
             continue;
         }
         $propertyReflection = new PropertyReflection($className, $propertyName);
         $propertyValue = $propertyReflection->getValue($object);
         if (is_object($propertyValue) && $propertyValue instanceof DependencyInjection\DependencyProxy) {
             continue;
         }
         if (is_object($propertyValue) && isset($this->objectReferences[$propertyValue])) {
             $propertyArray[$propertyName][self::TYPE] = 'object';
             $propertyArray[$propertyName][self::VALUE] = \spl_object_hash($propertyValue);
             continue;
         }
         $propertyClassName = is_object($propertyValue) ? get_class($propertyValue) : '';
         if ($propertyClassName === 'SplObjectStorage') {
             $propertyArray[$propertyName][self::TYPE] = 'SplObjectStorage';
             $propertyArray[$propertyName][self::VALUE] = [];
             foreach ($propertyValue as $storedObject) {
                 $propertyArray[$propertyName][self::VALUE][] = spl_object_hash($storedObject);
                 $this->serializeObjectAsPropertyArray($storedObject, false);
             }
         } elseif (is_object($propertyValue) && $propertyValue instanceof \Doctrine\Common\Collections\Collection) {
             $propertyArray[$propertyName][self::TYPE] = 'Collection';
             $propertyArray[$propertyName][self::CLASSNAME] = get_class($propertyValue);
             foreach ($propertyValue as $storedObject) {
                 $propertyArray[$propertyName][self::VALUE][] = spl_object_hash($storedObject);
                 $this->serializeObjectAsPropertyArray($storedObject, false);
             }
         } elseif (is_object($propertyValue) && $propertyValue instanceof \ArrayObject) {
             $propertyArray[$propertyName][self::TYPE] = 'ArrayObject';
             $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue->getArrayCopy());
         } elseif (is_object($propertyValue) && $this->persistenceManager->isNewObject($propertyValue) === false && ($this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\Entity::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\ValueObject::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, ORM\Entity::class))) {
             $propertyArray[$propertyName][self::TYPE] = 'persistenceObject';
             $propertyArray[$propertyName][self::VALUE] = get_class($propertyValue) . ':' . $this->persistenceManager->getIdentifierByObject($propertyValue);
         } elseif (is_object($propertyValue)) {
             $propertyObjectName = $this->objectManager->getObjectNameByClassName($propertyClassName);
             if ($this->objectManager->getScope($propertyObjectName) === Configuration::SCOPE_SINGLETON) {
                 continue;
             }
             $propertyArray[$propertyName][self::TYPE] = 'object';
             $propertyArray[$propertyName][self::VALUE] = spl_object_hash($propertyValue);
             $this->serializeObjectAsPropertyArray($propertyValue, false);
         } elseif (is_array($propertyValue)) {
             $propertyArray[$propertyName][self::TYPE] = 'array';
             $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue);
         } else {
             $propertyArray[$propertyName][self::TYPE] = 'simple';
             $propertyArray[$propertyName][self::VALUE] = $propertyValue;
         }
     }
     $this->objectsAsArray[spl_object_hash($object)] = [self::CLASSNAME => $className, self::PROPERTIES => $propertyArray];
     if ($isTopLevelItem) {
         return $this->objectsAsArray;
     }
 }