/**
  * @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);
 }
Beispiel #2
0
 /**
  * @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());
 }
Beispiel #3
0
 /**
  * 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 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 '';
 }
 /**
  * @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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
    /**
     * @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);
    }
 /**
  * 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;
 }
 /**
  * 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;
     }
 }
 /**
  * Get all fields from form
  *
  * @param Form $form
  * @param string $property
  * @param bool $htmlSpecialChars
  * @return array
  */
 public function render(Form $form, $property = 'title', $htmlSpecialChars = true)
 {
     $fields = [];
     foreach ($form->getPages() as $page) {
         foreach ($page->getFields() as $field) {
             $fieldProperty = ObjectAccess::getProperty($field, $property);
             if ($htmlSpecialChars) {
                 $fieldProperty = htmlspecialchars($fieldProperty);
             }
             $fields[] = $fieldProperty;
         }
     }
     return $fields;
 }
 /**
  * @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';
     $frontend = new TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], 1, 0);
     $frontend->cObj = new ContentObjectRenderer();
     $frontend->cObj->start($record);
     $this->performDummyRegistration();
     $controllerClassName = substr(get_class($this), 0, -4);
     /** @var AbstractFluxController $instance */
     $instance = $this->objectManager->get($controllerClassName);
     ObjectAccess::setProperty($instance, 'extensionName', 'Flux', TRUE);
     ObjectAccess::getProperty($instance, 'configurationManager', TRUE)->setContentObject($frontend->cObj);
     return $instance;
 }
Beispiel #16
0
 /**
  * Set properties of an object/array in cobj->LOAD_REGISTER which can then
  * be used to be loaded via TS with register:name
  *
  * @param string $properties comma separated list of properties
  * @param mixed $object object or array to get the properties
  * @param string $prefix optional prefix
  * @return void
  */
 public static function setRegisterProperties($properties, $object, $prefix = 'news')
 {
     if (!empty($properties) && !is_null($object)) {
         $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         $items = GeneralUtility::trimExplode(',', $properties, TRUE);
         $register = array();
         foreach ($items as $item) {
             $key = $prefix . ucfirst($item);
             try {
                 $register[$key] = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $item);
             } catch (\Exception $e) {
                 GeneralUtility::devLog($e->getMessage(), 'news', GeneralUtility::SYSLOG_SEVERITY_WARNING);
             }
         }
         $cObj->LOAD_REGISTER($register, '');
     }
 }
Beispiel #17
0
 /**
  * Groups the titles to their indexes
  *
  * @param $titles
  * @return array
  */
 protected function getAzGrouping($titles)
 {
     $groupings = [];
     $lastChar = '';
     foreach ($titles as $title) {
         // find titleField and get contents
         $objectTitle = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($title, $this->configuration['titleField']);
         $title->linkObject = [$this->configuration['linkObject'] => $title->getUid()];
         $firstLetter = $this->getSpecifiedLetter($objectTitle, 0);
         if ($firstLetter != $lastChar) {
             $groupings[$firstLetter] = [];
         }
         array_push($groupings[$firstLetter], $title);
         $lastChar = $this->getSpecifiedLetter($objectTitle, 0);
     }
     return $groupings;
 }
Beispiel #18
0
 /**
  * @param string $term
  * @return string
  */
 public function autocompleteAction($term)
 {
     $searchProperty = $this->widgetConfiguration['searchProperty'];
     $query = $this->widgetConfiguration['objects']->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));
     }
     $results = $query->execute();
     $output = [];
     foreach ($results as $singleResult) {
         $val = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($singleResult, $searchProperty);
         $output[] = ['id' => $val, 'label' => $val, 'value' => $val];
     }
     return json_encode($output);
 }
Beispiel #19
0
 /**
  * Set properties of an object/array in cobj->LOAD_REGISTER which can then
  * be used to be loaded via TS with register:name
  *
  * @param string $properties comma separated list of properties
  * @param mixed $object object or array to get the properties
  * @param string $prefix optional prefix
  * @return void
  */
 public static function setRegisterProperties($properties, $object, $prefix = 'news')
 {
     if (!empty($properties) && !is_null($object)) {
         /** @var ContentObjectRenderer $cObj */
         $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
         $items = GeneralUtility::trimExplode(',', $properties, true);
         $register = [];
         foreach ($items as $item) {
             $key = $prefix . ucfirst($item);
             try {
                 $register[$key] = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $item);
             } catch (\Exception $e) {
                 GeneralUtility::devLog($e->getMessage(), 'news', GeneralUtility::SYSLOG_SEVERITY_WARNING);
             }
         }
         $cObj->cObjGetSingle('LOAD_REGISTER', $register);
     }
 }
 /**
  * Sort the array.
  *
  * @param mixed $records
  * @param int $num
  * @param string $key
  *
  * @return mixed|null
  */
 private function sortArray($records, $num, $key = 'uid')
 {
     foreach ($records as $record) {
         if (is_array($record)) {
             $recordUid = $record[$key];
         } elseif ($record instanceof AbstractDomainObject) {
             $recordUid = ObjectAccess::getProperty($record, $key);
         } elseif (is_object($record)) {
             $recordUid = $record->{$key};
         } else {
             throw new UnexpectedValueException('It is not possible to get key of record');
         }
         if ((string) $recordUid === (string) $num) {
             return $record;
         }
     }
     return null;
 }
