public static function getServiceRegistry($selector)
 {
     $serviceRegistry = parse_ini_file(RequestHandler::GetBaseDirectory() . "/ini/serviceRegistry.ini", true);
     if (array_key_exists($selector, $serviceRegistry)) {
         return $serviceRegistry[$selector];
     }
     return null;
 }
Exemplo n.º 2
0
 public function display($data, $template)
 {
     header("generatedBy: Tracy Lauren");
     header("Framework: Utopia Framework");
     if (!isset($_REQUEST['__outmode'])) {
         $_REQUEST['__outmode'] = 'render';
     }
     switch ($_REQUEST['__outmode']) {
         case 'xml':
             // this requires the pear XML_Serializer package to be installed
             // to install run the following command: "pear install XML_Serializer-beta"
             require_once "XML/Serializer.php";
             header('Content-Type: text/xml');
             $serializer = new XML_Serializer(array("indent" => "\t", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8", "rootName" => "result", "defaultTagName" => "item"));
             $result = $serializer->serialize($data);
             if ($result === true) {
                 echo $serializer->getSerializedData();
             } else {
                 throw new BadRequestException("Failed to serialize data to XML");
             }
             break;
         case 'json':
             header('Content-Type: text/plain');
             $__json = json_encode($data);
             if (json_last_error() != JSON_ERROR_NONE && strlen($__json) == 0) {
                 throw new BadRequestException("Failed to serialize data to JSON");
             }
             print $__json;
             break;
         default:
             $templateChain = array('default');
             $browser = new Browser();
             if (in_array($browser->getBrowser(), array(Browser::BROWSER_IPHONE, Browser::BROWSER_IPOD, Browser::BROWSER_IPAD))) {
                 $templateChain[] = 'mobile';
             }
             extract($data);
             foreach (array_reverse($templateChain) as $templateRoot) {
                 if (file_exists(RequestHandler::GetBaseDirectory() . 'templates/' . $templateRoot . '/' . $template)) {
                     include RequestHandler::GetBaseDirectory() . 'templates/' . $templateRoot . '/' . $template;
                     // only include the first template that was found in the chain
                     break;
                 }
             }
             break;
     }
     // this function is only allowed to be called once, and is the final step in a request
     exit;
 }