Created
June 4, 2010 15:39
-
-
Save skurfuerst/425564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns the content specified by $locale. | |
* | |
* This function tries to return a content object which strictly matches the locale of the given | |
* context. If no such content exists it will try to find a content object which is suggested by | |
* the context's fallback strategy. | |
* | |
* @param \F3\TYPO3\Domain\Service\ContentContext $contentContext Context the content should match | |
* @return \F3\TYPO3\Domain\Model\Content\ContentInterface The content object or NULL if none matched the given context | |
* @author Robert Lemke <rober@typo3.org> | |
*/ | |
public function getContent(\F3\TYPO3\Domain\Service\ContentContext $contentContext) { | |
$locale = $contentContext->getLocale(); | |
$language = $locale->getLanguage(); | |
$region = $locale->getRegion(); | |
if (isset($this->contents[$language]) && isset($this->contents[$language][$region])) { | |
return $this->contents[$language][$region]; | |
} | |
return NULL; | |
} | |
static public function getGettablePropertyNames($object) { | |
if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1237301369); | |
$declaredPropertyNames = array_keys(get_class_vars(get_class($object))); | |
foreach (get_class_methods($object) as $methodName) { | |
if (is_callable(array($object, $methodName))) { | |
if (substr($methodName, 0, 2) === 'is') { | |
$declaredPropertyNames[] = lcfirst(substr($methodName, 2)); | |
} | |
if (substr($methodName, 0, 3) === 'get') { | |
$reflectionMethod = new \ReflectionMethod(get_class($object), $methodName); | |
if ($reflectionMethod->getNumberOfRequiredParameters() === 0) { | |
$declaredPropertyNames[] = lcfirst(substr($methodName, 3)); | |
} | |
} | |
} | |
} | |
$propertyNames = array_unique($declaredPropertyNames); | |
sort($propertyNames); | |
return $propertyNames; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment