Exemplo n.º 1
0
 /**
  */
 public function getOptions()
 {
     $classSchema = $this->reflectionService->getClassSchema($this->getRelationClass());
     if ($classSchema->getRepositoryClassName() !== NULL) {
         $repository = $this->objectManager->get($classSchema->getRepositoryClassName());
         $query = call_user_func(array($repository, $this->settings['QueryMethod']));
     } else {
         $query = $this->persistenceManager->createQueryForType($this->getRelationClass());
     }
     $options = $query->execute()->toArray();
     if ($this->settings['LabelPath'] !== NULL) {
         $options = array();
         foreach ($query->execute() as $option) {
             $identifier = $this->persistenceManager->getIdentifierByObject($option);
             $label = ObjectAccess::getPropertyPath($option, $this->settings['LabelPath']);
             $options[$identifier] = $label;
         }
     }
     if ($this->settings['EmptyOption'] !== NULL) {
         $newOptions = array('' => $this->settings['EmptyOption']);
         foreach ($options as $key => $value) {
             $newOptions[$key] = $value;
         }
         $options = $newOptions;
     }
     return $options;
 }
 /**
  * @param RegistrationFlow $value The value that should be validated
  * @return void
  * @throws InvalidValidationOptionsException
  */
 protected function isValid($value)
 {
     /** @noinspection PhpUndefinedMethodInspection */
     $existingAccount = $this->accountRepository->findOneByAccountIdentifier($value->getEmail());
     if ($existingAccount) {
         // todo: error message translatable
         $this->result->forProperty('email')->addError(new Error('Die Email-Adresse %s wird bereits verwendet!', 1336499566, [$value->getEmail()]));
     }
     // If a custom validation service is registered, call its validate method to allow custom validations during registration
     if ($this->objectManager->isRegistered(RegistrationFlowValidationServiceInterface::class)) {
         $instance = $this->objectManager->get(RegistrationFlowValidationServiceInterface::class);
         $instance->validateRegistrationFlow($value, $this);
     }
 }
Exemplo n.º 3
0
 /**
  * @param Asset $asset
  * @return MetaDataCollection
  * @throws NoExtractorAvailableException
  * @throws UnknownObjectException
  */
 public function extractMetaData(Asset $asset)
 {
     $flowResource = $asset->getResource();
     $suitableAdapterClasses = $this->findSuitableExtractorAdaptersForResource($flowResource);
     if (count($suitableAdapterClasses) == 0) {
         throw new NoExtractorAvailableException('No Extractor available for media type ' . $flowResource->getMediaType(), 1461433352);
     }
     $metaDataCollection = new MetaDataCollection();
     $this->buildAssetMetaData($asset, $metaDataCollection);
     foreach ($suitableAdapterClasses as $suitableAdapterClass) {
         /** @var ExtractorInterface $suitableAdapter */
         $suitableAdapter = $this->objectManager->get($suitableAdapterClass);
         $suitableAdapter->extractMetaData($flowResource, $metaDataCollection);
     }
     $this->metaDataManager->updateMetaDataForAsset($asset, $metaDataCollection);
     return $metaDataCollection;
 }
