Esempio n. 1
0
 public function generateRequests(ParametersManager $parManager)
 {
     $webpages = $parManager->getChordParameters('fminor', 'webpage');
     $requests = array();
     foreach ($webpages as $key => $webpage) {
         foreach ($webpage['parts'] as $part) {
             if (!$parManager->hasFeatureById($part, 'embeddedable')) {
                 throw new \InvalidArgumentException('parts should support be embeddedable');
             }
         }
         $requests[] = $this->createRoute($key, $webpage);
         $requests[] = $this->createController($key, $webpage);
         $requests[] = $this->createTemplate($key, $webpage);
     }
     return $requests;
 }
Esempio n. 2
0
 public function generateRequests(ParametersManager $parManager)
 {
     $sections = $parManager->getChordParameters('fminor', 'section');
     $twig = new TwigEngine(__DIR__);
     $requests = array();
     foreach ($sections as $key => $section) {
         foreach ($section['parts'] as $part) {
             if (!$parManager->hasFeatureById($part, 'embeddedable')) {
                 throw new \InvalidArgumentException('parts should support be embeddedable');
             }
         }
         $request = new TemplateRequest();
         $type = $section['inline'] === true ? TemplateRequest::INLINE : TemplateRequest::INCLUDED;
         $request->setId('fminor.section.' . $key)->setType($type)->setContent($twig->render('section.php.twig', array('name' => $key, 'parts' => $section['parts'])));
         $requests[] = $request;
     }
     return $requests;
 }
Esempio n. 3
0
 public function generateRequests(ParametersManager $parManager)
 {
     $menus = $parManager->getChordParameters('fminor', 'menu');
     $twig = new TwigEngine(__DIR__);
     $project = $parManager->getBaseParameter('project_name');
     $requests = array();
     foreach ($menus as $key => $menu) {
         foreach ($menu['parts'] as $menuPart) {
             if ($menuPart['type'] === 'links') {
                 foreach ($menuPart['parts'] as $part) {
                     if ($part['type'] === 'link') {
                         if (!$parManager->hasFeatureById($part['part'], 'linkable')) {
                             throw new \InvalidArgumentException("part in a link group of menu {$key} should support be linkable");
                         }
                     } elseif ($part['type'] === 'dropdown') {
                         foreach ($part['parts'] as $link) {
                             if (!$parManager->hasFeatureById($link['part'], 'linkable')) {
                                 throw new \InvalidArgumentException("part in a dropdown of menu {$key} should support be linkable");
                             }
                         }
                     }
                 }
             } elseif ($menuPart['type'] === 'embedded') {
                 if (!$parManager->hasFeatureById($menuPart['part'], 'embeddedable')) {
                     throw new \InvalidArgumentException("part type embedded in menu {$key} should support be embeddedable");
                 }
             }
         }
         $request = new TemplateRequest();
         $type = $menu['inline'] === true ? TemplateRequest::INLINE : TemplateRequest::INCLUDED;
         $request->setId('fminor.menu.' . $key)->setType($type)->setContent($twig->render('menu.php.twig', array('name' => $key, 'brand' => $menu['brand'], 'project_name' => $project, 'parts' => $menu['parts'])));
         $requests[] = $request;
     }
     return $requests;
 }
 public function generate(array $requests, ParametersManager $parManager)
 {
     $twig = new TwigEngine(__DIR__);
     $assets = AssetRequest::filter($requests);
     $libraries = LibraryRequest::filter($requests);
     $libraries = $this->addBaseLibraries($libraries);
     $preferCdns = $parManager->getBaseParameter('prefer_cdn');
     $projectName = $parManager->getBaseParameter('project_name');
     $stylesReq = array();
     $scriptsReq = array();
     $styles = array();
     $scripts = array();
     $bower = array();
     $already = array();
     $libraries = array_filter($libraries, function ($library) use($already) {
         if (isset($already[$library->getId()])) {
             return false;
         } else {
             $already[$library->getId()] = true;
             return true;
         }
     });
     foreach ($libraries as $library) {
         $bowerAlr = false;
         if ($preferCdns && $library->getStyleCdns() !== null) {
             $styles = array_merge($styles, $library->getStyleCdns());
         } elseif ($library->getStylePaths() !== null) {
             $styles = array_merge($styles, $library->getStylePaths());
             $bower[] = $library->getId();
             $bowerAlr = true;
         }
         if ($preferCdns && $library->getScriptCdns() !== null) {
             $scripts = array_merge($scripts, $library->getScriptCdns());
         } elseif ($library->getScriptPaths() !== null) {
             $scripts = array_merge($scripts, $library->getScriptPaths());
             if (!$bowerAlr) {
                 $bower[] = $library->getId();
             }
         }
     }
     foreach ($assets as $asset) {
         if ($asset->getType() === AssetRequest::STYLE) {
             $stylesReq[] = $asset;
         } elseif ($asset->getType() === AssetRequest::SCRIPT) {
             $scriptsReq[] = $asset;
         }
     }
     if (count($stylesReq) > 0) {
         $styles[] = '/css/style.css';
         $param = array('assets' => $stylesReq);
         $this->create('web/css/', 'style.css', $twig->render('asset.twig', $param));
     }
     if (count($scriptsReq) > 0) {
         $styles[] = '/js/scripts.js';
         $param = array('assets' => $scriptsReq);
         $this->create('web/js/', 'scripts.js', $twig->render('asset.twig', $param));
     }
     if (count($bower) > 0) {
         $param = array('libraries' => $bower, 'project_name' => $projectName);
         $this->create('/', 'bower.json', $twig->render('bower.json.twig', $param));
     }
     $param = array('styles' => $styles, 'scripts' => $scripts, 'project_name' => $projectName);
     $this->create('src/Resources/views/', 'base.php', $twig->render('base.php.twig', $param));
 }