public function getOptions()
 {
     $being = $this->property->being;
     if ($being == "array") {
         $selected = $this->property->getValue();
         $policy = $this->configurationManager->getConfiguration(\TYPO3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_POLICY);
         $options = array();
         foreach ($policy["roles"] as $key => $value) {
             $options[] = new \Admin\Core\Option($key, $key, $this->isSelected($key));
         }
         return $options;
     } else {
         $groups = $this->helper->getGroups();
         $actions = $this->getActions();
         foreach ($groups as $group => $beings) {
             foreach ($beings["beings"] as $being => $conf) {
                 foreach ($actions as $action => $label) {
                     $label = str_replace("@being", $conf["name"], $label);
                     $name = $group . " | " . $conf["name"] . " | " . $label;
                     $this->createOrUpdate($name, $action, $being);
                 }
             }
         }
         $this->persistenceManager->persistAll();
         return parent::getOptions();
     }
 }
 /**
  * @test
  */
 public function feedActionWithoutParametersRendersFeed()
 {
     $this->createTestData();
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $result = $this->sendWebRequest('Standard', 'Planetflow3', 'feed');
     // TODO Test actual output contains item
 }
Esempio n. 3
0
 /**
  * Loads the objects this LazySplObjectStorage is supposed to hold.
  *
  * @return void
  */
 protected function initialize()
 {
     if (is_array($this->objectIdentifiers)) {
         foreach ($this->objectIdentifiers as $identifier) {
             try {
                 parent::attach($this->persistenceManager->getObjectByIdentifier($identifier));
             } catch (\TYPO3\FLOW3\Persistence\Generic\Exception\InvalidObjectDataException $e) {
                 // when security query rewriting holds back an object here, we skip it...
             }
         }
         $this->objectIdentifiers = NULL;
     }
 }
Esempio n. 4
0
 /**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->mockObjectManager = $this->getMock('TYPO3\\FLOW3\\Object\\ObjectManagerInterface');
     $this->mockObjectManager->expects($this->any())->method('create')->will($this->returnCallback(array($this, 'objectManagerCallBack')));
     $this->route = $this->getAccessibleMock('TYPO3\\FLOW3\\Mvc\\Routing\\Route', array('dummy'));
     $this->route->_set('objectManager', $this->mockObjectManager);
     $this->mockRouter = $this->getMock('TYPO3\\FLOW3\\Mvc\\Routing\\RouterInterface');
     $this->mockRouter->expects($this->any())->method('getControllerObjectName')->will($this->returnValue('SomeControllerObjectName'));
     $this->route->injectRouter($this->mockRouter);
     $this->mockPersistenceManager = $this->getMock('TYPO3\\FLOW3\\Persistence\\PersistenceManagerInterface');
     $this->mockPersistenceManager->expects($this->any())->method('convertObjectsToIdentityArrays')->will($this->returnCallback(function ($array) {
         return $array;
     }));
     $this->route->injectPersistenceManager($this->mockPersistenceManager);
 }
Esempio n. 5
0
 /**
  * Finds an object from the repository by searching for its identity properties.
  *
  * @param array $identityProperties Property names and values to search for
  * @param string $type The object type to look for
  * @return object Either the object matching the identity or NULL if no object was found
  * @throws \TYPO3\FLOW3\Property\Exception\DuplicateObjectException if more than one object was found
  */
 protected function findObjectByIdentityProperties(array $identityProperties, $type)
 {
     $query = $this->persistenceManager->createQueryForType($type);
     $classSchema = $this->reflectionService->getClassSchema($type);
     $equals = array();
     foreach ($classSchema->getIdentityProperties() as $propertyName => $propertyType) {
         if (isset($identityProperties[$propertyName])) {
             if ($propertyType === 'string') {
                 $equals[] = $query->equals($propertyName, $identityProperties[$propertyName], FALSE);
             } else {
                 $equals[] = $query->equals($propertyName, $identityProperties[$propertyName]);
             }
         }
     }
     if (count($equals) === 1) {
         $constraint = current($equals);
     } else {
         $constraint = $query->logicalAnd(current($equals), next($equals));
         while (($equal = next($equals)) !== FALSE) {
             $constraint = $query->logicalAnd($constraint, $equal);
         }
     }
     $objects = $query->matching($constraint)->execute();
     $numberOfResults = $objects->count();
     if ($numberOfResults === 1) {
         return $objects->getFirst();
     } elseif ($numberOfResults === 0) {
         return NULL;
     } else {
         throw new \TYPO3\FLOW3\Property\Exception\DuplicateObjectException('More than one object was returned for the given identity, this is a constraint violation.', 1259612399);
     }
 }
