Exemplo n.º 1
0
 /**
  * @param	string	$file	
  * @param	string	$data
  * @return	string
  */
 public static function composePackage($name, array $data, $isInit = false)
 {
     if (is_string($name)) {
         $name = new PkgName($name);
     } else {
         if (!$name instanceof PkgNameInterface) {
             $err = 'package name must be a string of an object that ';
             $err .= 'implements Appfuel\\Html\\Resource\\PkgNameInterface';
             throw new InvalidArgumentException($err);
         }
     }
     $pkg = ResourceTreeManager::getPkg($name);
     if (!$pkg) {
         $err = "could not compose pkg -({$name->getName()}) not found";
         throw new DomainException($err);
     }
     $vPath = ResourceTreeManager::getVendorPath($name->getVendor());
     $path = "{$vPath}/{$pkg->getMarkupFile()}";
     $finder = self::loadFileFinder();
     $absolute = $finder->getPath($path);
     if (!$finder->fileExists($absolute, false)) {
         $err = "template file not found at -({$absolute})";
         throw new DomainException($err, 404);
     }
     $compositor = self::loadFileCompositor();
     $view = $compositor->compose($absolute, $data);
     if ($pkg->isJsInitFile()) {
         $path = "{$vPath}/{$pkg->getJsInitFile()}";
         $absolute = $finder->getPath($path);
         if (!$finder->fileExists($absolute, false)) {
             $err = "template file not found at -({$absolute})";
             throw new DomainException($err, 404);
         }
         $init = $compositor->compose($absolute, $data);
         return array($view, $init);
     }
     return $view;
 }