Source for file tables.php

Documentation is available at tables.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.  * Configuration parser for the tables-specific settings
  13.  *
  14.  * @package  FrameworkOnFramework
  15.  * @since    2.1
  16.  */
  17. class FOFConfigDomainTables implements FOFConfigDomainInterface
  18. {
  19.     /**
  20.      * Parse the XML data, adding them to the $ret array
  21.      *
  22.      * @param   SimpleXMLElement  $xml   The XML data of the component's configuration area
  23.      * @param   array             &$ret  The parsed data, in the form of a hash array
  24.      *
  25.      * @return  void 
  26.      */
  27.     public function parseDomain(SimpleXMLElement $xmlarray &$ret)
  28.     {
  29.         // Initialise
  30.         $ret['tables'array();
  31.  
  32.         // Parse table configuration
  33.         $tableData $xml->xpath('table');
  34.  
  35.         // Sanity check
  36.         if (empty($tableData))
  37.         {
  38.             return;
  39.         }
  40.  
  41.         foreach ($tableData as $aTable)
  42.         {
  43.             $key = (string) $aTable['name'];
  44.  
  45.             $ret['tables'][$key]['behaviors'= (string) $aTable->behaviors;
  46.             $ret['tables'][$key]['tablealias'$aTable->xpath('tablealias');
  47.             $ret['tables'][$key]['fields'array();
  48.             $fieldData $aTable->xpath('field');
  49.  
  50.             if (!empty($fieldData))
  51.             {
  52.                 foreach ($fieldData as $field)
  53.                 {
  54.                     $k = (string) $field['name'];
  55.                     $ret['tables'][$key]['fields'][$k= (string) $field;
  56.                 }
  57.             }
  58.         }
  59.     }
  60.  
  61.     /**
  62.      * Return a configuration variable
  63.      *
  64.      * @param   string  &$configuration  Configuration variables (hashed array)
  65.      * @param   string  $var             The variable we want to fetch
  66.      * @param   mixed   $default         Default value
  67.      *
  68.      * @return  mixed  The variable's value
  69.      */
  70.     public function get(&$configuration$var$default)
  71.     {
  72.         $parts explode('.'$var);
  73.  
  74.         $view $parts[0];
  75.         $method 'get' ucfirst($parts[1]);
  76.  
  77.         if (!method_exists($this$method))
  78.         {
  79.             return $default;
  80.         }
  81.  
  82.         array_shift($parts);
  83.         array_shift($parts);
  84.  
  85.         $ret $this->$method($view$configuration$parts$default);
  86.  
  87.         return $ret;
  88.     }
  89.  
  90.     /**
  91.      * Internal method to return the magic field mapping
  92.      *
  93.      * @param   string  $table           The table for which we will be fetching a field map
  94.      * @param   array   &$configuration  The configuration parameters hash array
  95.      * @param   array   $params          Extra options; key 0 defines the table we want to fetch
  96.      * @param   string  $default         Default magic field mapping; empty if not defined
  97.      *
  98.      * @return  array   Field map
  99.      */
  100.     protected function getField($table&$configuration$params$default '')
  101.     {
  102.         $fieldmap array();
  103.  
  104.         if (isset($configuration['tables']['*']&& isset($configuration['tables']['*']['fields']))
  105.         {
  106.             $fieldmap $configuration['tables']['*']['fields'];
  107.         }
  108.  
  109.         if (isset($configuration['tables'][$table]&& isset($configuration['tables'][$table]['fields']))
  110.         {
  111.             $fieldmap array_merge($fieldmap$configuration['tables'][$table]['fields']);
  112.         }
  113.  
  114.         $map $default;
  115.  
  116.         if (empty($params[0]))
  117.         {
  118.             $map $fieldmap;
  119.         }
  120.         elseif (isset($fieldmap[$params[0]]))
  121.         {
  122.             $map $fieldmap[$params[0]];
  123.         }
  124.  
  125.         return $map;
  126.     }
  127.  
  128.     /**
  129.      * Internal method to get table alias
  130.      *
  131.      * @param   string  $table           The table for which we will be fetching table alias
  132.      * @param   array   &$configuration  The configuration parameters hash array
  133.      * @param   array   $params          Extra options; key 0 defines the table we want to fetch
  134.      * @param   string  $default         Default table alias
  135.      *
  136.      * @return  string  Table alias
  137.      */
  138.     protected function getTablealias($table&$configuration$params$default '')
  139.     {
  140.         $tablealias $default;
  141.  
  142.         if (isset($configuration['tables']['*'])
  143.             && isset($configuration['tables']['*']['tablealias'])
  144.             && isset($configuration['tables']['*']['tablealias'][0]))
  145.         {
  146.             $tablealias = (string) $configuration['tables']['*']['tablealias'][0];
  147.         }
  148.  
  149.         if (isset($configuration['tables'][$table])
  150.             && isset($configuration['tables'][$table]['tablealias'])
  151.             && isset($configuration['tables'][$table]['tablealias'][0]))
  152.         {
  153.             $tablealias = (string) $configuration['tables'][$table]['tablealias'][0];
  154.         }
  155.  
  156.         return $tablealias;
  157.     }
  158.  
  159.     /**
  160.      * Internal method to get table alias
  161.      *
  162.      * @param   string  $table           The table for which we will be fetching table alias
  163.      * @param   array   &$configuration  The configuration parameters hash array
  164.      * @param   array   $params          Extra options; key 0 defines the table we want to fetch
  165.      * @param   string  $default         Default table alias
  166.      *
  167.      * @return  string  Table alias
  168.      */
  169.     protected function getBehaviors($table&$configuration$params$default '')
  170.     {
  171.         $behaviors $default;
  172.  
  173.         if (isset($configuration['tables']['*'])
  174.             && isset($configuration['tables']['*']['behaviors'])
  175.             && isset($configuration['tables']['*']['behaviors']))
  176.         {
  177.             $behaviors = (string) $configuration['tables']['*']['behaviors'];
  178.         }
  179.  
  180.         if (isset($configuration['tables'][$table])
  181.             && isset($configuration['tables'][$table]['behaviors'])
  182.             && isset($configuration['tables'][$table]['behaviors']))
  183.         {
  184.             $behaviors = (string) $configuration['tables'][$table]['behaviors'];
  185.         }
  186.  
  187.         return $behaviors;
  188.     }
  189. }

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