Esempio n. 6
0
 /**
  * Forwards the request to another action and / or controller.
  *
  * Request is directly transfered to the other action / controller
  *
  * @param string $actionName Name of the action to forward to
  * @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used.
  * @param string $packageKey Key of the package containing the controller to forward to. May also contain the sub package, concatenated with backslash (Vendor.Foo\Bar\Baz). If not specified, the current package is assumed.
  * @param array $arguments Arguments to pass to the target action
  * @return void
  * @throws \TYPO3\FLOW3\Mvc\Exception\ForwardException
  * @see redirect()
  * @api
  */
 protected function forward($actionName, $controllerName = NULL, $packageKey = NULL, array $arguments = array())
 {
     $nextRequest = clone $this->request;
     $nextRequest->setControllerActionName($actionName);
     if ($controllerName !== NULL) {
         $nextRequest->setControllerName($controllerName);
     }
     if ($packageKey !== NULL && strpos($packageKey, '\\') !== FALSE) {
         list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);
     } else {
         $subpackageKey = NULL;
     }
     if ($packageKey !== NULL) {
         $nextRequest->setControllerPackageKey($packageKey);
     }
     if ($subpackageKey !== NULL) {
         $nextRequest->setControllerSubpackageKey($subpackageKey);
     }
     $regularArguments = array();
     foreach ($arguments as $argumentName => $argumentValue) {
         if (substr($argumentName, 0, 2) === '__') {
             $nextRequest->setArgument($argumentName, $argumentValue);
         } else {
             $regularArguments[$argumentName] = $argumentValue;
         }
     }
     $nextRequest->setArguments($this->persistenceManager->convertObjectsToIdentityArrays($regularArguments));
     $this->arguments->removeAll();
     $forwardException = new \TYPO3\FLOW3\Mvc\Exception\ForwardException();
     $forwardException->setNextRequest($nextRequest);
     throw $forwardException;
 }
Esempio n. 7
0
 /**
  * Schedules a modified object for persistence.
  *
  * @param object $object The modified object
  * @return void
  * @throws \TYPO3\FLOW3\Persistence\Exception\IllegalObjectTypeException
  * @api
  */
 public function update($object)
 {
     if (!$object instanceof $this->objectType) {
         throw new \TYPO3\FLOW3\Persistence\Exception\IllegalObjectTypeException('The modified object given to update() was not of the type (' . $this->objectType . ') this repository manages.', 1249479625);
     }
     $this->persistenceManager->update($object);
 }
