示例#1
0
 /**
  * Creates a Page object.
  *
  * @param  string $template   Page's template name.
  * @param  array  $parameters Parameters visible in this page.
  * @param  string $outputFile Target file.
  *
  * @return Page
  */
 public function createPage($template, array $parameters = array(), $outputFile = null)
 {
     $page = new Page();
     // if absolute path given then take a name from it
     if (mb_substr($template, 0, 1) === DS) {
         $page->setTemplateFile(new SplFileInfo($template));
         $page->setTemplateName($this->templateNameFromPath($template));
         // if relative path given then build template location from the name
     } else {
         $page->setTemplateFile(new SplFileInfo($this->templatesDir . $template));
         $page->setTemplateName($template);
     }
     // if no output file given then build it automatically
     if (!$outputFile) {
         $outputPath = $this->outputPathFromTemplate($page->getTemplateName());
         $page->setOutputFile(new SplFileInfo($outputPath));
         $page->setOutputName($this->outputNameFromPath($outputPath));
         // if absolute path to output file given then take a name from it
     } elseif (mb_substr($outputFile, 0, 1) === DS) {
         $page->setOutputFile(new SplFileInfo($outputFile));
         $page->setOutputName($this->outputNameFromPath($outputFile));
         // if relative path to output given then build output location from the name
     } else {
         $page->setOutputFile(new SplFileInfo($this->webDir . $outputFile));
         $page->setOutputName($outputFile);
     }
     $page->setParameters($parameters);
     return $page;
 }