protected function getPrefixedResourceTemplateName($templateName, $templateNamePrefix = NULL) { $templateName = preg_replace_callback('/\\/(.*)/', function ($matches) { return strtolower($matches[0]); }, $templateName); if ($templateNamePrefix !== NULL) { $templateName = $templateNamePrefix . $templateName; } return \Radmiraal\Emberjs\Utility\EmberDataUtility::uncamelize($templateName); }
/** * @dataProvider camelcasedNames * @test * * @param string $camelCasedName * @param string $expectedOutput * @return void */ public function uncamelizeSplitsAtHumpsAndReturnsUnderscoredLowercase($camelCasedName, $expectedOutput) { $this->assertEquals($expectedOutput, EmberDataUtility::uncamelize($camelCasedName)); }
/** * 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 * @param boolean $onlyIdentifier * @return array Object structure as an array * @todo implement sideloading */ protected function transformObject($object, array $configuration, $onlyIdentifier = TRUE) { if ($object instanceof \DateTime) { return $object->format('Y-m-d\\TH:i:s'); } elseif ($onlyIdentifier === TRUE) { $objectIdentifier = $this->persistenceManager->getIdentifierByObject($object); if ($objectIdentifier === NULL && method_exists($object, 'getId')) { $objectIdentifier = $object->getId(); } return $objectIdentifier; } else { $transformedObject = array(); if ($this->excludeIdentifier === FALSE) { $objectIdentifier = $this->persistenceManager->getIdentifierByObject($object); $transformedObject['id'] = $objectIdentifier; } $propertyNames = ObjectAccess::getGettablePropertyNames($object); foreach ($propertyNames as $propertyName) { if (substr($propertyName, 0, 1) !== '_') { if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) { continue; } if ($this->propertyIsExcluded($propertyName, $configuration)) { continue; } $propertyValue = ObjectAccess::getProperty($object, $propertyName); $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object)); if (!$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Transient')) { if (is_array($propertyValue) || $propertyValue instanceof \ArrayAccess) { $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $this->transformValue($propertyValue, array()); } elseif ($propertyValue instanceof \DateTime) { $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $propertyValue->format('Y-m-d\\TH:i:s'); } elseif (is_object($propertyValue)) { $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object)); if ($this->objectManager->getScope($objectName) !== \TYPO3\Flow\Object\Configuration\Configuration::SCOPE_SINGLETON) { $transformedObject[EmberDataUtility::uncamelize($propertyName) . '_id'] = $this->persistenceManager->getIdentifierByObject($propertyValue); if (isset($configuration['sideloadedAssociations']) && in_array($propertyName, $configuration['sideloadedAssociations'])) { // sideload this propertyvalue } } } else { $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $propertyValue; } } } } return $transformedObject; } }