Esempio n. 8
0
 /**
  * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext
  * @return void
  * @throws \TYPO3\Setup\Exception
  */
 public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext)
 {
     $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues();
     if (isset($formValues['prune']) && intval($formValues['prune']) === 1) {
         $this->nodeRepository->removeAll();
         $this->workspaceRepository->removeAll();
         $this->domainRepository->removeAll();
         $this->siteRepository->removeAll();
         $this->persistenceManager->persistAll();
     }
     if (!empty($formValues['packageKey'])) {
         if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) {
             throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486);
         }
         $packageKey = $formValues['packageKey'];
         $siteName = $formValues['packageKey'];
         $this->packageManager->createPackage($packageKey, NULL, Files::getUnixStylePath(Files::concatenatePaths(array(FLOW3_PATH_PACKAGES, 'Sites'))));
         $this->generatorService->generateSitesXml($packageKey, $siteName);
         $this->generatorService->generateSitesTypoScript($packageKey, $siteName);
         $this->generatorService->generateSitesTemplate($packageKey, $siteName);
         $this->packageManager->activatePackage($packageKey);
     } else {
         $packageKey = $formValues['site'];
     }
     if ($packageKey !== '') {
         try {
             $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
             $this->nodeRepository->setContext($contentContext);
             $this->siteImportService->importFromPackage($packageKey);
         } catch (\Exception $exception) {
             $finisherContext->cancel();
             $this->flashMessageContainer->addMessage(new \TYPO3\FLOW3\Error\Error(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage())));
         }
     }
 }
Esempio n. 9
0
 /**
  * Schedules a modified object for persistence.
  *
  * @param object $object The modified object
  * @throws \TYPO3\FLOW3\Persistence\Exception\IllegalObjectTypeException
  * @api
  */
 public function update($object)
 {
     if (!is_object($object) || !$object instanceof $this->entityClassName) {
         $type = is_object($object) ? get_class($object) : gettype($object);
         throw new \TYPO3\FLOW3\Persistence\Exception\IllegalObjectTypeException('The value given to update() was ' . $type . ' , however the ' . get_class($this) . ' can only store ' . $this->entityClassName . ' instances.', 1249479625);
     }
     $this->persistenceManager->update($object);
 }
Esempio n. 10
0
 /**
  * Returns the number of objects in the result
  *
  * @return integer The number of matching objects
  * @api
  */
 public function count()
 {
     if (is_array($this->queryResult)) {
         return count($this->queryResult);
     } else {
         return $this->persistenceManager->getObjectCountByQuery($this->query);
     }
 }
Esempio n. 11
0
 /**
  * @param object $object
  * @param string $parentIdentifier
  * @return array
  */
 protected function processObject($object, $parentIdentifier)
 {
     if (isset($this->classSchemata[get_class($object)]) && $this->classSchemata[get_class($object)]->isAggregateRoot() && !$this->persistenceManager->isNewObject($object)) {
         return array('identifier' => $this->persistenceSession->getIdentifierByObject($object));
     } else {
         return array('identifier' => $this->persistObject($object, $parentIdentifier));
     }
 }