Beispiel #21
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an array
  */
 protected function transformObject($object, array $configuration)
 {
     if ($object instanceof \DateTime) {
         return $object->format(\DateTime::ISO8601);
     } else {
         $propertyNames = \TYPO3\CMS\Extbase\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\CMS\Extbase\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);
         }
         if (isset($configuration['_exposeClassName']) && ($configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED || $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_UNQUALIFIED)) {
             $className = get_class($object);
             $classNameParts = explode('\\', $className);
             $propertiesToRender['__class'] = $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED ? $className : array_pop($classNameParts);
         }
         return $propertiesToRender;
     }
 }
 /**
  * @test
  */
 public function canGetTemplateByActionName()
 {
     $templatePaths = $this->getFixtureTemplatePaths();
     $service = $this->createFluxServiceInstance();
     $viewContext = new ViewContext(NULL, 'Flux', 'Content');
     $viewContext->setTemplatePaths(new TemplatePaths($templatePaths));
     $view = $service->getPreparedExposedTemplateView($viewContext);
     $controllerContext = ObjectAccess::getProperty($view, 'controllerContext', TRUE);
     $controllerContext->getRequest()->setControllerActionName('dummy');
     $controllerContext->getRequest()->setControllerName('Content');
     $view->setControllerContext($controllerContext);
     $output = $view->getTemplatePathAndFilename('dummy');
     $this->assertNotEmpty($output);
     $this->assertFileExists($output);
 }
 /**
  * @test
  */
 public function canGetGridWhenItDoesNotExistAndStorageDoesNotExist()
 {
     $form = Form::create();
     $instance = $this->createMockedInstanceForVariableContainerTests();
     ObjectAccess::getProperty($instance, 'viewHelperVariableContainer', TRUE)->expects($this->any())->method('exists')->will($this->returnValue(FALSE));
     ObjectAccess::getProperty($instance, 'templateVariableContainer', TRUE)->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
     ObjectAccess::getProperty($instance, 'templateVariableContainer', TRUE)->expects($this->any())->method('get')->will($this->returnValue($form));
     $output = $this->callInaccessibleMethod($instance, 'getGrid');
     $this->assertInstanceOf('FluidTYPO3\\Flux\\Form\\Container\\Grid', $output);
 }
Beispiel #24
0
 /**
  * Converts an object based validation result to an array (can be used to
  * be converted for JSON usage).
  *
  * @param    Error\Result|Error\Result[] $validationResult The validation result you want to convert.
  * @return    array                        The converted result.
  */
 public static function convertValidationResultToArray($validationResult)
 {
     $validationResultArray = ['errors' => [], 'warnings' => [], 'notices' => []];
     foreach ($validationResultArray as $validationName => $validationValue) {
         $validationResultArray[$validationName] = [];
         if (!is_array($validationResult)) {
             $validationResult = [$validationResult];
         }
         foreach ($validationResult as $validatorResult) {
             /** @var Message[] $values */
             $values = ObjectAccess::getProperty($validatorResult, $validationName);
             foreach ($values as $value) {
                 $validationResultArray[$validationName][] = $value->render();
             }
         }
     }
     return $validationResultArray;
 }
 /**
  * @test
  */
 public function canUseFlexFormDataWhenPresent()
 {
     $instance = $this->canCreateInstanceOfCustomRegisteredController();
     $settings = array('settings' => array('test' => 'test'));
     ObjectAccess::setProperty($instance, 'data', $settings, TRUE);
     $this->callInaccessibleMethod($instance, 'initializeProvider');
     $this->callInaccessibleMethod($instance, 'initializeOverriddenSettings');
     $overriddenSettings = ObjectAccess::getProperty($instance, 'settings', TRUE);
     $this->assertEquals($settings['settings']['test'], $overriddenSettings['test']);
 }
Beispiel #26
0
 /**
  * @test
  */
 public function getPropertyCanAccessPropertiesOfAnArray()
 {
     $array = array('key' => 'value');
     $expected = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($array, 'key');
     $this->assertEquals($expected, 'value', 'getProperty does not work with Array property.');
 }
 /**
  * @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);
 }
Beispiel #28
0
 /**
  * @param QueryInterface $query
  * @return array
  */
 protected function addOptionsFromResults(QueryInterface $query)
 {
     $items = array();
     $results = $query->execute();
     $type = $query->getType();
     $table = strtolower(str_replace('\\', '_', $type));
     $propertyName = $this->getLabelPropertyName($table, $type);
     foreach ($results as $result) {
         $uid = $result->getUid();
         array_push($items, array(ObjectAccess::getProperty($result, $propertyName), $uid));
     }
     return $items;
 }
Beispiel #29
0
 /**
  * @param string $name
  * @param bool   $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;
             }
         }
     }
 }
Beispiel #30
0
 /**
  * Gets the value to use as sorting value from $object
  *
  * @param mixed $object
  * @return mixed
  */
 protected function getSortValue($object)
 {
     $field = $this->arguments['sortBy'];
     $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $field);
     if ($value instanceof \DateTime) {
         $value = $value->format('U');
     } elseif ($value instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage) {
         $value = $value->count();
     } elseif (is_array($value)) {
         $value = count($value);
     }
     return $value;
 }