/** * @param string $propertyName * @param mixed $object * @return mixed */ public function render($propertyName, $subject = NULL) { if ($subject === NULL) { $subject = $this->renderChildren(); } return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($subject, $propertyName); }
/** * Render the option tags. * * @param $optionOverride added by nnaddress * @return array an associative array of options, key will be the value of the option tag */ protected function getOptions($optionOverride = NULL) { if (!$this->arguments['renderSubGroups']) { return parent::getOptions(); } if (!is_array($this->arguments['options']) && !$this->arguments['options'] instanceof \Traversable) { return array(); } $options = array(); $optionsArgument = $optionOverride ? $optionOverride : $this->arguments['options']; foreach ($optionsArgument as $key => $value) { if (is_object($value)) { // Added by NN Address $childOptions = $this->getOptions($value->getChildGroups()); if ($this->hasArgument('optionValueField')) { $key = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionValueField']); if (is_object($key)) { if (method_exists($key, '__toString')) { $key = (string) $key; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428); } } // TODO: use $this->persistenceManager->isNewObject() once it is implemented } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) { $key = $this->persistenceManager->getIdentifierByObject($value); } elseif (method_exists($value, '__toString')) { $key = (string) $value; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('No identifying value for object of class "' . get_class($value) . '" found.', 1247826696); } if ($this->hasArgument('optionLabelField')) { $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionLabelField']); if (is_object($value)) { if (method_exists($value, '__toString')) { $value = (string) $value; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Label value for object of class "' . get_class($value) . '" was an object without a __toString() method.', 1247827553); } } } elseif (method_exists($value, '__toString')) { $value = (string) $value; // TODO: use $this->persistenceManager->isNewObject() once it is implemented } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) { $value = $this->persistenceManager->getIdentifierByObject($value); } } $options[$key] = $value; // Added by NN Address if (sizeof($childOptions) > 0) { $options = $options + $childOptions; } } if ($this->arguments['sortByOptionLabel']) { asort($options, SORT_LOCALE_STRING); } return $options; }
/** * Filter an item/value according to desired filter. Returns TRUE if * the item should be included, FALSE otherwise. This default method * simply does a weak comparison (==) for sameness. * * @param mixed $item * @param mixed $filter Could be a single value or an Array. If so the function returns TRUE when $item matches with any value in it. * @param string $propertyName * @return boolean */ protected function filter($item, $filter, $propertyName) { if (FALSE === empty($propertyName) && (TRUE === is_object($item) || TRUE === is_array($item))) { $value = ObjectAccess::getPropertyPath($item, $propertyName); } else { $value = $item; } return is_array($filter) ? in_array($value, $filter) : $value == $filter; }
/** * @param string $name * @return string */ public function render($name) { if (strpos($name, '.') === FALSE) { return $this->templateVariableContainer->get($name); } else { $parts = explode('.', $name); return ObjectAccess::getPropertyPath($this->templateVariableContainer->get(array_shift($parts)), implode('.', $parts)); } }
/** * Returns the settings at path $path, which is separated by ".", * e.g. "pages.uid". * "pages.uid" would return $this->settings['pages']['uid']. * * If the path is invalid or no entry is found, false is returned. * * @param string $path * @return mixed */ public function getByPath($path) { $configuration = $this->getConfiguration(); $setting = ObjectAccess::getPropertyPath($configuration, $path); if ($setting === NULL) { $setting = ObjectAccess::getPropertyPath($configuration['settings'], $path); } return $setting; }
/** * @param array $objects * @param array $propertyNames * @return string */ public function convertFromArray(array $objects, array $propertyNames) { $result = ''; $columnNames = array(); foreach ($propertyNames as $propertyName) { $columnNames[] = $this->escapeValue($propertyName); } $result .= implode(';', $columnNames) . chr(10); foreach ($objects as $object) { $cells = array(); foreach ($propertyNames as $propertyName) { $cells[] = $this->escapeValue(ObjectAccess::getPropertyPath($object, $propertyName)); } $result .= implode(';', $cells) . chr(10); } return $result; }
/** * @return ImageRendererConfiguration */ public function __construct() { if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fluid_styled_responsive_images'])) { $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fluid_styled_responsive_images']); if (!is_array($extensionConfiguration)) { $extensionConfiguration = ['enableSmallDefaultImage' => true]; } $this->extensionConfiguration = filter_var_array($extensionConfiguration, ['enableSmallDefaultImage' => FILTER_VALIDATE_BOOLEAN], false); } $this->settings = []; $this->typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class); $this->tagBuilder = GeneralUtility::makeInstance(TagBuilder::class); $configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($this->getTypoScriptSetup()); $settings = ObjectAccess::getPropertyPath($configuration, 'tt_content.textmedia.settings.responsive_image_rendering'); $settings = is_array($settings) ? $settings : []; $this->settings['layoutKey'] = isset($settings['layoutKey']) ? $settings['layoutKey'] : 'default'; $this->settings['sourceCollection'] = isset($settings['sourceCollection']) && is_array($settings['sourceCollection']) ? $settings['sourceCollection'] : []; }
/** * @param string $qualifiedExtensionName * @return array */ protected function getTypoScriptOverrides($qualifiedExtensionName) { if (static::$overrides === NULL) { $collected = array(); $typoScript = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface')->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); foreach ((array) ObjectAccess::getPropertyPath($typoScript, 'plugin') as $prefix => $pluginSettings) { if (!empty($pluginSettings['package'])) { $collected[substr($prefix, 3)] = $pluginSettings['package']; } } static::$overrides = $collected; } $packageSignature = ExtensionNamingUtility::getExtensionSignature($qualifiedExtensionName); if (!empty(static::$overrides[$packageSignature])) { return static::$overrides[$packageSignature]; } return array(); }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $extensionKey = $arguments['extensionKey']; $path = $arguments['path']; if (null === $extensionKey) { $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (!array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return null; } elseif (!array_key_exists($extensionKey, static::$configurations)) { $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); static::$configurations[$extensionKey] = GeneralUtility::removeDotsFromTS($extConf); } if (!$path) { return static::$configurations[$extensionKey]; } return ObjectAccess::getPropertyPath(static::$configurations[$extensionKey], $path); }
/** * @param string $name * @param boolean $useRawKeys * @return mixed */ public function render($name, $useRawKeys = FALSE) { if (FALSE === strpos($name, '.')) { if (TRUE === $this->templateVariableContainer->exists($name)) { return $this->templateVariableContainer->get($name); } } else { $segments = explode('.', $name); $lastSegment = array_shift($segments); $templateVariableRootName = $lastSegment; if (TRUE === $this->templateVariableContainer->exists($templateVariableRootName)) { $templateVariableRoot = $this->templateVariableContainer->get($templateVariableRootName); if (TRUE === $useRawKeys) { return ObjectAccess::getPropertyPath($templateVariableRoot, implode('.', $segments)); } try { $value = $templateVariableRoot; foreach ($segments as $segment) { if (TRUE === ctype_digit($segment)) { $segment = intval($segment); $index = 0; // Note: this loop approach is not a stupid solution. If you doubt this, // attempt to feth a number at a numeric index from ObjectStorage ;) foreach ($value as $possibleValue) { if ($index === $segment) { $value = $possibleValue; break; } ++$index; } continue; } $value = ObjectAccess::getProperty($value, $segment); } return $value; } catch (\Exception $e) { return NULL; } } } return NULL; }
/** * Build a option array. * * @param string $key * @param string $value * @return array an associative array of an option, key will be the value of the option tag */ protected function getOption($key, $value) { $option = array(); if (is_object($value) || is_array($value)) { if ($this->hasArgument('optionValueField')) { $key = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionValueField']); if (is_object($key)) { if (method_exists($key, '__toString')) { $key = (string) $key; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428); } } // @todo use $this->persistenceManager->isNewObject() once it is implemented } elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) { $key = $this->persistenceManager->getIdentifierByObject($value); } elseif (method_exists($value, '__toString')) { $key = (string) $value; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('No identifying value for object of class "' . get_class($value) . '" found.', 1247826696); } if ($this->hasArgument('optionLabelField')) { $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionLabelField']); if (is_object($value)) { if (method_exists($value, '__toString')) { $value = (string) $value; } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Label value for object of class "' . get_class($value) . '" was an object without a __toString() method.', 1247827553); } } } elseif (method_exists($value, '__toString')) { $value = (string) $value; // @todo use $this->persistenceManager->isNewObject() once it is implemented } elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) { $value = $this->persistenceManager->getIdentifierByObject($value); } } $option[$key] = $value; return $option; }
/** * @return string */ public function render() { $value = NULL; if ($this->arguments['object']) { if ($this->arguments['attribute']) { $getter = 'get' . ucfirst($this->arguments['attribute']); } else { $getter = $this->arguments['getter']; } if ($getter && is_object($this->arguments['object']) && method_exists($this->arguments['object'], $getter)) { $value = call_user_func(array($this->arguments['object'], $getter)); } else { $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($this->arguments['object'], $this->arguments['attribute']); } } if ($this->arguments['as']) { $variableNameArr = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $this->arguments['as'], TRUE, 2); $variableName = $variableNameArr[0]; $attributePath = $variableNameArr[1]; if ($this->templateVariableContainer->exists($variableName)) { $oldValue = $this->templateVariableContainer->get($variableName); $this->templateVariableContainer->remove($variableName); } if ($attributePath) { if ($oldValue && is_array($oldValue)) { $templateValue = $oldValue; $templateValue[$attributePath] = $value; } else { $templateValue = array($attributePath => $value); } } else { $templateValue = $value; } $this->templateVariableContainer->add($variableName, $templateValue); return ''; } else { return $value; } }
/** * Groups the given array by the specified groupBy property. * * @param array $elements The array / traversable object to be grouped * @param string $groupBy Group by this property * @return array The grouped array in the form array('keys' => array('key1' => [key1value], 'key2' => [key2value], ...), 'values' => array('key1' => array([key1value] => [element1]), ...), ...) * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception */ protected function groupElements(array $elements, $groupBy) { $groups = array('keys' => array(), 'values' => array()); foreach ($elements as $key => $value) { if (is_array($value)) { $currentGroupIndex = isset($value[$groupBy]) ? $value[$groupBy] : NULL; } elseif (is_object($value)) { $currentGroupIndex = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $groupBy); } else { throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('GroupedForViewHelper only supports multi-dimensional arrays and objects', 1253120365); } $currentGroupKeyValue = $currentGroupIndex; if (is_object($currentGroupIndex)) { if ($currentGroupIndex instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) { $currentGroupIndex = $currentGroupIndex->_loadRealInstance(); } $currentGroupIndex = spl_object_hash($currentGroupIndex); } $groups['keys'][$currentGroupIndex] = $currentGroupKeyValue; $groups['values'][$currentGroupIndex][$key] = $value; } return $groups; }
/** * Recursively extract the key * * @param \Traversable $iterator * @param string $key * @return string * @throws \Exception */ public function recursivelyExtractKey($iterator, $key) { $content = array(); foreach ($iterator as $k => $v) { // Lets see if we find something directly: $result = ObjectAccess::getPropertyPath($v, $key); if (NULL !== $result) { $content[] = $result; } elseif (TRUE === is_array($v) || TRUE === $v instanceof \Traversable) { $content[] = $this->recursivelyExtractKey($v, $key); } } $content = $this->flattenArray($content); return $content; }
/** * @param string $name * @return mixed */ public function getVariable($name) { return ObjectAccess::getPropertyPath($this->variables, $name); }
/** * @test */ public function getPropertyPathReturnsNullIfSubjectOnPathIsNoObject() { $object = new \stdClass(); $object->foo = 'Hello World'; $this->assertNull(\TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($object, 'foo.bar')); }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { return ObjectAccess::getPropertyPath($renderingContext->getTemplateVariableContainer()->getAll(), $arguments['name']); }
/** * @param array $inheritedConfiguration * @param string $propertyPath * @return mixed */ protected function getInheritedPropertyValueByDottedPath($inheritedConfiguration, $propertyPath) { if (true === empty($propertyPath)) { return null; } elseif (false === strpos($propertyPath, '.')) { if (isset($inheritedConfiguration[$propertyPath])) { return ObjectAccess::getProperty($inheritedConfiguration, $propertyPath); } return null; } return ObjectAccess::getPropertyPath($inheritedConfiguration, $propertyPath); }
/** * @param array $row * @param string $propertyPath * @return mixed */ protected function getInheritedPropertyValueByDottedPath(array $row, $propertyPath) { $tree = $this->getInheritanceTree($row); $inheritedConfiguration = $this->getMergedConfiguration($tree); if (FALSE === strpos($propertyPath, '.')) { return TRUE === isset($inheritedConfiguration[$propertyPath]) ? ObjectAccess::getProperty($inheritedConfiguration, $propertyPath) : NULL; } return ObjectAccess::getPropertyPath($inheritedConfiguration, $propertyPath); }
/** * Gets the value/array from global TypoScript by * dotted path expression. * * @param string $path * @return array */ public function getTypoScriptByPath($path) { $typoScript = $this->getAllTypoScript(); return (array) ObjectAccess::getPropertyPath($typoScript, $path); }
/** * Get a variable by dotted path expression, retrieving the * variable from nested arrays/objects one segment at a time. * If the second argument is provided, it must be an array of * accessor names which can be used to extract each value in * the dotted path. * * @param string $path * @param array $accessors * @return mixed */ public function getByPath($path, array $accessors = []) { return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($this->variables, $path); }
/** * Read the option called $optionName from $this->options, and parse {...} * as object accessors. * * Then translate the value. * * If $optionName was not found, the corresponding default option is returned (from $this->defaultOptions) * * @param string $optionName * @return string|array|null * @api */ protected function parseOption(string $optionName) { if ($optionName === 'translation') { return null; } $optionValue = ArrayUtility::getValueByPath($this->options, $optionName); $defaultValue = ArrayUtility::getValueByPath($this->defaultOptions, $optionName); if ($optionValue === null && $defaultValue !== null) { $optionValue = $defaultValue; } if ($optionValue === null) { return null; } if (is_array($optionValue)) { return $optionValue; } $formRuntime = $this->finisherContext->getFormRuntime(); $optionToCompare = $optionValue; // You can encapsulate a option value with {}. // This enables you to access every getable property from the // TYPO3\CMS\Form\Domain\Runtime. // // For example: {formState.formValues.<elemenIdentifier>} // This is equal to "$formRuntime->getFormState()->getFormValues()[<elemenIdentifier>]" $optionValue = preg_replace_callback('/{([^}]+)}/', function ($match) use($formRuntime) { return ObjectAccess::getPropertyPath($formRuntime, $match[1]); }, $optionValue); if ($optionToCompare === $optionValue) { // This is just a shortcut for a {formState.formValues.<elementIdentifier>} notation. // If one of the finisher option values is equal // to a identifier from the form definition then // the value of the submitted form element is used // insteed. // Lets say you have a textfield in your form with the // identifier "Text1". If you put "Text1" // in the email finisher option "subject" then the submited value // from the "Text1" element is used as the email subject. $formValues = $this->finisherContext->getFormValues(); if (!is_bool($optionValue) && array_key_exists($optionValue, $formValues)) { $optionValue = $formRuntime[$optionValue]; } } if (isset($this->options['translation']['translationFile'])) { $optionValue = TranslationService::getInstance()->translateFinisherOption($formRuntime, $this->finisherIdentifier, $optionName, $optionValue, $this->options['translation']); } if (empty($optionValue)) { if ($defaultValue !== null) { $optionValue = $defaultValue; } } return $optionValue; }
/** * Gets the value to use as sorting value from $object * * @param mixed $object * @return mixed */ protected function getSortValue($object) { $field = $this->arguments['sortBy']; $value = ObjectAccess::getPropertyPath($object, $field); if (TRUE === $value instanceof \DateTime) { $value = intval($value->format('U')); } elseif (TRUE === $value instanceof ObjectStorage || TRUE === $value instanceof LazyObjectStorage) { $value = $value->count(); } elseif (is_array($value)) { $value = count($value); } return $value; }
/** * Shorthand helper for getting setting values with optional default values * * Any setting value is automatically processed via stdWrap if configured. * * @param string $settingPath Path to the setting, e.g. "foo.bar.qux" * @param mixed $defaultValue Default value if no value is set * @return mixed */ protected function getSettingValue($settingPath, $defaultValue = NULL) { $value = ObjectAccess::getPropertyPath($this->settings, $settingPath); $stdWrapConfiguration = ObjectAccess::getPropertyPath($this->settings, $settingPath . '.stdWrap'); if ($stdWrapConfiguration !== NULL) { $value = $this->getFrontendController()->cObj->stdWrap($value, $stdWrapConfiguration); } // Change type of value to type of default value if possible if (!empty($value) && $defaultValue !== NULL) { settype($value, gettype($defaultValue)); } $value = !empty($value) ? $value : $defaultValue; return $value; }
/** * @param string $name * @return mixed */ public function getOption($name) { return ObjectAccess::getPropertyPath($this->options, $name); }
/** * Returns the settings at path $path, which is separated by ".", * e.g. "pages.uid". * "pages.uid" would return $this->settings['pages']['uid']. * * If the path is invalid or no entry is found, false is returned. * * @param string $path * @return mixed */ public function getByPath($path) { return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($this->getSettings(), $path); }
/** * 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 \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($valueElement, $this->arguments['optionValueField']); } else { // @todo use $this->persistenceManager->isNewObject() once it is implemented if ($this->persistenceManager->getIdentifierByObject($valueElement) !== NULL) { return $this->persistenceManager->getIdentifierByObject($valueElement); } else { return (string) $valueElement; } } } else { return $valueElement; } }
/** * Get the current property of the object bound to this form. * * @return mixed Value */ protected function getPropertyValue() { if (!$this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject')) { return null; } $formObject = $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'); $propertyName = $this->arguments['property']; if (is_array($formObject)) { return isset($formObject[$propertyName]) ? $formObject[$propertyName] : null; } return ObjectAccess::getPropertyPath($formObject, $propertyName); }
/** * Get the current property of the object bound to this form. * * @return mixed Value */ protected function getPropertyValue() { if (!$this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject')) { return null; } $formObject = $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'); return ObjectAccess::getPropertyPath($formObject, $this->arguments['property']); }
/** * @return void */ protected function getConfiguration() { $configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($this->getTypoScriptSetup()); $settings = ObjectAccess::getPropertyPath($configuration, 'tt_content.textmedia.settings.responsive_image_rendering'); $settings = is_array($settings) ? $settings : []; $this->settings['layoutKey'] = isset($settings['layoutKey']) ? $settings['layoutKey'] : 'default'; $this->settings['sourceCollection'] = isset($settings['sourceCollection']) && is_array($settings['sourceCollection']) ? $settings['sourceCollection'] : []; $this->absRefPrefix = ObjectAccess::getPropertyPath($configuration, 'config.absRefPrefix') ?: ''; }