Example #1
0
 /**
  * Twig constructor.
  *
  * @param AbsMenuPage $menuPage
  *
  * @since  1.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function __construct(AbsMenuPage $menuPage)
 {
     $basePath = $menuPage->getWpMenuPages()->getBasePath();
     $this->defaultPaths[] = $basePath . '/' . IfcTemplateConstants::TEMPLATES_DIR;
     $sysTmpDir = sys_get_temp_dir();
     if (file_exists($sysTmpDir) && is_writable($sysTmpDir)) {
         $this->cachePath = trailingslashit($sysTmpDir) . 'twig/cache';
     }
     $twigOptions = [];
     if ($this->cachePath) {
         $twigOptions['cache'] = $this->cachePath;
     }
     if (IfcConstants::DEV) {
         $twigOptions['debug'] = true;
         $twigOptions['auto_reload'] = true;
         $twigOptions['strict_variables'] = true;
     }
     /**
      * Allows the ability to define extra locations when looking for templates.
      *
      * @param array $templatePaths The template paths
      *
      * @since 1.0.0
      */
     $templatePaths = apply_filters('MenuPages\\Templates\\Twig::templatePaths', $this->defaultPaths);
     $this->twigLoader = new \Twig_Loader_Filesystem($templatePaths);
     $this->twigEnvironment = new \Twig_Environment($this->twigLoader, $twigOptions);
     $this->twigEnvironment->addExtension(new WpTwigExtension($menuPage));
     if (IfcConstants::DEV) {
         $this->twigEnvironment->addExtension(new \Twig_Extension_Debug());
     }
 }
 /**
  * Returns the *Singleton* instance of this class.
  *
  * @param AbsMenuPage $menuPage
  *
  * @return $this ::class The *Singleton* instance.
  */
 public static function getInstance(AbsMenuPage $menuPage)
 {
     $class = get_called_class();
     if (!isset(self::$instances[$menuPage->getMenuSlug()])) {
         self::$instances[$menuPage->getMenuSlug()] = array();
     }
     if (!isset(self::$instances[$menuPage->getMenuSlug()][$class])) {
         self::$instances[$menuPage->getMenuSlug()][$class] = new $class($menuPage);
     }
     return self::$instances[$menuPage->getMenuSlug()][$class];
 }
Example #3
0
 /**
  * Registers a menu page
  *
  * @param AbsMenuPage $menuPage The menu page instance to be registered
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @see    WpMenuPages::$menuPages
  * @since  1.0.0
  */
 public function attachMenuPage(AbsMenuPage $menuPage)
 {
     if (isset($this->menuPages[$menuPage->getMenuSlug()])) {
         user_error('A page with the slug "' . $menuPage->getMenuSlug() . '" is already registered');
     }
     $this->menuPages[$menuPage->getMenuSlug()] = $menuPage;
 }
Example #4
0
 /**
  * @return Twig
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  1.0.0
  */
 public function getTwig()
 {
     return $this->menuPage->getTwig();
 }
Example #5
0
 /**
  * Each page instance should use this function to initialize options for her self
  *
  * @param AbsMenuPage $page A page to init options for
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  1.0.0
  */
 public function maybeInitPageOptions(AbsMenuPage $page)
 {
     if (!isset($this->options[self::PAGE_OPT][$page->getMenuSlug()])) {
         $this->options[self::PAGE_OPT][$page->getMenuSlug()] = [];
     }
 }