Esempio n. 12
0
 /**
  * Helper function which creates or fetches a resource pointer object for a given hash.
  *
  * If a ResourcePointer with the given hash exists, this one is used. Else, a new one
  * is created. This is a workaround for missing ValueObject support in Doctrine.
  *
  * @param string $hash
  * @return \TYPO3\FLOW3\Resource\ResourcePointer
  */
 public function getResourcePointerForHash($hash)
 {
     $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\FLOW3\\Resource\\ResourcePointer');
     if (!$resourcePointer) {
         $resourcePointer = new \TYPO3\FLOW3\Resource\ResourcePointer($hash);
         $this->persistenceManager->add($resourcePointer);
     }
     return $resourcePointer;
 }
 /**
  * Checks, if the given constraint holds for the passed result.
  *
  * @param array $constraintDefinition The constraint definition array
  * @param object $result The result object returned by the persistence manager
  * @return boolean TRUE if the query result is valid for the given constraint
  * @throws \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException
  */
 protected function checkSingleConstraintDefinitionOnResultObject(array $constraintDefinition, $result)
 {
     $referenceToThisFound = FALSE;
     if (!is_array($constraintDefinition['leftValue']) && strpos($constraintDefinition['leftValue'], 'this.') === 0) {
         $referenceToThisFound = TRUE;
         $propertyPath = substr($constraintDefinition['leftValue'], 5);
         $leftOperand = $this->getObjectValueByPath($result, $propertyPath);
     } else {
         $leftOperand = $this->getValueForOperand($constraintDefinition['leftValue']);
     }
     if (!is_array($constraintDefinition['rightValue']) && strpos($constraintDefinition['rightValue'], 'this.') === 0) {
         $referenceToThisFound = TRUE;
         $propertyPath = substr($constraintDefinition['rightValue'], 5);
         $rightOperand = $this->getObjectValueByPath($result, $propertyPath);
     } else {
         $rightOperand = $this->getValueForOperand($constraintDefinition['rightValue']);
     }
     if ($referenceToThisFound === FALSE) {
         throw new \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException('An entity security constraint must have at least one operand that references to "this.". Got: "' . $constraintDefinition['leftValue'] . '" and "' . $constraintDefinition['rightValue'] . '"', 1277218400);
     }
     if (is_object($leftOperand) && ($this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($leftOperand), 'TYPO3\\FLOW3\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($leftOperand), 'Doctrine\\ORM\\Mapping\\Entity'))) {
         $leftOperand = $this->persistenceManager->getIdentifierByObject($leftOperand);
     }
     if (is_object($rightOperand) && ($this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($rightOperand), 'TYPO3\\FLOW3\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($this->reflectionService->getClassNameByObject($rightOperand), 'Doctrine\\ORM\\Mapping\\Entity'))) {
         $rightOperand = $this->persistenceManager->getIdentifierByObject($rightOperand);
     }
     switch ($constraintDefinition['operator']) {
         case '!=':
             return $leftOperand !== $rightOperand;
             break;
         case '==':
             return $leftOperand === $rightOperand;
             break;
         case '<':
             return $leftOperand < $rightOperand;
             break;
         case '>':
             return $leftOperand > $rightOperand;
             break;
         case '<=':
             return $leftOperand <= $rightOperand;
             break;
         case '>=':
             return $leftOperand >= $rightOperand;
             break;
         case 'in':
             return in_array($leftOperand, $rightOperand);
             break;
         case 'contains':
             return in_array($rightOperand, $leftOperand);
             break;
         case 'matches':
             return count(array_intersect($leftOperand, $rightOperand)) !== 0;
             break;
     }
     throw new \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid. Got: ' . $constraintDefinition['operator'], 1277222521);
 }
Esempio n. 14
0
 public function deleteObject($being, $id)
 {
     $object = $this->persistenceManager->getObjectByIdentifier($id, $being);
     if ($object == null) {
         return;
     }
     $repositoryObject = $this->objectManager->get($this->getRepositoryForModel($being));
     $repositoryObject->remove($object);
     $this->persistenceManager->persistAll();
 }
Esempio n. 15
0
 /**
  * @test
  */
 public function createPathSegmentForObjectReturnsTheCleanedUpObjectIdentifierIfUriPatternIsEmpty()
 {
     $identityRoutePart = $this->getAccessibleMock('TYPO3\\FLOW3\\Mvc\\Routing\\IdentityRoutePart', array('dummy'));
     $identityRoutePart->_set('persistenceManager', $this->mockPersistenceManager);
     $identityRoutePart->setUriPattern('');
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue('Objäct--Identifüer/---'));
     $actualResult = $identityRoutePart->_call('createPathSegmentForObject', $object);
     $this->assertSame('Objaect-Identifueer', $actualResult);
 }
Esempio n. 16
0
 /**
  * Creates a new ObjectPathMapping and stores it in the repository
  *
  * @param string $pathSegment
  * @param mixed $identifier
  * @return void
  */
 protected function storeObjectPathMapping($pathSegment, $identifier)
 {
     $objectPathMapping = new \TYPO3\FLOW3\Mvc\Routing\ObjectPathMapping();
     $objectPathMapping->setObjectType($this->objectType);
     $objectPathMapping->setUriPattern($this->getUriPattern());
     $objectPathMapping->setPathSegment($pathSegment);
     $objectPathMapping->setIdentifier($identifier);
     $this->objectPathMappingRepository->add($objectPathMapping);
     // TODO can be removed, when persistence manager has some memory cache
     $this->persistenceManager->persistAll();
 }
 /**
  * Iterate through the configured modules, find the matching module and set
  * the route path accordingly
  *
  * @param array $value (contains action, controller and package of the module controller)
  * @return boolean
  */
 protected function resolveValue($value)
 {
     if (is_array($value)) {
         $this->value = isset($value['@action']) && $value['@action'] !== 'index' ? $value['@action'] : '';
         $exceedingArguments = array();
         foreach ($value as $argumentKey => $argumentValue) {
             if (substr($argumentKey, 0, 1) !== '@' && substr($argumentKey, 0, 2) !== '__') {
                 $exceedingArguments[$argumentKey] = $argumentValue;
             }
         }
         if ($exceedingArguments !== array()) {
             $exceedingArguments = \TYPO3\FLOW3\Utility\Arrays::removeEmptyElementsRecursively($exceedingArguments);
             $exceedingArguments = $this->persistenceManager->convertObjectsToIdentityArrays($exceedingArguments);
             $queryString = http_build_query(array($this->name => $exceedingArguments), NULL, '&');
             if ($queryString !== '') {
                 $this->value .= '?' . $queryString;
             }
         }
     }
     return TRUE;
 }
Esempio n. 18
0
 /**
  * @test
  */
 public function cacheResolveCallSkipsCacheIfRouteValuesContainObjectsThatCantBeConvertedToHashes()
 {
     $mockObject = new \stdClass();
     $routeValues = array('b' => 'route values', 'someObject' => $mockObject);
     $this->mockJoinPoint->expects($this->once())->method('getMethodArgument')->with('routeValues')->will($this->returnValue($routeValues));
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($mockObject)->will($this->returnValue(NULL));
     $matchingUri = 'uncached/matching/uri';
     $this->mockAdviceChain->expects($this->once())->method('proceed')->with($this->mockJoinPoint)->will($this->returnValue($matchingUri));
     $this->mockResolveCache->expects($this->never())->method('has');
     $this->mockResolveCache->expects($this->never())->method('set');
     $this->routerCachingAspect->cacheResolveCall($this->mockJoinPoint);
 }
Esempio n. 19
0
 /**
  * Converts the given string or array to a ResourcePointer object.
  *
  * If the input format is an array, this method assumes the resource to be a
  * fresh file upload and imports the temporary upload file through the
  * resource manager.
  *
  * @param array $source The upload info (expected keys: error, name, tmp_name)
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\FLOW3\Resource\Resource|TYPO3\FLOW3\Error\Error if the input format is not supported or could not be converted for other reasons
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) {
             $resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\FLOW3\\Resource\\ResourcePointer');
             if ($resourcePointer) {
                 $resource = new Resource();
                 $resource->setFilename($source['submittedFile']['filename']);
                 $resource->setResourcePointer($resourcePointer);
                 return $resource;
             }
         }
         return NULL;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new \TYPO3\FLOW3\Error\Error(\TYPO3\FLOW3\Utility\Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', \TYPO3\FLOW3\Utility\Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new \TYPO3\FLOW3\Error\Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source);
     if ($resource === FALSE) {
         return new \TYPO3\FLOW3\Error\Error('The resource manager could not create a Resource instance.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }
Esempio n. 20
0
 /**
  * Checks, whether given value can be resolved and if so, sets $this->value to the resolved value.
  * If $value is empty, this method checks whether a default value exists.
  * This method can be overridden by custom RoutePartHandlers to implement custom resolving mechanisms.
  *
  * @param string $value value to resolve
  * @return boolean TRUE if value could be resolved successfully, otherwise FALSE.
  * @api
  */
 protected function resolveValue($value)
 {
     if ($value === NULL) {
         return FALSE;
     }
     if (is_object($value)) {
         $value = $this->persistenceManager->getIdentifierByObject($value);
         if ($value === NULL || !is_string($value)) {
             return FALSE;
         }
     }
     $this->value = (string) $value;
     if ($this->lowerCase) {
         $this->value = strtolower($this->value);
     }
     return TRUE;
 }
Esempio n. 21
0
 /**
  * Fetch the metadata for a given image
  *
  * @param \TYPO3\Media\Domain\Model\Image $image
  * @return string
  */
 public function imageWithMetadataAction(\TYPO3\Media\Domain\Model\Image $image)
 {
     $thumbnail = $image->getThumbnail(500, 500);
     return json_encode(array('imageUuid' => $this->persistenceManager->getIdentifierByObject($image), 'previewImageResourceUri' => $this->resourcePublisher->getPersistentResourceWebUri($thumbnail->getResource()), 'originalSize' => array('w' => $image->getWidth(), 'h' => $image->getHeight()), 'previewSize' => array('w' => $thumbnail->getWidth(), 'h' => $thumbnail->getHeight())));
 }
Esempio n. 22
0
 /**
  * Reconstitutes a persistence object (entity or valueobject) identified by the given UUID.
  *
  * @param string $className The class name of the object to retrieve
  * @param string $uuid The UUID of the object
  * @return object The reconstituted persistence object, NULL if none was found
  */
 protected function reconstitutePersistenceObject($className, $uuid)
 {
     return $this->persistenceManager->getObjectByIdentifier($uuid, $className);
 }
 /**
  * Wrap the $content identified by $node with the needed markup for
  * the backend.
  * $parameters can be used to further pass parameters to the content element.
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node
  * @param string $typoscriptPath
  * @param string $content
  * @param boolean $isPage
  * @return string
  */
 public function wrapContentObject(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node, $typoscriptPath, $content, $isPage = FALSE)
 {
     $contentType = $node->getContentType();
     $tagBuilder = new \TYPO3\Fluid\Core\ViewHelper\TagBuilder('div');
     $tagBuilder->forceClosingTag(TRUE);
     if (!$node->isRemoved()) {
         $tagBuilder->setContent($content);
     }
     if (!$isPage) {
         $cssClasses = array('t3-contentelement');
         $cssClasses[] = str_replace(array(':', '.'), '-', strtolower($contentType->getName()));
         if ($node->isHidden()) {
             $cssClasses[] = 't3-contentelement-hidden';
         }
         if ($node->isRemoved()) {
             $cssClasses[] = 't3-contentelement-removed';
         }
         $tagBuilder->addAttribute('class', implode(' ', $cssClasses));
         $tagBuilder->addAttribute('id', 'c' . $node->getIdentifier());
     }
     try {
         $this->accessDecisionManager->decideOnResource('TYPO3_TYPO3_Backend_BackendController');
     } catch (\TYPO3\FLOW3\Security\Exception\AccessDeniedException $e) {
         return $tagBuilder->render();
     }
     $tagBuilder->addAttribute('typeof', 'typo3:' . $contentType->getName());
     $tagBuilder->addAttribute('about', $node->getContextPath());
     $this->addScriptTag($tagBuilder, '__workspacename', $node->getWorkspace()->getName());
     $this->addScriptTag($tagBuilder, '_removed', $node->isRemoved() ? 'true' : 'false', 'boolean');
     $this->addScriptTag($tagBuilder, '_typoscriptPath', $typoscriptPath);
     foreach ($contentType->getProperties() as $propertyName => $propertyConfiguration) {
         $dataType = isset($propertyConfiguration['type']) ? $propertyConfiguration['type'] : 'string';
         if ($propertyName[0] === '_') {
             $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($node, substr($propertyName, 1));
         } else {
             $propertyValue = $node->getProperty($propertyName);
         }
         // Serialize boolean values to String
         if (isset($propertyConfiguration['type']) && $propertyConfiguration['type'] === 'boolean') {
             $propertyValue = $propertyValue ? 'true' : 'false';
         }
         // Serialize date values to String
         if ($propertyValue !== NULL && isset($propertyConfiguration['type']) && $propertyConfiguration['type'] === 'date') {
             $propertyValue = $propertyValue->format('Y-m-d');
         }
         // Serialize objects to JSON strings
         if (is_object($propertyValue) && $propertyValue !== NULL && isset($propertyConfiguration['type']) && $this->objectManager->isRegistered($propertyConfiguration['type'])) {
             $gettableProperties = \TYPO3\FLOW3\Reflection\ObjectAccess::getGettableProperties($propertyValue);
             $convertedProperties = array();
             foreach ($gettableProperties as $key => $value) {
                 if (is_object($value)) {
                     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($value);
                     if ($entityIdentifier !== NULL) {
                         $value = $entityIdentifier;
                     }
                 }
                 $convertedProperties[$key] = $value;
             }
             $propertyValue = json_encode($convertedProperties);
             $dataType = 'jsonEncoded';
         }
         $this->addScriptTag($tagBuilder, $propertyName, $propertyValue, $dataType);
     }
     if (!$isPage) {
         // add CSS classes
         $this->addScriptTag($tagBuilder, '__contenttype', $contentType->getName());
     } else {
         $tagBuilder->addAttribute('id', 't3-page-metainformation');
         $tagBuilder->addAttribute('data-__sitename', $this->nodeRepository->getContext()->getCurrentSite()->getName());
         $tagBuilder->addAttribute('data-__siteroot', sprintf('/sites/%s@%s', $this->nodeRepository->getContext()->getCurrentSite()->getNodeName(), $this->nodeRepository->getContext()->getWorkspace()->getName()));
     }
     return $tagBuilder->render();
 }
Esempio n. 24
0
 /**
  * @test
  */
 public function convertFromReturnsNullIfSpecifiedResourcePointerCantBeFound()
 {
     $source = array('error' => \UPLOAD_ERR_NO_FILE, 'submittedFile' => array('filename' => 'SomeFilename', 'resourcePointer' => 'someNonExistingResourcePointer'));
     $this->mockPersistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('someNonExistingResourcePointer', 'TYPO3\\FLOW3\\Resource\\ResourcePointer')->will($this->returnValue(NULL));
     $this->assertNull($this->resourceTypeConverter->convertFrom($source, 'TYPO3\\FLOW3\\Resource\\Resource'));
 }
Esempio n. 25
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param mixed $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an aray
  */
 protected function transformObject($object, $configuration)
 {
     if ($object instanceof \DateTime) {
         return $object->format('Y-m-d\\TH:i:s');
     } else {
         $propertyNames = \TYPO3\FLOW3\Reflection\ObjectAccess::getGettablePropertyNames($object);
         $propertiesToRender = array();
         foreach ($propertyNames as $propertyName) {
             if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
                 continue;
             }
             if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
                 continue;
             }
             $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName);
             if (!is_array($propertyValue) && !is_object($propertyValue)) {
                 $propertiesToRender[$propertyName] = $propertyValue;
             } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
                 $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
             }
         }
         if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === TRUE) {
             if (isset($configuration['_exposedObjectIdentifierKey']) && strlen($configuration['_exposedObjectIdentifierKey']) > 0) {
                 $identityKey = $configuration['_exposedObjectIdentifierKey'];
             } else {
                 $identityKey = '__identity';
             }
             $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
         }
         return $propertiesToRender;
     }
 }
