/** * Log a message if a post is deleted * * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint * @Flow\Around("method(TYPO3\Neos\View\TypoScriptView->render())") * @return void */ public function replacePlaceholdersIfNecessary(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { $result = $joinPoint->getAdviceChain()->proceed($joinPoint); /* @var $typoScriptView TypoScriptView */ $typoScriptView = $joinPoint->getProxy(); $viewVariables = ObjectAccess::getProperty($typoScriptView, 'variables', TRUE); if (!isset($viewVariables['value']) || !$viewVariables['value']->getNodeType()->isOfType('Sandstorm.Newsletter:Newsletter')) { // No newsletter, so logic does not apply return $result; } /* @var $httpRequest Request */ $httpRequest = $this->controllerContext->getRequest()->getHttpRequest(); $arguments = $httpRequest->getUri()->getArguments(); if (!isset($arguments['hmac'])) { if ($this->securityContext->isInitialized() && $this->securityContext->hasRole('TYPO3.Neos:Editor')) { // Logged into backend, so we don't need to do anything. return $result; } else { // No HMAC sent -- so we return the email INCLUDING placeholders (as per customer's request) return $result; //return '<h1>Error: HMAC not included in the link.</h1>'; } } $actualHmac = $arguments['hmac']; $uriWithoutHmac = str_replace('&hmac=' . $actualHmac, '', (string) $httpRequest->getUri()); $expectedHmac = hash_hmac('sha1', urldecode($uriWithoutHmac), $this->hmacUrlSecret); if ($expectedHmac !== $actualHmac) { return '<h1>Error: Wrong link clicked.</h1>Please contact your administrator for help'; } $result = preg_replace_callback(ReplacePlaceholdersInLiveImplementation::PLACEHOLDER_REGEX, function ($element) use($arguments) { return ObjectAccess::getPropertyPath($arguments, $element[1]); }, $result); return $result; }
/** * @param string $term * @return string */ public function autocompleteAction($term) { $searchProperty = $this->widgetConfiguration['searchProperty']; /** @var $queryResult QueryResultInterface */ $queryResult = $this->widgetConfiguration['objects']; $query = clone $queryResult->getQuery(); $constraint = $query->getConstraint(); if ($constraint !== NULL) { $query->matching($query->logicalAnd($constraint, $query->like($searchProperty, '%' . $term . '%', FALSE))); } else { $query->matching($query->like($searchProperty, '%' . $term . '%', FALSE)); } if (isset($this->configuration['limit'])) { $query->setLimit((int) $this->configuration['limit']); } $results = $query->execute(); $output = array(); $values = array(); foreach ($results as $singleResult) { $val = ObjectAccess::getPropertyPath($singleResult, $searchProperty); if (isset($values[$val])) { continue; } $values[$val] = TRUE; $output[] = array('id' => $val, 'label' => $val, 'value' => $val); } return json_encode($output); }
/** * The input is assumed to be an array or Collection of objects. Groups this input by the $groupingKey property of each element. * * @param array|Collection $set * @param string $groupingKey * @return array */ public function groupBy($set, $groupingKey) { $result = array(); foreach ($set as $element) { $result[ObjectAccess::getPropertyPath($element, $groupingKey)][] = $element; } return $result; }
/** * @param string $propertyPath * @return string */ public function render($propertyPath = 'party.name') { $tokens = $this->securityContext->getAuthenticationTokens(); foreach ($tokens as $token) { if ($token->isAuthenticated()) { return (string) \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($token->getAccount(), $propertyPath); } } return ''; }
/** * Updates the identifier credential from the GET/POST vars, if the GET/POST parameters * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent. * * Note: You need to send the password in this parameter: * __authentication[_OurBrand_][Quiz][Security][IdentifierToken][identifier] * * @param \TYPO3\Flow\Mvc\ActionRequest $actionRequest The current action request * @return void */ public function updateCredentials(\TYPO3\Flow\Mvc\ActionRequest $actionRequest) { $postArguments = $actionRequest->getInternalArguments(); $username = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($postArguments, '__authentication._OurBrand_.Quiz.Security.IdentifierToken.username'); $password = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($postArguments, '__authentication._OurBrand_.Quiz.Security.IdentifierToken.password'); if (!empty($username) && !empty($password)) { $this->credentials['username'] = $username; $this->credentials['password'] = $password; $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * @return void */ public function up() { $this->processConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, function (array &$configuration) { $presetsConfiguration = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($configuration, 'TYPO3.Form.presets'); if (!is_array($presetsConfiguration)) { return; } $presetsConfiguration = $this->renameTranslationPackage($presetsConfiguration); $configuration['TYPO3']['Form']['presets'] = $presetsConfiguration; }, true); }
/** * Updates the password credential from the POST vars, if the POST parameters * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent. * * Note: You need to send the password in this POST parameter: * __authentication[TYPO3][Flow][Security][Authentication][Token][PasswordToken][password] * * @param \TYPO3\Flow\Mvc\ActionRequest $actionRequest The current action request * @return void */ public function updateCredentials(\TYPO3\Flow\Mvc\ActionRequest $actionRequest) { if ($actionRequest->getHttpRequest()->getMethod() !== 'POST') { return; } $postArguments = $actionRequest->getInternalArguments(); $password = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($postArguments, '__authentication.TYPO3.Flow.Security.Authentication.Token.PasswordToken.password'); if (!empty($password)) { $this->credentials['password'] = $password; $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * Returns contents of Composer manifest - or part there of. * * @param string $manifestPath * @param string $configurationPath Optional. Only return the part of the manifest indexed by configurationPath * @return array|mixed */ public static function getComposerManifest($manifestPath, $configurationPath = null) { $composerManifest = static::readComposerManifest($manifestPath); if ($composerManifest === null) { return null; } if ($configurationPath !== null) { return ObjectAccess::getPropertyPath($composerManifest, $configurationPath); } else { return $composerManifest; } }
/** * Evaluate the property name filter by traversing to the child object. We only support * nested objects right now * * @param \TYPO3\Eel\FlowQuery\FlowQuery $query * @param string $propertyNameFilter * @return void */ protected function evaluatePropertyNameFilter(\TYPO3\Eel\FlowQuery\FlowQuery $query, $propertyNameFilter) { $resultObjects = array(); $resultObjectHashes = array(); foreach ($query->getContext() as $element) { $subProperty = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, $propertyNameFilter); if (is_object($subProperty) && !isset($resultObjectHashes[spl_object_hash($subProperty)])) { $resultObjectHashes[spl_object_hash($subProperty)] = TRUE; $resultObjects[] = $subProperty; } } $query->setContext($resultObjects); }
/** * {@inheritdoc} * * @param \TYPO3\Eel\FlowQuery\FlowQuery $flowQuery the FlowQuery object * @param array $arguments the property path to use (in index 0) * @return mixed */ public function evaluate(\TYPO3\Eel\FlowQuery\FlowQuery $flowQuery, array $arguments) { if (!isset($arguments[0]) || empty($arguments[0])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('property() must be given an attribute name when used on objects, fetching all attributes is not supported.', 1332492263); } else { $context = $flowQuery->getContext(); if (!isset($context[0])) { return null; } $element = $context[0]; $propertyPath = $arguments[0]; return \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, $propertyPath); } }
/** * Evaluate this TypoScript object and return the result * * @return mixed */ public function evaluate() { $value = $this->tsValue('value'); $isActive = $this->tsValue('isActive'); $sampleData = $this->tsValue('sampleData'); if ($isActive) { $value = preg_replace_callback(self::PLACEHOLDER_REGEX, function ($element) use($sampleData) { return ObjectAccess::getPropertyPath($sampleData, $element[1]); }, $value); return $value; } else { return $value; } }
/** * Updates the username and password credentials from the POST vars, if the POST parameters * are available. Sets the authentication status to REAUTHENTICATION_NEEDED, if credentials have been sent. * * Note: You need to send the username and password in these two POST parameters: * __authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][username] * and __authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][password] * * @param ActionRequest $actionRequest The current action request * @return void */ public function updateCredentials(ActionRequest $actionRequest) { $httpRequest = $actionRequest->getHttpRequest(); if ($httpRequest->getMethod() !== 'POST') { return; } $arguments = $actionRequest->getInternalArguments(); $username = ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.Flow.Security.Authentication.Token.UsernamePassword.username'); $password = ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.Flow.Security.Authentication.Token.UsernamePassword.password'); if (!empty($username) && !empty($password)) { $this->credentials['username'] = $username; $this->credentials['password'] = $password; $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * @test * @dataProvider attributeExamples */ public function evaluateTests($properties, $expectedOutput) { $path = 'attributes/test'; $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) use($path, $properties) { $relativePath = str_replace($path . '/', '', $evaluatePath); return ObjectAccess::getPropertyPath($properties, str_replace('/', '.', $relativePath)); })); $typoScriptObjectName = 'TYPO3.TypoScript:Attributes'; $renderer = new AttributesImplementation($this->mockTsRuntime, $path, $typoScriptObjectName); if ($properties !== null) { foreach ($properties as $name => $value) { ObjectAccess::setProperty($renderer, $name, $value); } } $result = $renderer->evaluate(); $this->assertEquals($expectedOutput, $result); }
/** * {@inheritdoc} * * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return mixed */ public function evaluate(FlowQuery $flowQuery, array $arguments) { if (!isset($arguments[0]) || empty($arguments[0])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('property() does not support returning all attributes yet', 1332492263); } else { $context = $flowQuery->getContext(); $propertyPath = $arguments[0]; if (!isset($context[0])) { return null; } $element = $context[0]; if ($propertyPath[0] === '_') { return \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, substr($propertyPath, 1)); } else { return $element->getProperty($propertyPath); } } }
/** * {@inheritdoc} * * First argument is the node property to sort by. Works with internal arguments (_xyz) as well. * Second argument is the sort direction (ASC or DESC). * * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation. * @return mixed */ public function evaluate(FlowQuery $flowQuery, array $arguments) { $nodes = $flowQuery->getContext(); // Check sort property if (isset($arguments[0]) && !empty($arguments[0])) { $sortProperty = $arguments[0]; } else { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('Please provide a node property to sort by.', 1467881104); } // Check sort direction if (isset($arguments[1]) && !empty($arguments[1]) && in_array(strtoupper($arguments[1]), ['ASC', 'DESC'])) { $sortOrder = strtoupper($arguments[1]); } else { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('Please provide a valid sort direction (ASC or DESC)', 1467881105); } $sortedNodes = []; $sortSequence = []; $nodesByIdentifier = []; // Determine the property value to sort by /** @var Node $node */ foreach ($nodes as $node) { if ($sortProperty[0] === '_') { $propertyValue = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($node, substr($sortProperty, 1)); } else { $propertyValue = $node->getProperty($sortProperty); } if ($propertyValue instanceof \DateTime) { $propertyValue = $propertyValue->getTimestamp(); } $sortSequence[$node->getIdentifier()] = $propertyValue; $nodesByIdentifier[$node->getIdentifier()] = $node; } // Create the sort sequence if ($sortOrder === 'DESC') { arsort($sortSequence); } elseif ($sortOrder === 'ASC') { asort($sortSequence); } // Build the sorted context that is returned foreach ($sortSequence as $nodeIdentifier => $value) { $sortedNodes[] = $nodesByIdentifier[$nodeIdentifier]; } $flowQuery->setContext($sortedNodes); }
/** * Updates the authentication credentials, the authentication manager needs to authenticate this token. * This could be a username/password from a login controller. * This method is called while initializing the security context. By returning TRUE you * make sure that the authentication manager will (re-)authenticate the tokens with the current credentials. * Note: You should not persist the credentials! * * @param \TYPO3\Flow\Mvc\ActionRequest $request The current request instance * @return boolean TRUE if this token needs to be (re-)authenticated */ public function updateCredentials(\TYPO3\Flow\Mvc\ActionRequest $actionRequest) { $httpRequest = $actionRequest->getHttpRequest(); if ($httpRequest->getMethod() !== 'GET') { return; } // Check if we have a callback request $arguments = $httpRequest->getArguments(); $accessTokenCipher = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($arguments, '__flowpack.singlesignon.accessToken'); $signature = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($arguments, '__flowpack.singlesignon.signature'); if (!empty($accessTokenCipher) && !empty($signature)) { // Get callback parameters from request $this->credentials['accessToken'] = base64_decode($accessTokenCipher); $this->credentials['signature'] = base64_decode($signature); $this->callbackUri = $actionRequest->getHttpRequest()->getUri(); $arguments = $this->callbackUri->getArguments(); unset($arguments['__flowpack']); $this->callbackUri->setQuery(http_build_query($arguments)); $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return void */ public function evaluate(FlowQuery $flowQuery, array $arguments) { $context = $flowQuery->getContext(); if (!isset($context[0])) { return NULL; } $output = array(); /* @var $element NodeInterface */ $element = $context[0]; $properties = ObjectAccess::getPropertyPath($element, 'properties'); $dynamicPropertyPrefix = $this->settings['propertyPrefix']; $propertyConfiguration = $element->getNodeType()->getProperties(); // Retrieve human readable label for each dynamic property from the properties configuration. // Don't show properties which don't exist anymore in the node types configuration. foreach ($propertyConfiguration as $propertyName => $propertyConfig) { if (strpos($propertyName, $dynamicPropertyPrefix) === 0) { $output[$propertyName] = array('label' => $propertyConfig['ui']['label'], 'value' => array_key_exists($propertyName, $properties) ? $properties[$propertyName] : $propertyConfig['defaultValue']); } } $flowQuery->setContext($output); }
/** * Evaluate the property name filter by traversing to the child object. We only support * nested objects right now * * @param \TYPO3\Eel\FlowQuery\FlowQuery $query * @param string $propertyNameFilter * @return void */ protected function evaluatePropertyNameFilter(\TYPO3\Eel\FlowQuery\FlowQuery $query, $propertyNameFilter) { $resultObjects = array(); $resultObjectHashes = array(); foreach ($query->getContext() as $element) { $subProperty = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, $propertyNameFilter); if (is_object($subProperty) || is_array($subProperty)) { if (is_array($subProperty) || $subProperty instanceof \Traversable) { foreach ($subProperty as $childElement) { if (!isset($resultObjectHashes[spl_object_hash($childElement)])) { $resultObjectHashes[spl_object_hash($childElement)] = true; $resultObjects[] = $childElement; } } } elseif (!isset($resultObjectHashes[spl_object_hash($subProperty)])) { $resultObjectHashes[spl_object_hash($subProperty)] = true; $resultObjects[] = $subProperty; } } } $query->setContext($resultObjects); }
/** * {@inheritdoc} * * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return mixed */ public function evaluate(FlowQuery $flowQuery, array $arguments) { if (!isset($arguments[0]) || empty($arguments[0])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('sort() needs property name by which nodes should be sorted', 1332492263); } else { $nodes = $flowQuery->getContext(); $sortByPropertyPath = $arguments[0]; $sortOrder = 'DESC'; if (isset($arguments[1]) && !empty($arguments[1]) && in_array($arguments[1], array('ASC', 'DESC'))) { $sortOrder = $arguments[1]; } $sortedNodes = array(); $sortSequence = array(); $nodesByIdentifier = array(); /** @var Node $node */ foreach ($nodes as $node) { if ($sortByPropertyPath[0] === '_') { $propertyValue = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($node, substr($sortByPropertyPath, 1)); } else { $propertyValue = $node->getProperty($sortByPropertyPath); } if ($propertyValue instanceof \DateTime) { $propertyValue = $propertyValue->getTimestamp(); } $sortSequence[$node->getIdentifier()] = $propertyValue; $nodesByIdentifier[$node->getIdentifier()] = $node; } if ($sortOrder === 'DESC') { arsort($sortSequence); } else { asort($sortSequence); } foreach ($sortSequence as $nodeIdentifier => $value) { $sortedNodes[] = $nodesByIdentifier[$nodeIdentifier]; } $flowQuery->setContext($sortedNodes); } }
/** * @test * @dataProvider attributeExamples */ public function evaluateTests($properties, $expectedOutput, $expectedOutputAsArray) { // print_r(func_get_args()); $path = 'attributes/test'; $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) use($path, $properties) { $relativePath = str_replace($path . '/', '', $evaluatePath); return ObjectAccess::getPropertyPath($properties, str_replace('/', '.', $relativePath)); })); $typoScriptObjectName = 'TYPO3.TypoScript:Attributes'; $renderer = new AttributesImplementation($this->mockTsRuntime, $path, $typoScriptObjectName); if ($properties !== NULL) { foreach ($properties as $name => $value) { ObjectAccess::setProperty($renderer, $name, $value); } } $result = $renderer->evaluate(); $this->assertInstanceOf('M12\\Foundation\\TypoScriptObjects\\AttributesImplementation', $result); $this->assertTrue(is_string($result->getAsString())); $this->assertTrue(is_array($result->getAsArray())); $this->assertEquals($expectedOutput, $result); $this->assertEquals($expectedOutput, $result->getAsString()); $this->assertEquals($expectedOutputAsArray, $result->getAsArray()); }
/** * {@inheritdoc} */ public function render($property, $tag = 'div', NodeInterface $node = NULL) { if ($node === NULL) { $node = $this->getNodeFromTypoScriptContext(); } $propertyConfiguration = $node->getNodeType()->getProperties(); $properties = ObjectAccess::getPropertyPath($node, 'properties'); $dynamicPropertyPrefix = $this->settings['propertyPrefix']; // Add dynamic properties to context which are missing $addedProperties = array(); foreach ($propertyConfiguration as $propertyName => $propertyConfig) { if (strpos($propertyName, $dynamicPropertyPrefix) === 0 && !$this->templateVariableContainer->exists($propertyName)) { $value = array_key_exists($propertyName, $properties) ? $properties[$propertyName] : $propertyConfig['defaultValue']; $this->templateVariableContainer->add($propertyName, $value); $addedProperties[] = $propertyName; } } $output = parent::render($property, $tag, $node); // Remove dynamic properties again foreach ($addedProperties as $propertyName) { $this->templateVariableContainer->remove($propertyName); } return $output; }
/** * Creates a URI representation (path segment) for the given object matching $this->uriPattern. * * @param mixed $object object of type $this->objectType * @return string URI representation (path segment) of the given object * @throws InvalidUriPatternException */ protected function createPathSegmentForObject($object) { $matches = array(); preg_match_all('/(?P<dynamic>{?)(?P<content>[^}{]+)}?/', $this->getUriPattern(), $matches, PREG_SET_ORDER); $pathSegment = ''; foreach ($matches as $match) { if (empty($match['dynamic'])) { $pathSegment .= $match['content']; } else { $dynamicPathSegmentParts = explode(':', $match['content']); $propertyPath = $dynamicPathSegmentParts[0]; $dynamicPathSegment = ObjectAccess::getPropertyPath($object, $propertyPath); if (is_object($dynamicPathSegment)) { if ($dynamicPathSegment instanceof \DateTimeInterface) { $dateFormat = isset($dynamicPathSegmentParts[1]) ? trim($dynamicPathSegmentParts[1]) : 'Y-m-d'; $pathSegment .= $this->rewriteForUri($dynamicPathSegment->format($dateFormat)); } else { throw new InvalidUriPatternException(sprintf('Invalid uriPattern "%s" for route part "%s". Property "%s" must be of type string or \\DateTime. "%s" given.', $this->getUriPattern(), $this->getName(), $propertyPath, is_object($dynamicPathSegment) ? get_class($dynamicPathSegment) : gettype($dynamicPathSegment)), 1316442409); } } else { $pathSegment .= $this->rewriteForUri($dynamicPathSegment); } } } return $pathSegment; }
/** * @param string $path * @return mixed */ public function getOptionByPath($path) { return ObjectAccess::getPropertyPath($this->options, $path); }
/** * Collect the array keys inside $this->subject with each position meta-argument. * If there is no position but the array is numerically ordered, we use the array index as position. * * @return array an associative array where each key of $subject has a position string assigned */ protected function collectArrayKeysAndPositions() { $arrayKeysWithPosition = array(); foreach ($this->subject as $key => $value) { // if the value was set to NULL it was unset and should not be used if ($value === NULL) { continue; } $position = ObjectAccess::getPropertyPath($value, $this->positionPropertyPath); if ($position !== NULL) { $arrayKeysWithPosition[$key] = $position; } elseif (is_numeric($key)) { $arrayKeysWithPosition[$key] = $key; } else { $arrayKeysWithPosition[$key] = 0; } } return $arrayKeysWithPosition; }
/** * {@inheritdoc} * * @param object $element * @param string $propertyPath * @return mixed */ protected function getPropertyPath($element, $propertyPath) { if ($propertyPath[0] === '_') { return \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, substr($propertyPath, 1)); } else { return $element->getProperty($propertyPath); } }
/** * @return array */ protected function getRequireJsPathMapping() { $pathMappings = array(); $validatorSettings = ObjectAccess::getPropertyPath($this->settings, 'userInterface.validators'); if (is_array($validatorSettings)) { foreach ($validatorSettings as $validatorName => $validatorConfiguration) { if (isset($validatorConfiguration['path'])) { $pathMappings[$validatorName] = $this->getStaticResourceWebBaseUri($validatorConfiguration['path']); } } } $editorSettings = ObjectAccess::getPropertyPath($this->settings, 'userInterface.inspector.editors'); if (is_array($editorSettings)) { foreach ($editorSettings as $editorName => $editorConfiguration) { if (isset($editorConfiguration['path'])) { $pathMappings[$editorName] = $this->getStaticResourceWebBaseUri($editorConfiguration['path']); } } } $requireJsPathMappingSettings = ObjectAccess::getPropertyPath($this->settings, 'userInterface.requireJsPathMapping'); if (is_array($requireJsPathMappingSettings)) { foreach ($requireJsPathMappingSettings as $namespace => $path) { $pathMappings[$namespace] = $this->getStaticResourceWebBaseUri($path); } } return $pathMappings; }
/** * Evaluate a property path. This is outsourced to a single method * to make overriding this functionality easy. * * @param object $element * @param string $propertyPath * @return mixed */ protected function getPropertyPath($element, $propertyPath) { return \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($element, $propertyPath); }
/** * Returns the route value of the current route part. * This method can be overridden by custom RoutePartHandlers to implement custom resolving mechanisms. * * @param array $routeValues An array with key/value pairs to be resolved by Dynamic Route Parts. * @return string|array value to resolve. * @api */ protected function findValueToResolve(array $routeValues) { return ObjectAccess::getPropertyPath($routeValues, $this->name); }
/** * Get the option value for an object * * @param mixed $valueElement * @return string */ protected function getOptionValueScalar($valueElement) { if (is_object($valueElement)) { if ($this->hasArgument('optionValueField')) { return ObjectAccess::getPropertyPath($valueElement, $this->arguments['optionValueField']); } elseif ($this->persistenceManager->getIdentifierByObject($valueElement) !== NULL) { return $this->persistenceManager->getIdentifierByObject($valueElement); } else { return (string) $valueElement; } } else { return $valueElement; } }
/** * @param array $paths * @param string $templateNamePrefix * @param string $suffix * @return string */ public function render(array $paths, $templateNamePrefix = NULL, $suffix = '.hbs') { foreach ($paths as $path) { $templates = \TYPO3\Flow\Utility\Files::readDirectoryRecursively($path, $suffix); foreach ($templates as $template) { if (substr($template, 0, strlen($path) + 10) === $path . '/Resources') { $templateName = str_replace(array($path . '/Resources/', $suffix), '', $template); $this->handlebarTemplates[$this->getPrefixedResourceTemplateName($templateName, $templateNamePrefix)] = $template; } elseif (substr($template, 0, strlen($path) + 9) === $path . '/Partials') { $templateName = str_replace(array($path . '/Partials/', $suffix), '', $template); $this->handlebarTemplates['_' . $this->getPrefixedResourceTemplateName($templateName, $templateNamePrefix)] = $template; } else { $templateName = str_replace(array($path . '/', $suffix, '/'), array('', '', '_'), $template); $this->handlebarTemplates[$this->getPrefixedTemplateName($templateName, $templateNamePrefix)] = $template; } } } foreach ($this->handlebarTemplates as $templateName => $template) { $handlebarView = new \TYPO3\Fluid\View\StandaloneView(); $handlebarView->setFormat('html'); $handlebarView->setTemplateSource(\TYPO3\Flow\Utility\Files::getFileContents($template)); $assignHelpers = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($this->settings, 'handlebar.view.assignHelpers.' . $templateName); if (is_array($assignHelpers)) { foreach ($assignHelpers as $variable => $helper) { if (!isset($helper['class']) || !isset($helper['method'])) { continue; } $helperInstance = $this->objectManager->get($helper['class']); $value = call_user_func_array(array($helperInstance, $helper['method']), isset($helper['arguments']) ? $helper['arguments'] : array()); $handlebarView->assign($variable, $value); } } $this->handlebarTemplates[$templateName] = sprintf('<script type="text/x-handlebars" data-template-name="%s">%s</script>', $templateName, $handlebarView->render()); } return implode('', $this->handlebarTemplates); }