Ejemplo n.º 1
0
 /**
  * Build a data source manager with data sources
  * loaded from config array.
  *
  * Config array structure:
  *
  * .Array
  * (
  *   [data_source_name_1] => Array
  *        (
  *            [class] => Yosymfony\Spress\Core\DataSource\Filesystem\FilesystemDataSource
  *            [arguments] => Array
  *                (
  *                    [source_root] => %site_dir%/src
  *                )
  *        )
  *
  *    [data_source_name_2] => Array
  *        (
  *        )
  * )
  *
  * @param array $config Configuration array with data about data sources
  *
  * @return \Yosymfony\Spress\Core\DataSource\DataSourceManager
  *
  * @throws \RuntimeException if params "class" not found or the class pointed by "class" params not exists
  */
 public function buildFromConfigArray(array $config)
 {
     $dsm = new DataSourceManager();
     foreach ($config as $dataSourceName => $data) {
         if (false === isset($data['class'])) {
             throw new \RuntimeException(sprintf('Expected param "class" at the configuration of the data source: "%s".', $dataSourceName));
         }
         $classname = $data['class'];
         $arguments = true === isset($data['arguments']) ? $data['arguments'] : [];
         if (count($this->parameterKeys) > 0 && count($arguments) > 0) {
             $arguments = $this->resolveArgumentsParameters($arguments);
         }
         if (false === class_exists($classname)) {
             throw new \RuntimeException(sprintf('Data source "%s" class not found: "%s".', $dataSourceName, $classname));
         }
         $ds = new $classname($arguments);
         $dsm->addDataSource($dataSourceName, $ds);
     }
     return $dsm;
 }
 public function frontendOutputPreGenerate(&$context)
 {
     $pairs_config = @simplexml_load_file(MANIFEST . '/entry-attribute-counts.xml');
     if (!$pairs_config) {
         return;
     }
     $pairs = $pairs_config->xpath('pair');
     $xml = simplexml_load_string($context['xml']);
     foreach ($pairs as $pair) {
         foreach ($xml as $name => $node) {
             if ($name != $pair->attributes()->{'add-attribute-to'}) {
                 continue;
             }
             foreach ($node as $name => $entry) {
                 if ($name != 'entry') {
                     continue;
                 }
                 $dsm = new DataSourceManager(Frontend::instance());
                 $ds_copy = $dsm->create($pair->attributes()->{'get-count-from'});
                 require_once EXTENSIONS . '/entry_attribute_counts/lib/class.datasource_count.php';
                 $ds = new CountDataSource(Frontend::instance(), NULL, FALSE);
                 $ds->dsSource = $ds_copy->getSource();
                 $ds->dsParamROOTELEMENT = $ds_copy->dsParamROOTELEMENT;
                 $ds->dsParamORDER = $ds_copy->dsParamORDER;
                 $ds->dsParamLIMIT = 999999;
                 $ds->dsParamREDIRECTONEMPTY = 'no';
                 $ds->dsParamREQUIREDPARAM = '';
                 $ds->dsParamSORT = $ds_copy->dsParamSORT;
                 $ds->dsParamSTARTPAGE = 1;
                 $ds->dsParamASSOCIATEDENTRYCOUNTS = 'no';
                 $ds->dsParamFILTERS = $ds_copy->dsParamFILTERS;
                 $ds->dsParamINCLUDEDELEMENTS = $ds_copy->dsParamINCLUDEDELEMENTS;
                 $this->param_pool['ds-' . $pair->attributes()->{'add-attribute-to'}] = $entry->attributes()->id;
                 $ds->processParameters(array('env' => array(), 'param' => $this->param_pool));
                 $grab_xml = $ds->grab($this->param_pool);
                 $entry->addAttribute(Lang::createHandle($pair->attributes()->{'get-count-from'}), $grab_xml->getValue());
             }
         }
     }
     $context['xml'] = $xml->asXML();
 }
Ejemplo n.º 3
0
 function Execute($dsn, $username = NULL, $password = NULL)
 {
     $pdo = new WaxPDO($dsn, $username, $password);
     DataSourceManager::Register($dsn, $pdo);
     return $dsn;
 }
Ejemplo n.º 4
0
 static function DataSource($name = NULL)
 {
     return DataSourceManager::Get($name);
 }
Ejemplo n.º 5
0
 /**
  * Registers a datasource for use later.
  * Datasource names should be unique, such 
  * as a database dsn or an xml file path
  *
  * @param string $name The name of the datasource
  * @param iWaxDataSource $obj The datasource to register
  */
 static function Register($name, iWaxDataSource $obj)
 {
     self::$datasources[$name] = $obj;
     self::$last = $name;
 }