Exemple #1
0
 /**
  *
  * @param string $name
  * @param array $depend
  * @return App
  */
 public static function module($name, array $depend = [])
 {
     $app = new App($name);
     // Configure the main app
     if (self::$firstLoad !== true) {
         $docRoot = Pie::find('$server.DOCUMENT_ROOT');
         // Attempt to load default config
         if (is_file($docRoot . '/../config.ini')) {
             Env::loadFromFile($docRoot . '/../config.ini');
         }
         // Create the root scope
         Pie::$rootScope = new RootScope();
         // Initiate common services
         $app->service('request', new Request());
         $app->service('validation', new Validation());
         $app->service('env', new Env());
         $app->service('rootScope', Pie::$rootScope);
         self::$firstLoad = true;
     }
     $app->addDepndencies($depend);
     return $app;
 }
Exemple #2
0
 public function executeController(App $parent, Controller $controller)
 {
     $result = $parent->execController($controller);
     $displayAs = null;
     if (isset($controller->settings['displayAs'])) {
         $displayAs = isset($controller->settings['displayAs']);
     } elseif (isset($this->getAlways()['displayAs'])) {
         $displayAs = $this->getAlways()['displayAs'];
     }
     if ($displayAs !== null) {
         switch ($displayAs) {
             case 'json':
                 header('Content-Type: application/json');
                 echo json_encode($result);
                 break;
             case 'xml':
                 $xml = new SimpleXMLElement('<root/>');
                 array_walk_recursive($result, array($xml, 'addChild'));
                 header('Content-Type: application/xml');
                 echo $xml->asXML();
                 break;
             default:
                 echo $result;
                 break;
         }
     }
 }