Source for file provider.php

Documentation is available at provider.php

  1. <?php
  2. /**
  3.  *  @package     FrameworkOnFramework
  4.  *  @subpackage  config
  5.  *  @copyright   Copyright (c)2010-2012 Nicholas K. Dionysopoulos
  6.  *  @license     GNU General Public License version 2, or later
  7.  */
  8.  
  9. defined('FOF_INCLUDED'or die();
  10.  
  11. /**
  12.  * Reads and parses the fof.xml file in the back-end of a FOF-powered component,
  13.  * provisioning the data to the rest of the FOF framework
  14.  *
  15.  * @package  FrameworkOnFramework
  16.  * @since    2.1
  17.  */
  18. {
  19.     /**
  20.      * Cache of FOF components' configuration variables
  21.      *
  22.      * @var array 
  23.      */
  24.     public static $configurations array();
  25.  
  26.     /**
  27.      * Parses the configuration of the specified component
  28.      *
  29.      * @param   string   $component  The name of the component, e.g. com_foobar
  30.      * @param   boolean  $force      Force reload even if it's already parsed?
  31.      *
  32.      * @return  void 
  33.      */
  34.     public function parseComponent($component$force false)
  35.     {
  36.         if (!$force && isset(self::$configurations[$component]))
  37.         {
  38.             return;
  39.         }
  40.  
  41.         if (FOFPlatform::getInstance()->isCli())
  42.         {
  43.             $order array('cli''backend');
  44.         }
  45.         elseif (FOFPlatform::getInstance()->isBackend())
  46.         {
  47.             $order array('backend');
  48.         }
  49.         else
  50.         {
  51.             $order array('frontend');
  52.         }
  53.  
  54.         $order['common';
  55.  
  56.         $order array_reverse($order);
  57.         self::$configurations[$componentarray();
  58.  
  59.         foreach ($order as $area)
  60.         {
  61.             $config $this->parseComponentArea($component$area);
  62.             self::$configurations[$componentarray_merge_recursive(self::$configurations[$component]$config);
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Returns the value of a variable. Variables use a dot notation, e.g.
  68.      * view.config.whatever where the first part is the domain, the rest of the
  69.      * parts specify the path to the variable.
  70.      *
  71.      * @param   string  $variable  The variable name
  72.      * @param   mixed   $default   The default value, or null if not specified
  73.      *
  74.      * @return  mixed  The value of the variable
  75.      */
  76.     public function get($variable$default null)
  77.     {
  78.         static $domains null;
  79.  
  80.         if (is_null($domains))
  81.         {
  82.             $domains $this->getDomains();
  83.         }
  84.  
  85.         list($component$domain$varexplode('.'$variable3);
  86.  
  87.         if (!isset(self::$configurations[$component]))
  88.         {
  89.             $this->parseComponent($component);
  90.         }
  91.  
  92.         if (!in_array($domain$domains))
  93.         {
  94.             return $default;
  95.         }
  96.  
  97.         $class 'FOFConfigDomain' ucfirst($domain);
  98.         $o new $class;
  99.  
  100.         return $o->get(self::$configurations[$component]$var$default);
  101.     }
  102.  
  103.     /**
  104.      * Parses the configuration options of a specific component area
  105.      *
  106.      * @param   string  $component  Which component's cionfiguration to parse
  107.      * @param   string  $area       Which area to parse (frontend, backend, cli)
  108.      *
  109.      * @return  array  A hash array with the configuration data
  110.      */
  111.     protected function parseComponentArea($component$area)
  112.     {
  113.         // Initialise the return array
  114.         $ret array();
  115.  
  116.         // Get the folders of the component
  117.         $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($component);
  118.  
  119.         // Check that the path exists
  120.         JLoader::import('joomla.filesystem.folder');
  121.         $path $componentPaths['admin'];
  122.         $path JPath::check($path);
  123.  
  124.         if (!JFolder::exists($path))
  125.         {
  126.             return $ret;
  127.         }
  128.  
  129.         // Read the filename if it exists
  130.         $filename $path '/fof.xml';
  131.         JLoader::import('joomla.filesystem.file');
  132.  
  133.         if (!JFile::exists($filename))
  134.         {
  135.             return $ret;
  136.         }
  137.  
  138.         $data JFile::read($filename);
  139.  
  140.         // Load the XML data in a SimpleXMLElement object
  141.         $xml simplexml_load_string($data);
  142.  
  143.         if (!($xml instanceof SimpleXMLElement))
  144.         {
  145.             return $ret;
  146.         }
  147.  
  148.         // Get this area's data
  149.         $areaData $xml->xpath('//' $area);
  150.  
  151.         if (empty($areaData))
  152.         {
  153.             return $ret;
  154.         }
  155.  
  156.         $xml array_shift($areaData);
  157.  
  158.         // Parse individual configuration domains
  159.         $domains $this->getDomains();
  160.  
  161.         foreach ($domains as $dom)
  162.         {
  163.             $class 'FOFConfigDomain' ucfirst($dom);
  164.  
  165.             if (class_exists($classtrue))
  166.             {
  167.                 $o new $class;
  168.                 $o->parseDomain($xml$ret);
  169.             }
  170.         }
  171.  
  172.         // Finally, return the result
  173.         return $ret;
  174.     }
  175.  
  176.     /**
  177.      * Gets a list of the available configuration domain adapters
  178.      *
  179.      * @return  array  A list of the available domains
  180.      */
  181.     protected function getDomains()
  182.     {
  183.         static $domains array();
  184.  
  185.         if (empty($domains))
  186.         {
  187.             JLoader::import('joomla.filesystem.folder');
  188.             $files JFolder::files(__DIR__ . '/domain''.php');
  189.  
  190.             if (!empty($files))
  191.             {
  192.                 foreach ($files as $file)
  193.                 {
  194.                     $domain basename($file'.php');
  195.  
  196.                     if ($domain == 'interface')
  197.                     {
  198.                         continue;
  199.                     }
  200.  
  201.                     $domain preg_replace('/[^A-Za-z0-9]/'''$domain);
  202.                     $domains[$domain;
  203.                 }
  204.  
  205.                 $domains array_unique($domains);
  206.             }
  207.         }
  208.  
  209.         return $domains;
  210.     }
  211. }

Documentation generated on Tue, 19 Nov 2013 15:11:21 +0100 by phpDocumentor 1.4.3