* @license PHP License * @package WB * @subpackage MailMime */ WBClass::load('WBCli' , 'WBObserver'); /** * Command Line Interface class: Datasource * * Walk throuch Datasource * * @version 1.1.1 * @package WB */ class WBCli_DatasourceWalker extends WBCli implements WBObserver { /** * Datasource * @var WBDatasource_View */ private $view; /** * Datasource renderer * @var WBDatasource_Renderer */ private $renderer; /** * Command line arguments * @var array */ protected $arguments = array( CONSOLE_GETARGS_PARAMS => array( 'min' => 0, 'max' => 1, 'desc' => 'Datasource', 'default' => '' ) ); /** * 2nd constructor * * load config and setup importer */ protected function init() { $this->view = WBClass::create('WBDatasource_View'); $this->renderer = WBClass::create('WBDatasource_Renderer_Observable'); $this->renderer->attach($this); $this->view->setRenderer($this->renderer); } /** * execute programme * * */ protected function execute() { if (empty($this->commands)) { $this->commands = array(); } $optFmt = ' %10s: %s'; $this->fetchDatasources(); if (empty($this->commands)) { $this->pl('No datasources to walk', STDERR); return 1; } $this->pvl(sprintf($optFmt, 'Verbose', $this->verbosity)); $this->pvl(sprintf($optFmt, '# of DS', count($this->commands))); foreach ($this->commands as $ds) { $this->walkDS($ds); } return 0; } private function walkDS($datasource) { $this->p($datasource . ' '); WBClass::load('WBException_File'); try { $this->view->render($datasource); } catch (WBException_File $e) { $this->pl('Config for datasource: "' . $datasource . '" not found!', STDERR); return; } catch (Exception $e) { $this->pl($e->getMessage(), STDERR); return; } $this->pl($this->renderer->getCount()); } private function fetchDatasources() { if (!empty($this->commands)) { return; } $config = WBClass::create('WBConfig'); if (!$config->load('datasource/walk', true)) { $this->pl('List of datasource: "etc/datasource/walk.xml" not found!', STDERR); return; } $this->commands = $config->get('datasource', array()); } /** * get help text - head * * Override this method to set suitable help text * * @return string */ protected function getHelpHead() { $head = array(); $head[] = 'Wombat Datasource Walker'; $head[] = ''; $head[] = 'Usage: ' . basename($_SERVER['_']) . ' [OPTION]... [DATASOURCE]'; $head[] = ''; $head[] = 'In case no datasource is specified, it will load the list from etc/datasource/walk.xml'; $head[] = ''; $head[] = 'Options:'; $head[] = ''; return implode("\n", $head); } /** * inform observer * * @param WBDatasource_Renderer_Observable $subject */ public function update($subject) { $item = $subject->getItem(); // $this->pvl($item['id']); } }