Esempio n. 26
0
 /**
  * After returning advice, making sure we have an UUID for each and every entity.
  *
  * @param \TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint The current join point
  * @return void
  * @FLOW3\Before("TYPO3\FLOW3\Persistence\Aspect\PersistenceMagicAspect->isEntity && method(.*->(__construct|__clone)())")
  */
 public function generateUuid(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint)
 {
     $proxy = $joinPoint->getProxy();
     \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($proxy, 'FLOW3_Persistence_Identifier', \TYPO3\FLOW3\Utility\Algorithms::generateUUID(), TRUE);
     $this->persistenceManager->registerNewObject($proxy);
 }
Esempio n. 27
0
 /**
  * @test
  */
 public function resolveValueReturnsFalseIfTheValueToBeResolvedIsAnObjectWithAnIdentifierThatIsNoString()
 {
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue(array('foo', 'bar')));
     $this->assertFalse($this->dynamicRoutPart->_call('resolveValue', $object));
 }
Esempio n. 28
0
 /**
  * Checks whether $routeValues can be resolved to a corresponding uri.
  * If all Route Parts can resolve one or more of the $routeValues, TRUE is
  * returned and $this->matchingURI contains the generated URI (excluding
  * protocol and host).
  *
  * @param array $routeValues An array containing key/value pairs to be resolved to uri segments
  * @return boolean TRUE if this Route corresponds to the given $routeValues, otherwise FALSE
  * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException
  * @see getMatchingUri()
  */
 public function resolves(array $routeValues)
 {
     $this->matchingUri = NULL;
     if ($this->uriPattern === NULL) {
         return FALSE;
     }
     if (!$this->isParsed) {
         $this->parse();
     }
     $matchingUri = '';
     $mergedRouteValues = \TYPO3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($this->defaults, $routeValues);
     $requireOptionalRouteParts = FALSE;
     $matchingOptionalUriPortion = '';
     foreach ($this->routeParts as $routePart) {
         if (!$routePart->resolve($routeValues)) {
             if (!$routePart->hasDefaultValue()) {
                 return FALSE;
             }
         }
         $routePartValue = NULL;
         if ($routePart->hasValue()) {
             $routePartValue = $routePart->getValue();
             if (!is_string($routePartValue)) {
                 throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException('RoutePart::getValue() must return a string after calling RoutePart::resolve(), got ' . (is_object($routePartValue) ? get_class($routePartValue) : gettype($routePartValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
             }
         }
         $routePartDefaultValue = $routePart->getDefaultValue();
         if ($routePartDefaultValue !== NULL && !is_string($routePartDefaultValue)) {
             throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException('RoutePart::getDefaultValue() must return a string, got ' . (is_object($routePartDefaultValue) ? get_class($routePartDefaultValue) : gettype($routePartDefaultValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
         }
         if (!$routePart->isOptional()) {
             $matchingUri .= $routePart->hasValue() ? $routePartValue : $routePartDefaultValue;
             $requireOptionalRouteParts = FALSE;
             continue;
         }
         if ($routePart->hasValue() && $routePartValue !== $routePartDefaultValue) {
             $matchingOptionalUriPortion .= $routePartValue;
             $requireOptionalRouteParts = TRUE;
         } else {
             $matchingOptionalUriPortion .= $routePartDefaultValue;
         }
         if ($requireOptionalRouteParts) {
             $matchingUri .= $matchingOptionalUriPortion;
             $matchingOptionalUriPortion = '';
         }
     }
     if ($this->compareAndRemoveMatchingDefaultValues($this->defaults, $routeValues) !== TRUE) {
         return FALSE;
     }
     if (isset($routeValues['@format']) && $routeValues['@format'] === '') {
         unset($routeValues['@format']);
     }
     $this->throwExceptionIfTargetControllerDoesNotExist($mergedRouteValues);
     // add query string
     if (count($routeValues) > 0) {
         $routeValues = \TYPO3\FLOW3\Utility\Arrays::removeEmptyElementsRecursively($routeValues);
         $routeValues = $this->persistenceManager->convertObjectsToIdentityArrays($routeValues);
         if (!$this->appendExceedingArguments) {
             $internalArguments = $this->extractInternalArguments($routeValues);
             if ($routeValues !== array()) {
                 return FALSE;
             }
             $routeValues = $internalArguments;
         }
         $queryString = http_build_query($routeValues, NULL, '&');
         if ($queryString !== '') {
             $matchingUri .= strpos($matchingUri, '?') !== FALSE ? '&' . $queryString : '?' . $queryString;
         }
     }
     $this->matchingUri = $matchingUri;
     return TRUE;
 }