/** * Set (override) the variable in $name. * * @param string $name * @param mixed $value * @return void */ public function render($name, $value = NULL) { if ($value === NULL) { $value = $this->renderChildren(); } if (FALSE === strpos($name, '.')) { if ($this->templateVariableContainer->exists($name) === TRUE) { $this->templateVariableContainer->remove($name); } $this->templateVariableContainer->add($name, $value); } elseif (1 == substr_count($name, '.')) { $parts = explode('.', $name); $objectName = array_shift($parts); $path = implode('.', $parts); if (FALSE === $this->templateVariableContainer->exists($objectName)) { return NULL; } $object = $this->templateVariableContainer->get($objectName); try { \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($object, $path, $value); // Note: re-insert the variable to ensure unreferenced values like arrays also get updated $this->templateVariableContainer->remove($objectName); $this->templateVariableContainer->add($objectName, $object); } catch (\Exception $error) { return NULL; } } return NULL; }
/** * Checks if object was changed or not * * @param object $object * @return bool */ public static function isDirtyObject($object) { foreach (array_keys($object->_getProperties()) as $propertyName) { try { $property = ObjectAccess::getProperty($object, $propertyName); } catch (PropertyNotAccessibleException $e) { // if property can not be accessed continue; } /** * std::Property (string, int, etc..), * PHP-Objects (DateTime, RecursiveIterator, etc...), * TYPO3-Objects (user, page, etc...) */ if (!$property instanceof ObjectStorage) { if ($object->_isDirty($propertyName)) { return true; } } else { /** * ObjectStorage */ if ($property->_isDirty()) { return true; } } } return false; }
/** * @test */ public function createsValidFieldInterfaceComponents() { $instance = $this->buildViewHelperInstance($this->defaultArguments); $instance->render(); $component = $instance->getComponent(ObjectAccess::getProperty($instance, 'renderingContext', TRUE), ObjectAccess::getProperty($instance, 'arguments', TRUE)); $this->assertInstanceOf('FluidTYPO3\\Flux\\Form\\WizardInterface', $component); }
/** * @param string $className * @param string $annotationName * @param string|boolean $propertyName * @return array|boolean */ public static function getAnnotationValueFromClass($className, $annotationName, $propertyName = NULL) { $reflection = new ClassReflection($className); $sample = new $className(); $annotations = array(); if (NULL === $propertyName) { if (FALSE === $reflection->isTaggedWith($annotationName)) { return FALSE; } $annotations = $reflection->getTagValues($annotationName); } elseif (FALSE === $propertyName) { $properties = ObjectAccess::getGettablePropertyNames($sample); foreach ($properties as $reflectedPropertyName) { if (FALSE === property_exists($className, $reflectedPropertyName)) { continue; } $propertyAnnotationValues = self::getPropertyAnnotations($reflection, $reflectedPropertyName, $annotationName); if (NULL !== $propertyAnnotationValues) { $annotations[$reflectedPropertyName] = $propertyAnnotationValues; } } } else { $annotations = self::getPropertyAnnotations($reflection, $propertyName, $annotationName); } $annotations = self::parseAnnotation($annotations); return NULL !== $propertyName && TRUE === isset($annotations[$propertyName]) ? $annotations[$propertyName] : $annotations; }
/** * @param ControllerPipe $instance * @param string $controllerClassName * @return mixed */ protected function performControllerExcecution(ControllerPipe $instance, $controllerClassName) { $controllerMock = $this->getMockForAbstractClass('FluidTYPO3\\Flux\\Controller\\AbstractFluxController', array(), $controllerClassName, TRUE, TRUE, TRUE, array('renderAction', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'canProcessRequest', 'mapRequestArgumentsToControllerArguments', 'checkRequestHash', 'buildControllerContext', 'setViewConfiguration', 'resolveView')); $controllerMock->expects($this->once())->method('initializeActionMethodArguments'); $controllerMock->expects($this->once())->method('initializeActionMethodValidators'); $controllerMock->expects($this->once())->method('renderAction')->will($this->returnValue($this->defaultData)); $controllerMock->expects($this->once())->method('canProcessRequest')->will($this->returnValue(TRUE)); $signalSlotDispatcherMock = $this->getMock('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher', array('dispatch')); $configurationManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('isFeatureEnabled')); $configurationManagerMock->expects($this->any())->method('isFeatureEnabled')->will($this->returnValue(TRUE)); $propertyMappingServiceMock = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfigurationService', array('initializePropertyMappingConfigurationFromRequest')); $argumentsMock = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('getIterator')); $argumentsMock->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array(new Argument('test', 'string'))))); ObjectAccess::setProperty($controllerMock, 'objectManager', $this->objectManager, TRUE); ObjectAccess::setProperty($controllerMock, 'configurationManager', $configurationManagerMock, TRUE); ObjectAccess::setProperty($controllerMock, 'mvcPropertyMappingConfigurationService', $propertyMappingServiceMock, TRUE); ObjectAccess::setProperty($controllerMock, 'arguments', $argumentsMock, TRUE); ObjectAccess::setProperty($controllerMock, 'signalSlotDispatcher', $signalSlotDispatcherMock, TRUE); $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get')); $response = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response', array('getContent')); $response->expects($this->once())->method('getContent')->will($this->returnValue($this->defaultData)); $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array('getControllerActionName', 'getMethodParameters', 'getDispatched')); $request->expects($this->at(0))->method('getDispatched')->will($this->returnValue(FALSE)); $request->expects($this->atLeastOnce())->method('getControllerActionName')->will($this->returnValue('render')); $dispatcherMock = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher', array('resolveController'), array($objectManagerMock)); ObjectAccess::setProperty($dispatcherMock, 'signalSlotDispatcher', $signalSlotDispatcherMock, TRUE); ObjectAccess::setProperty($dispatcherMock, 'objectManager', $this->objectManager, TRUE); $dispatcherMock->expects($this->once())->method('resolveController')->will($this->returnValue($controllerMock)); $objectManagerMock->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request')->will($this->returnValue($request)); $objectManagerMock->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response')->will($this->returnValue($response)); $objectManagerMock->expects($this->at(2))->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher')->will($this->returnValue($dispatcherMock)); ObjectAccess::setProperty($instance, 'objectManager', $objectManagerMock, TRUE); return $instance->conduct($this->defaultData); }
/** * @param \Iterator|\TYPO3\CMS\Extbase\DomainObject\AbstractEntity[] $iterator * @return array */ protected function getStructure($iterator) { $structure = array(); if (!$iterator instanceof \Iterator) { $iterator = array($iterator); } foreach ($iterator as $entity) { $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity)); $tableName = $dataMap->getTableName(); $identifier = $tableName . ':' . $entity->getUid(); $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties($entity); $structureItem = array(); foreach ($properties as $propertyName => $propertyValue) { $columnMap = $dataMap->getColumnMap($propertyName); if ($columnMap !== NULL) { $propertyName = $columnMap->getColumnName(); } if ($propertyValue instanceof \Iterator) { $structureItem[$propertyName] = $this->getStructure($propertyValue); } else { $structureItem[$propertyName] = $propertyValue; } } $structure[$identifier] = $structureItem; } return $structure; }
/** * @return mixed */ public function render() { $nodes = array(); foreach ($this->childViewHelperNodes as $viewHelperNode) { $viewHelper = $viewHelperNode->getUninitializedViewHelper(); $arguments = $viewHelper->prepareArguments(); $givenArguments = $viewHelperNode->getArguments(); $viewHelperReflection = new \ReflectionClass($viewHelper); $viewHelperDescription = $viewHelperReflection->getDocComment(); $viewHelperDescription = htmlentities($viewHelperDescription); $viewHelperDescription = '[CLASS DOC]' . LF . $viewHelperDescription . LF; $renderMethodDescription = $viewHelperReflection->getMethod('render')->getDocComment(); $renderMethodDescription = htmlentities($renderMethodDescription); $renderMethodDescription = implode(LF, array_map('trim', explode(LF, $renderMethodDescription))); $renderMethodDescription = '[RENDER METHOD DOC]' . LF . $renderMethodDescription . LF; $argumentDefinitions = array(); foreach ($arguments as &$argument) { $name = $argument->getName(); $argumentDefinitions[$name] = ObjectAccess::getGettableProperties($argument); } $sections = array($viewHelperDescription, DebuggerUtility::var_dump($argumentDefinitions, '[ARGUMENTS]', 4, TRUE, FALSE, TRUE), DebuggerUtility::var_dump($givenArguments, '[CURRENT ARGUMENTS]', 4, TRUE, FALSE, TRUE), $renderMethodDescription); array_push($nodes, implode(LF, $sections)); } return '<pre>' . implode(LF . LF, $nodes) . '</pre>'; }
/** * @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); }
/** * Processing the focus point crop (fallback to LocalCropScaleMaskHelper) * * @param TaskInterface $task * * @return array|NULL */ public function process(TaskInterface $task) { $configuration = $task->getConfiguration(); $crop = $configuration['crop'] ? json_decode($configuration['crop']) : null; if ($crop instanceof \stdClass && isset($crop->x)) { // if crop is enable release the process return parent::process($task); } $sourceFile = $task->getSourceFile(); try { if (self::$deepCheck === false) { self::$deepCheck = true; $ratio = $this->getCurrentRatioConfiguration(); $this->dimensionService->getRatio($ratio); $newFile = $this->focusCropService->getCroppedImageSrcByFile($sourceFile, $ratio); $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($newFile); $targetFile = $task->getTargetFile(); ObjectAccess::setProperty($targetFile, 'originalFile', $file, true); ObjectAccess::setProperty($targetFile, 'originalFileSha1', $file->getSha1(), true); ObjectAccess::setProperty($targetFile, 'storage', $file->getStorage(), true); ObjectAccess::setProperty($task, 'sourceFile', $file, true); ObjectAccess::setProperty($task, 'targetFile', $targetFile, true); } } catch (\Exception $ex) { } self::$deepCheck = false; return parent::process($task); }
/** * @test */ public function throwsErrorWhenNoTidyIsInstalled() { $instance = $this->createInstance(); ObjectAccess::setProperty($instance, 'hasTidy', FALSE, TRUE); $this->setExpectedException('RuntimeException', NULL, 1352059753); $instance->render('test', 'utf8'); }
/** * @test */ public function supportsForeignMatchFields() { $arguments = array('name' => 'test', 'foreignMatchFields' => array('test' => 'test')); $instance = $this->buildViewHelperInstance($arguments, array()); $component = $instance->getComponent(ObjectAccess::getProperty($instance, 'renderingContext', TRUE), ObjectAccess::getProperty($instance, 'arguments', TRUE)); $this->assertEquals($arguments['foreignMatchFields'], $component->getForeignMatchFields()); }
/** * @test */ public function supportsUseOfControllerAndActionSeparator() { $arguments = array('label' => 'Test field', 'controllerExtensionName' => 'Flux', 'pluginName' => 'API', 'controllerName' => 'Flux', 'actions' => array(), 'disableLocalLanguageLabels' => FALSE, 'excludeActions' => array(), 'localLanguageFileRelativePath' => '/Resources/Private/Language/locallang_db.xml', 'prefixOnRequiredArguments' => '*', 'subActions' => array(), 'separator' => ' :: '); $instance = $this->buildViewHelperInstance($arguments, array(), NULL, $arguments['extensionName'], $arguments['pluginName']); $instance->initializeArgumentsAndRender(); $component = $instance->getComponent(ObjectAccess::getProperty($instance, 'renderingContext', TRUE), ObjectAccess::getProperty($instance, 'arguments', TRUE)); $this->assertSame($arguments['separator'], $component->getSeparator()); }
/** * Get a Property from Field by given Marker and Form * * @param string $marker Field Marker * @param Form $form * @param string $property Field Property * @return string Property */ public function render($marker, Form $form, $property) { $field = $this->fieldRepository->findByMarkerAndForm($marker, $form->getUid()); if ($field !== null) { return ObjectAccess::getProperty($field, $property); } return ''; }
/** * @param array $settings * @return void */ public function loadSettings(array $settings) { foreach ($settings as $name => $value) { if (TRUE === property_exists($this, $name)) { ObjectAccess::setProperty($this, $name, $value); } } }
/** * 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; }
/** * @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)); } }
/** * @test */ public function canLoadSettings() { $instance = $this->createInstance(); $instance->loadSettings($this->defaultData); foreach ($this->defaultData as $propertyName => $propertyValue) { $result = ObjectAccess::getProperty($instance, $propertyName, TRUE); $this->assertEquals($propertyValue, $result); } }
/** * 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; }
/** * 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; }
/** * Extends a given default ControllerContext. * * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext * @return ControllerContext */ public static function extend(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $source) { $controllerContext = \TYPO3\CMS\Form\Utility\FormUtility::getObjectManager()->get(ControllerContext::class); $propertyNames = ObjectAccess::getGettableProperties($source); foreach ($propertyNames as $propertyName => $propertyValue) { ObjectAccess::setProperty($controllerContext, $propertyName, $propertyValue); } return $controllerContext; }
/** * Validates required properties and adds an error for * each empty property is empty * Expects an array with property names as keys and * error codes as values: * [ * <propertyName> => <errorCode> * ] * * @param $object * @param array $requiredProperties An array with property names and error codes * @return void * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException */ protected function validateRequiredProperties($object, $requiredProperties) { foreach ($requiredProperties as $propertyName => $errorCode) { $propertyValue = ObjectAccess::getProperty($object, $propertyName); if ($this->isEmpty($propertyValue)) { $this->addError($propertyName . ' is required.', $errorCode); } } }
/** * Load the property value to be used for validation. * * In case the object is a doctrine proxy, we need to load the real instance first. * * @param object $object * @param string $propertyName * @return mixed */ protected function getPropertyValue($object, $propertyName) { // TODO: add support for lazy loading proxies, if needed if (ObjectAccess::isPropertyGettable($object, $propertyName)) { return ObjectAccess::getProperty($object, $propertyName); } else { return ObjectAccess::getProperty($object, $propertyName, TRUE); } }
/** * @test * @dataProvider linkedDataProvider */ public function itemsAreAddedToContainer($subject, $predicate, $object, $objectType, $language, $name, $expected) { $this->fixture->setArguments(['subject' => $subject, 'predicate' => $predicate, 'object' => $object, 'objectType' => $objectType, 'language' => $language, 'name' => $name]); $this->templateVariableContainer->expects($this->once())->method('remove')->with($name); $this->templateVariableContainer->expects($this->once())->method('add')->with($name)->will($this->returnValue('')); ObjectAccess::setProperty($this->fixture, 'templateVariableContainer', $this->templateVariableContainer, true); $this->fixture->render(); $this->markTestIncomplete('Todo'); }
/** * Build array with countries * * @param string $key * @param string $value * @param string $sortbyField * @param string $sorting * @return array */ public function getCountries($key = 'isoCodeA3', $value = 'officialNameLocal', $sortbyField = 'isoCodeA3', $sorting = 'asc') { $countries = $this->countryRepository->findAllOrderedBy($sortbyField, $sorting); $countriesArray = []; foreach ($countries as $country) { /** @var $country \SJBR\StaticInfoTables\Domain\Model\Country */ $countriesArray[ObjectAccess::getProperty($country, $key)] = ObjectAccess::getProperty($country, $value); } return $countriesArray; }
/** * Solution for {outer.{inner}} call in fluid * * @param object|array $obj object or array * @param string $prop property name * @return mixed */ public function render($obj, $prop) { if (is_array($obj) && array_key_exists($prop, $obj)) { return $obj[$prop]; } if (is_object($obj)) { return ObjectAccess::getProperty($obj, GeneralUtility::underscoredToLowerCamelCase($prop)); } return null; }
/** * Renders the content. * * @param string $extensionName Render partial of this extension * @param string $partial The partial to render * @param array $arguments Arguments to pass to the partial * @return string */ public function render($extensionName, $partial = null, array $arguments = array()) { // Overload arguments with own extension local settings (to pass own settings to external partial) $arguments = $this->loadSettingsIntoArgumentsNonStatic($arguments); $oldPartialRootPaths = ObjectAccess::getProperty($this->viewHelperVariableContainer->getView(), 'partialRootPaths', true); $newPartialRootPaths = array(ExtensionManagementUtility::extPath($extensionName) . 'Resources/Private/Partials'); $this->viewHelperVariableContainer->getView()->setPartialRootPaths($newPartialRootPaths); $content = $this->viewHelperVariableContainer->getView()->renderPartial($partial, null, $arguments); $this->viewHelperVariableContainer->getView()->setPartialRootPaths($oldPartialRootPaths); return $content; }
/** * @test */ public function canTidySourceFromArgument() { $instance = $this->createInstance(); if (FALSE === ObjectAccess::getProperty($instance, 'hasTidy', TRUE)) { return; } $source = '<foo> <bar> </bar> </foo>'; $test = $this->executeViewHelper(array('content' => $source)); $this->assertNotSame($source, $test); }
/** * action update * * @param User $user * @validate $user In2code\Femanager\Domain\Validator\ServersideValidator * @validate $user In2code\Femanager\Domain\Validator\CaptchaValidator * @return void */ public function updateAction(\Gigabonus\Gbfemanager\Domain\Model\User $user = null) { if ($user !== NULL && $GLOBALS['TSFE']->fe_user->user['uid'] == $user->getUid()) { $telephonelastchanged = ObjectAccess::getProperty($user, 'txGbfemanagerTelephonelastchanged'); $user->setTxGbfemanagerTelephonelastchanged(time()); parent::updateAction($user); } else { // Versuch die uid im FireBug oder Ähnlichem zu manipulieren exit; } }
/** * @return AbstractFluxController */ protected function createAndTestDummyControllerInstance() { $record = Records::$contentRecordWithoutParentAndWithoutChildren; $record['pi_flexform'] = Xml::SIMPLE_FLEXFORM_SOURCE_DEFAULT_SHEET_ONE_FIELD; $record['tx_fed_fcefile'] = 'Flux:Default.html'; $this->performDummyRegistration(); $controllerClassName = 'FluidTYPO3\\Flux\\Controller\\ContentController'; /** @var AbstractFluxController $instance */ $instance = $this->objectManager->get($controllerClassName); ObjectAccess::setProperty($instance, 'extensionName', 'Flux', TRUE); return $instance; }
/** * @dataProvider getRenderTestValues * @param array $arguments * @param mixed $selectedValue * @param mixed $content * @param string $expected */ public function testRender(array $arguments, $selectedValue, $content, $expected) { $instance = $this->buildViewHelperInstance($arguments, array(), NULL, 'Vhs'); $viewHelperVariableContainer = new ViewHelperVariableContainer(); $viewHelperVariableContainer->add('FluidTYPO3\\Vhs\\ViewHelpers\\Form\\SelectViewHelper', 'options', array()); $viewHelperVariableContainer->add('FluidTYPO3\\Vhs\\ViewHelpers\\Form\\SelectViewHelper', 'value', $selectedValue); ObjectAccess::setProperty($instance, 'viewHelperVariableContainer', $viewHelperVariableContainer, TRUE); $instance->setArguments($arguments); $instance->setRenderChildrenClosure(function () use($content) { return $content; }); $result = $instance->render(); $this->assertEquals($expected, $result); }