Exemplo n.º 4
0
 /**
  * @test
  */
 public function parseSetsDefaultValueOfRoutePartsRecursively()
 {
     $this->route->setUriPattern('{foo.bar}');
     $this->route->setRoutePartsConfiguration(array('foo.bar' => array('handler' => 'SomeRoutePartHandler')));
     $this->route->setDefaults(array('foo' => array('bar' => 'SomeDefaultValue')));
     $mockRoutePartHandler = $this->getMock('TYPO3\\Flow\\Mvc\\Routing\\DynamicRoutePartInterface');
     $mockRoutePartHandler->expects($this->once())->method('setDefaultValue')->with('SomeDefaultValue');
     $this->mockObjectManager->expects($this->once())->method('get')->with('SomeRoutePartHandler')->will($this->returnValue($mockRoutePartHandler));
     $this->route->parse();
 }
 /**
  * Returns a fresh or existing instance of the object specified by $objectName.
  *
  * This specialized get() method is able to do setter injection for properties
  * defined in the object configuration of the specified object.
  *
  * @param string $objectName The name of the object to return an instance of
  * @return object The object instance
  * @throws \TYPO3\Flow\Object\Exception\CannotBuildObjectException
  * @throws \TYPO3\Flow\Object\Exception\UnresolvedDependenciesException
  * @throws \TYPO3\Flow\Object\Exception\UnknownObjectException
  */
 public function get($objectName)
 {
     if (isset($this->objects[$objectName]['i'])) {
         return $this->objects[$objectName]['i'];
     }
     if (isset($this->objectConfigurations[$objectName]) && count($this->objectConfigurations[$objectName]->getArguments()) > 0) {
         throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because constructor injection is not available in the compile time Object Manager. Refactor your code to use setter injection instead. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '. Build stack: ' . implode(', ', $this->objectNameBuildStack), 1297090026);
     }
     if (!isset($this->objects[$objectName])) {
         throw new Exception\UnknownObjectException('Cannot build object "' . $objectName . '" because it is unknown to the compile time Object Manager.', 1301477694);
     }
     if ($this->objects[$objectName]['s'] !== Configuration::SCOPE_SINGLETON) {
         throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because the get() method in the compile time Object Manager only supports singletons.', 1297090027);
     }
     $this->objectNameBuildStack[] = $objectName;
     $object = parent::get($objectName);
     /** @var Configuration $objectConfiguration */
     $objectConfiguration = $this->objectConfigurations[$objectName];
     /** @var Property $property */
     foreach ($objectConfiguration->getProperties() as $propertyName => $property) {
         if ($property->getAutowiring() !== Configuration::AUTOWIRING_MODE_ON) {
             continue;
         }
         switch ($property->getType()) {
             case Property::PROPERTY_TYPES_STRAIGHTVALUE:
                 $value = $property->getValue();
                 break;
             case Property::PROPERTY_TYPES_CONFIGURATION:
                 $propertyValue = $property->getValue();
                 $value = $this->configurationManager->getConfiguration($propertyValue['type'], $propertyValue['path']);
                 break;
             case Property::PROPERTY_TYPES_OBJECT:
                 $propertyObjectName = $property->getValue();
                 if (!is_string($propertyObjectName)) {
                     throw new Exception\CannotBuildObjectException('The object definition of "' . $objectName . '::' . $propertyName . '" is too complex for the compile time Object Manager. You can only use plain object names, not factories and the like. Check configuration in ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . ' and objects which depend on ' . $objectName . '.', 1297099659);
                 }
                 $value = $this->get($propertyObjectName);
                 break;
             default:
                 throw new Exception\CannotBuildObjectException('Invalid property type.', 1297090029);
         }
         if (method_exists($object, $setterMethodName = 'inject' . ucfirst($propertyName))) {
             $object->{$setterMethodName}($value);
         } elseif (method_exists($object, $setterMethodName = 'set' . ucfirst($propertyName))) {
             $object->{$setterMethodName}($value);
         } else {
             throw new Exception\UnresolvedDependenciesException('Could not inject configured property "' . $propertyName . '" into "' . $objectName . '" because no injection method exists, but for compile time use this is required. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '.', 1297110953);
         }
     }
     $initializationLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleInitializationMethodName();
     if (method_exists($object, $initializationLifecycleMethodName)) {
         $object->{$initializationLifecycleMethodName}();
     }
     $shutdownLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName();
     if (method_exists($object, $shutdownLifecycleMethodName)) {
         $this->shutdownObjects[$object] = $shutdownLifecycleMethodName;
     }
     array_pop($this->objectNameBuildStack);
     return $object;
 }
Exemplo n.º 6
0
 /**
  * Create a new Search Query underneath the given $contextNode
  *
  * @param NodeInterface $contextNode
  * @return QueryBuilderInterface
  */
 public function query(NodeInterface $contextNode)
 {
     $queryBuilder = $this->objectManager->get('TYPO3\\TYPO3CR\\Search\\Search\\QueryBuilderInterface');
     return $queryBuilder->query($contextNode);
 }
 /**
  * Initializes the runtime Object Manager
  *
  * @param Bootstrap $bootstrap
  * @return void
  */
 public static function initializeObjectManager(Bootstrap $bootstrap)
 {
     $configurationManager = $bootstrap->getEarlyInstance(ConfigurationManager::class);
     $objectConfigurationCache = $bootstrap->getEarlyInstance(CacheManager::class)->getCache('Flow_Object_Configuration');
     $objectManager = new ObjectManager($bootstrap->getContext());
     Bootstrap::$staticObjectManager = $objectManager;
     $objectManager->injectAllSettings($configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS));
     $objectManager->setObjects($objectConfigurationCache->get('objects'));
     foreach ($bootstrap->getEarlyInstances() as $objectName => $instance) {
         $objectManager->setInstance($objectName, $instance);
     }
     $objectManager->get(Dispatcher::class)->injectObjectManager($objectManager);
     Debugger::injectObjectManager($objectManager);
     $bootstrap->setEarlyInstance(ObjectManagerInterface::class, $objectManager);
 }