/** * Convert raw property values to the correct type according to a node type configuration * * @param NodeType $nodeType * @param string $propertyName * @param string $rawValue * @param Context $context * @return mixed */ public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context) { $propertyType = $nodeType->getPropertyType($propertyName); switch ($propertyType) { case 'string': return $rawValue; case 'reference': return $this->convertReference($rawValue, $context); case 'references': return $this->convertReferences($rawValue, $context); case 'DateTime': return $this->convertDateTime($rawValue); case 'integer': return $this->convertInteger($rawValue); case 'boolean': return $this->convertBoolean($rawValue); case 'array': return $this->convertArray($rawValue); default: $innerType = $propertyType; if ($propertyType !== null) { try { $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($propertyType); $innerType = $parsedType['elementType'] ?: $parsedType['type']; } catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) { } } if (is_string($rawValue) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') { return $this->propertyMapper->convert(json_decode($rawValue, true), $propertyType, $configuration); } } }
/** * @param Message $message * @return void */ public function queue(Message $message) { /** @var EventHandlerInterface $handler */ $handler = $this->objectManager->get($message->getRecipient()); $event = $this->arraySerializer->unserialize($message->getPayload()); $handler->handle($event); }
/** * Mocks an entity as wished * * @param string $fqcn the fully qualified class name * @param boolean $persist if the entity should be directly persisted or not * @param array $customProperties the properties to set if wished * @return Object */ public function create($fqcn, $persist = false, $customProperties = array()) { $entityConfiguration = $this->entityConfiguration[$fqcn]; $this->validateEntityConfiguration($fqcn, $entityConfiguration); // create from reflection class if constructor needs arguments if (!empty($entityConfiguration['constructorArguments'])) { $reflector = new \ReflectionClass($fqcn); $constructorArguments = $this->getValuesFromConfigurations($entityConfiguration['constructorArguments']); $entity = $reflector->newInstanceArgs($constructorArguments); } else { $entity = new $fqcn(); } // set the properties $configuredProperties = $entityConfiguration['properties'] ?: array(); $properties = array_merge($configuredProperties, $customProperties); foreach ($this->getValuesFromConfigurations($properties, $persist) as $propertyName => $propertyValue) { $propertyCouldBeSet = ObjectAccess::setProperty($entity, $propertyName, $propertyValue); if (!$propertyCouldBeSet) { throw new \Exception($fqcn . '::$' . $propertyName . ' could not be set to ' . print_r($propertyValue, true), 1416481470); } } // persist if wished if ($persist && is_string($entityConfiguration['repository'])) { $this->objectManager->get($entityConfiguration['repository'])->add($entity); // flush this entity here... $this->entityManager->flush($entity); // add to managed entities $identifier = $this->persistenceManager->getIdentifierByObject($entity); $this->managedEntities[$identifier] = $entity; } return $entity; }
/** * Returns the HTML needed to include ExtJS, that is, CSS and JS includes. * * = Examples = * * <code title="Simple"> * {namespace ext=TYPO3\ExtJS\ViewHelpers} * ... * <ext:include/> * </code> * Renders the script and link tags needed to include everything needed to * use ExtJS. * * <code title="Use a specific theme"> * <ext:include theme="xtheme-gray"/> * </code> * * @param string $theme The theme to include, simply the name of the CSS * @param boolean $debug Whether to use the debug version of ExtJS * @param boolean $includeStylesheets Include ExtJS CSS files if true * @return string HTML needed to include ExtJS * @api */ public function render($theme = 'xtheme-blue', $debug = NULL, $includeStylesheets = TRUE) { if ($debug === NULL) { $debug = $this->objectManager->getContext()->isDevelopment() ?: FALSE; } $baseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/TYPO3.ExtJS/'; $output = ''; if ($includeStylesheets) { $output .= ' <link rel="stylesheet" href="' . $baseUri . 'CSS/ext-all-notheme.css" /> <link rel="stylesheet" href="' . $baseUri . 'CSS/' . $theme . '.css" />'; } if ($debug) { $output .= ' <script type="text/javascript" src="' . $baseUri . 'JavaScript/adapter/ext/ext-base-debug.js"></script> <script type="text/javascript" src="' . $baseUri . 'JavaScript/ext-all-debug.js"></script>'; } else { $output .= ' <script type="text/javascript" src="' . $baseUri . 'JavaScript/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="' . $baseUri . 'JavaScript/ext-all.js"></script>'; } $output .= ' <script type="text/javascript"> Ext.BLANK_IMAGE_URL = \'' . $baseUri . 'images/default/s.gif\'; Ext.FlashComponent.EXPRESS_INSTALL_URL = \'' . $baseUri . 'Flash/expressinstall.swf\'; Ext.chart.Chart.CHART_URL = \'' . $baseUri . 'Flash/chart.swf\'; </script> '; return $output; }
/** * @param array $chainConfiguration * @return ComponentChain * @throws Exception */ public function create(array $chainConfiguration) { if (empty($chainConfiguration)) { return null; } $arraySorter = new PositionalArraySorter($chainConfiguration); $sortedChainConfiguration = $arraySorter->toArray(); $chainComponents = array(); foreach ($sortedChainConfiguration as $componentName => $configuration) { $componentOptions = isset($configuration['componentOptions']) ? $configuration['componentOptions'] : array(); if (isset($configuration['chain'])) { $component = $this->create($configuration['chain']); } else { if (!isset($configuration['component'])) { throw new Exception(sprintf('Component chain could not be created because no component class name is configured for component "%s"', $componentName), 1401718283); } $component = $this->objectManager->get($configuration['component'], $componentOptions); if (!$component instanceof ComponentInterface) { throw new Exception(sprintf('Component chain could not be created because the class "%s" does not implement the ComponentInterface, in component "%s" does not implement', $configuration['component'], $componentName), 1401718283); } } $chainComponents[] = $component; } return new ComponentChain(array('components' => $chainComponents)); }
/** * Initializes the context * * @param array $parameters Context parameters (configured through behat.yml) */ public function __construct(array $parameters) { $this->useContext('flow', new \Flowpack\Behat\Tests\Behat\FlowContext($parameters)); $this->objectManager = $this->getSubcontext('flow')->getObjectManager(); $this->environment = $this->objectManager->get('TYPO3\\Flow\\Utility\\Environment'); $this->nodeAuthorizationService = $this->objectManager->get('TYPO3\\TYPO3CR\\Service\\AuthorizationService'); }
/** * Sets the pattern (match) configuration * * @param object $patternConfiguration The pattern (match) configuration * @return void */ public function setPattern($patternConfiguration) { $this->patternConfiguration = $patternConfiguration; if (isset($patternConfiguration['resolverType'])) { $this->publicKeyResolver = $this->objectManager->get($patternConfiguration['resolverType']); } }
/** * @param NodeType $nodeType * @return NodeGeneratorImplementationInterface * @throws \TYPO3\Flow\Exception */ protected function getNodeGeneratorImplementationClassByNodeType(NodeType $nodeType) { if (!isset($this->generators[(string) $nodeType]['class'])) { throw new Exception(sprintf('Unknown generator for the current Node Type (%s)', (string) $nodeType, 1391771111)); } return $this->objectManager->get($this->generators[(string) $nodeType]['class']); }
/** * Sets up this test case * */ protected function setUp() { $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('isRegistered')->will($this->returnCallback(array($this, 'objectManagerIsRegisteredCallback'))); $this->parser = $this->getAccessibleMock(Parser::class, array('dummy')); $this->parser->_set('objectManager', $this->mockObjectManager); }
/** * Set the routes configuration for the Neos setup and configures the routing component * to skip initialisation, which would overwrite the specific settings again. * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $configurationSource = $this->objectManager->get('TYPO3\\Flow\\Configuration\\Source\\YamlSource'); $routesConfiguration = $configurationSource->load($this->packageManager->getPackage('TYPO3.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router->setRoutesConfiguration($routesConfiguration); $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization', TRUE); }
/** * Adds all validators that extend the AssetValidatorInterface. * * @return void */ protected function initializeObject() { $assetValidatorImplementationClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface(AssetValidatorInterface::class); foreach ($assetValidatorImplementationClassNames as $assetValidatorImplementationClassName) { $this->addValidator($this->objectManager->get($assetValidatorImplementationClassName)); } }
/** * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface|null $configuration * @return mixed|\Netlogix\JsonApiOrg\Schema\ResourceInterface|\TYPO3\Flow\Error\Error */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { if (is_string($source)) { $sourceArray = json_decode($source, true); $source = is_array($sourceArray) ? $sourceArray : ['id' => $source]; } if (!array_key_exists('type', $source)) { $dummyPayload = $this->objectManager->get($targetType); $typeIdentifier = $dummyPayload->getType(); $source['type'] = $this->exposableTypeMap->getType($typeIdentifier); } if (array_key_exists('id', $source)) { $arguments = $source['id']; } else { $arguments = []; } $payload = $this->propertyMapper->convert($arguments, $this->exposableTypeMap->getClassName($source['type'])); $resourceInformation = $this->resourceMapper->findResourceInformation($payload); $resource = $resourceInformation->getResource($payload); if (isset($source['attributes'])) { $attributes = $resource->getAttributes(); foreach ($source['attributes'] as $fieldName => $value) { $attributes[$fieldName] = $value; } } if (isset($source['relationships'])) { $relationships = $resource->getRelationships(); foreach ($source['relationships'] as $fieldName => $value) { $relationships[$fieldName] = $value; } } return $resource; }
/** * Sets up this test case * */ protected function setUp() { $this->mockObjectManager = $this->createMock('TYPO3\\Flow\\Object\\ObjectManagerInterface'); $this->mockObjectManager->expects($this->any())->method('isRegistered')->will($this->returnCallback(array($this, 'objectManagerIsRegisteredCallback'))); $this->parser = $this->getAccessibleMock('TYPO3\\TypoScript\\Core\\Parser', array('dummy')); $this->parser->_set('objectManager', $this->mockObjectManager); }
/** * Adds all validators that extend the AssetValidatorInterface. * * @return void */ protected function initializeObject() { $assetValidatorImplementationClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface('TYPO3\\Media\\Domain\\Validator\\AssetValidatorInterface'); foreach ($assetValidatorImplementationClassNames as $assetValidatorImplementationClassName) { $this->addValidator($this->objectManager->get($assetValidatorImplementationClassName)); } }
/** * Initializes the context * * @param array $parameters Context parameters (configured through behat.yml) */ public function __construct(array $parameters) { $this->useContext('flow', new \Flowpack\Behat\Tests\Behat\FlowContext($parameters)); $this->flowContext = $this->getSubcontext('flow'); $this->objectManager = $this->flowContext->getObjectManager(); $this->accountRepository = $this->objectManager->get('TYPO3\\Flow\\Security\\AccountRepository'); }
/** * Sets up this test case * * @author Robert Lemke <*****@*****.**> */ protected function setUp() { $this->mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface', array(), array(), '', false); $this->mockObjectManager->expects($this->any())->method('isRegistered')->will($this->returnCallback(array($this, 'objectManagerIsRegisteredCallback'))); $parserClassName = $this->buildAccessibleProxy('TYPO3\\TypoScript\\Core\\Parser'); $this->parser = new $parserClassName(); $this->parser->_set('objectManager', $this->mockObjectManager); }
/** * @param string $providerName The provider name as given in Settings.yaml * @throws \InvalidArgumentException * @return TokenEndpointInterface */ public function getTokenEndpointForProvider($providerName) { $tokenEndpointClassName = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, sprintf('TYPO3.Flow.security.authentication.providers.%s.providerOptions.tokenEndpointClassName', $providerName)); if ($tokenEndpointClassName === NULL) { throw new \InvalidArgumentException(sprintf('In Settings.yaml, there was no "tokenEndpointClassName" option given for the provider "%s".', $providerName), 1383743372); } return $this->objectManager->get($tokenEndpointClassName); }
/** * @return void */ public function initializeObject() { // flush routing caches if in Development context & routing settings changed if ($this->objectManager->getContext()->isDevelopment() && $this->routeCache->get('routingSettings') !== $this->routingSettings) { $this->flushCaches(); $this->routeCache->set('routingSettings', $this->routingSettings); } }
/** * Returns a map of all available jobs configuration * * @param ObjectManagerInterface $objectManager * @return array Array of available jobs configuration * @Flow\CompileStatic */ public static function getAvailableJobConfigurations($objectManager) { $reflectionService = $objectManager->get('TYPO3\\Flow\\Reflection\\ReflectionService'); $result = []; foreach ($reflectionService->getAllImplementationClassNamesForInterface(self::JOB_CONFIGURATION_INTERFACE) as $implementation) { $result[$implementation] = ['implementation' => $implementation]; } return $result; }
/** * TODO: Document this Method! */ public function preToolbarRendering() { $dispatcher = $this->objectManager->get('TYPO3\\Flow\\SignalSlot\\Dispatcher'); if (method_exists($dispatcher, 'getSignals')) { $classes = $this->objectManager->get('TYPO3\\Flow\\SignalSlot\\Dispatcher')->getSignals(); $classes = $this->sanitize($classes); \Debug\Toolbar\Service\Collector::getModule('Signals')->getToolbar()->addText('Signals')->addBadge(count($classes))->getPopup()->addPartial('Signals', array('classes' => $classes))->getPanel()->addPartial('Signals', array('classes' => $classes)); } }
/** * This object is created very early and is part of the blacklisted "TYPO3\Flow\Aop" namespace so we can't rely on AOP for the property injection. * * @param ObjectManagerInterface $objectManager * @return void */ public function injectObjectManager(ObjectManagerInterface $objectManager) { if ($this->objectManager === null) { $this->objectManager = $objectManager; /** @var CacheManager $cacheManager */ $cacheManager = $this->objectManager->get(\TYPO3\Flow\Cache\CacheManager::class); $this->runtimeExpressionsCache = $cacheManager->getCache('Flow_Aop_RuntimeExpressions'); $this->runtimeExpressions = $this->runtimeExpressionsCache->requireOnce('Flow_Aop_RuntimeExpressions'); } }
/** * Prepare test objects */ protected function setUp() { $this->nodeFactory = $this->getMockBuilder(NodeFactory::class)->setMethods(array('filterNodeByContext'))->getMock(); $this->nodeFactory->expects(self::any())->method('filterNodeByContext')->willReturnArgument(0); $this->reflectionServiceMock = $this->createMock(ReflectionService::class); $this->reflectionServiceMock->expects(self::any())->method('getAllImplementationClassNamesForInterface')->with(NodeInterface::class)->willReturn(array(Node::class)); $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class); $this->objectManagerMock->expects(self::any())->method('get')->with(ReflectionService::class)->willReturn($this->reflectionServiceMock); $this->objectManagerMock->expects(self::any())->method('getClassNameByObjectName')->with(NodeInterface::class)->willReturn(Node::class); $this->inject($this->nodeFactory, 'objectManager', $this->objectManagerMock); }
/** * @param string $annotatedTransformer Either a full qualified class name or a shortened one which is seeked in the current package. * * @throws \Flowpack\ElasticSearch\Exception * @return \Flowpack\ElasticSearch\Indexer\Object\Transform\TransformerInterface */ public function create($annotatedTransformer) { if (!class_exists($annotatedTransformer)) { $annotatedTransformer = 'Flowpack\\ElasticSearch\\Indexer\\Object\\Transform\\' . $annotatedTransformer . 'Transformer'; } $transformer = $this->objectManager->get($annotatedTransformer); if (!$transformer instanceof \Flowpack\ElasticSearch\Indexer\Object\Transform\TransformerInterface) { throw new \Flowpack\ElasticSearch\Exception(sprintf('The transformer instance "%s" does not implement the TransformerInterface.', $annotatedTransformer), 1339598316); } return $transformer; }
/** * Prepare test objects */ protected function setUp() { $this->nodeFactory = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Factory\\NodeFactory', array('filterNodeByContext')); $this->nodeFactory->expects(self::any())->method('filterNodeByContext')->willReturnArgument(0); $this->reflectionServiceMock = $this->getMock('TYPO3\\Flow\\Reflection\\ReflectionService'); $this->reflectionServiceMock->expects(self::any())->method('getAllImplementationClassNamesForInterface')->with('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface')->willReturn(array('TYPO3\\TYPO3CR\\Domain\\Model\\Node')); $this->objectManagerMock = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface'); $this->objectManagerMock->expects(self::any())->method('get')->with('TYPO3\\Flow\\Reflection\\ReflectionService')->willReturn($this->reflectionServiceMock); $this->objectManagerMock->expects(self::any())->method('getClassNameByObjectName')->with('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface')->willReturn('TYPO3\\TYPO3CR\\Domain\\Model\\Node'); $this->inject($this->nodeFactory, 'objectManager', $this->objectManagerMock); }
/** * Sets the pattern (match) configuration * * @param object $pattern The pattern (match) configuration * @return void */ public function setPattern($patternValue) { $this->patternValue = $patternValue; if (isset($patternValue['patterns'])) { foreach ($patternValue['patterns'] as $patternConfiguration) { $requestPattern = $this->objectManager->get($this->requestPatternResolver->resolveRequestPatternClass($patternConfiguration['patternType'])); $requestPattern->setPattern($patternConfiguration['patternValue']); $this->subPatterns[] = $requestPattern; } } }
/** * @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->getMock(\TYPO3\Flow\Cli\CommandManager::class); $mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('test:default:list')->will($this->throwException(new \TYPO3\Flow\Mvc\Exception\NoSuchCommandException())); $this->requestBuilder->injectCommandManager($mockCommandManager); $request = $this->requestBuilder->build('test:default:list'); $this->assertSame(\TYPO3\Flow\Command\HelpCommandController::class, $request->getControllerObjectName()); }
/** * Resolves the class name of an authentication provider. If a valid provider class name is given, it is just returned. * * @param string $providerName The (short) name of the provider * @return string The object name of the authentication provider * @throws \TYPO3\Flow\Security\Exception\NoAuthenticationProviderFoundException */ public function resolveProviderClass($providerName) { $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName($providerName); if ($resolvedObjectName !== false) { return $resolvedObjectName; } $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName('TYPO3\\Flow\\Security\\Authentication\\Provider\\' . $providerName); if ($resolvedObjectName !== false) { return $resolvedObjectName; } throw new \TYPO3\Flow\Security\Exception\NoAuthenticationProviderFoundException('An authentication provider with the name "' . $providerName . '" could not be resolved.', 1217154134); }
/** * Create an action request from stored route match values and dispatch to that * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $httpRequest = $componentContext->getHttpRequest(); /** @var $actionRequest ActionRequest */ $actionRequest = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest); $this->securityContext->setRequest($actionRequest); $routingMatchResults = $componentContext->getParameter(\TYPO3\Flow\Mvc\Routing\RoutingComponent::class, 'matchResults'); $actionRequest->setArguments($this->mergeArguments($httpRequest, $routingMatchResults)); $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest); $componentContext->setParameter(\TYPO3\Flow\Mvc\DispatchComponent::class, 'actionRequest', $actionRequest); $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse()); }
/** * Resolves the class name of a security interceptor. If a valid interceptor class name is given, it is just returned. * * @param string $name The (short) name of the interceptor * @return string The class name of the security interceptor, NULL if no class was found. * @throws \TYPO3\Flow\Security\Exception\NoInterceptorFoundException */ public function resolveInterceptorClass($name) { $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName($name); if ($resolvedObjectName !== false) { return $resolvedObjectName; } $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName('TYPO3\\Flow\\Security\\Authorization\\Interceptor\\' . $name); if ($resolvedObjectName !== false) { return $resolvedObjectName; } throw new \TYPO3\Flow\Security\Exception\NoInterceptorFoundException('A security interceptor with the name: "' . $name . '" could not be resolved.', 1217154134); }
/** * Resolves the class name of a request pattern. If a valid request pattern class name is given, it is just returned. * * @param string $name The (short) name of the pattern * @return string The class name of the request pattern, NULL if no class was found. * @throws \TYPO3\Flow\Security\Exception\NoRequestPatternFoundException */ public function resolveRequestPatternClass($name) { $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName($name); if ($resolvedObjectName !== FALSE) { return $resolvedObjectName; } $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName('TYPO3\\Flow\\Security\\RequestPattern\\' . $name); if ($resolvedObjectName !== FALSE) { return $resolvedObjectName; } throw new \TYPO3\Flow\Security\Exception\NoRequestPatternFoundException('A request pattern with the name: "' . $name . '" could not be resolved.', 1217154134); }