protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tangler = new Tangler();
     $tangler->setAutoloader($this->getApplication()->autoloader);
     $filename = $input->getArgument('filename');
     $data = file_get_contents($filename);
     $xml = $movies = new SimpleXMLElement($data);
     foreach ($xml->autoload as $autoloadnode) {
         $prefix = (string) $autoloadnode['prefix'];
         $path = (string) $autoloadnode['path'];
         echo "Adding autoload prefix: " . $prefix . ' (' . $path . ')' . "\n";
         $tangler->getAutoloader()->add($prefix, $path);
     }
     $indexhtml = '<h1>Module index</h1>';
     foreach ($xml->moduledoc as $moduledocnode) {
         $classname = (string) $moduledocnode['class'];
         $output = (string) $moduledocnode['output'];
         //echo "CLASS: $classname\n";
         $module = new $classname();
         $html = $module->getHtml();
         $indexhtml .= $module->getIndexHtml();
         $data = array();
         $data['body'] = $html;
         file_put_contents($output, json_encode($data));
     }
     $data = array();
     $data['body'] = $indexhtml;
     file_put_contents('contents/modules.json', json_encode($data));
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tangler = new Tangler();
     $tangler->setAutoloader($this->getApplication()->autoloader);
     $loader = new TanglerLoader();
     $filename = $input->getArgument('filename');
     $loader->load($tangler, $filename);
     /*
     
             $channel = new Channel();
             $channel->setKey('test.channel.label');
             $channel->setLabel('Test channel label');
             $channel->setDescription('Test channel description');
     
             $trigger = new \Tangler\Service\File\NewFileTrigger();
             $trigger->parameter->setValue('dir', '/tmp/tangler.in/');
     
             $channel->setTrigger($trigger);
     
             $action = new \Tangler\Service\File\CreateFileAction();
             $action->parameter->setValue('dir', '/tmp/tangler.out/');
             $action->parameter->setValue('filename', 'new.{{filename}}.bin');
             $action->parameter->setValue('content', 'Content: {{content}}.the end');
             $channel->addAction($action);
     
             $action = new \Tangler\Service\Smtp\SendEmailAction();
             $action->parameter->setValue('smtp.host', 'mail.example.web');
             $action->parameter->setValue('smtp.username', 'qweqweqwe');
             $action->parameter->setValue('smtp.password', 'qweqweqwe');
             $action->parameter->setValue('subject', 'New file: {{filename}}');
             $action->parameter->setValue('from', '*****@*****.**');
             $action->parameter->setValue('to', '*****@*****.**');
             $action->parameter->setValue('body', "Found a file {{filename}}:\n{{content}}\nThe end!");
             $channel->addAction($action);
     
             $tangler->addChannel($channel);
     */
     $tangler->Run();
 }
Example #3
0
 public function load(Tangler $tangler, $filename)
 {
     //TODO: Sanity checks
     $data = file_get_contents($filename);
     $xml = $movies = new SimpleXMLElement($data);
     foreach ($xml->autoload as $autoloadnode) {
         $prefix = (string) $autoloadnode['prefix'];
         $path = (string) $autoloadnode['path'];
         echo "Adding autoload prefix: " . $prefix . ' (' . $path . ')' . "\n";
         $tangler->getAutoloader()->add($prefix, $path);
     }
     $registry = null;
     foreach ($xml->registry as $registrynode) {
         $classname = (string) $registrynode['class'];
         $registry = new $classname();
         $parameters = array();
         foreach ($registrynode->parameter as $parameternode) {
             $key = (string) $parameternode['key'];
             $value = (string) $parameternode;
             $parameters[$key] = $value;
         }
         $registry->init($parameters);
     }
     if (!$registry) {
         $sqlitefilename = 'tangler.sqlite3';
         // [, int $mode = 0666 [, string &$error_message ]] )
         $parameters = array();
         $parameters['dsn'] = 'sqlite:' . $sqlitefilename;
         $registry = new \Tangler\Core\PdoRegistry();
         $registry->init($parameters);
     }
     foreach ($xml->channel as $channelnode) {
         $channel = new Channel();
         $channel->setKey((string) $channelnode->key);
         $channel->setLabel((string) $channelnode->label);
         $channel->setDescription((string) $channelnode->description);
         foreach ($channelnode->trigger as $triggernode) {
             $classname = (string) $triggernode['class'];
             $trigger = new $classname();
             $trigger->setRegistry($registry);
             foreach ($triggernode->parameter as $parameternode) {
                 $key = (string) $parameternode['key'];
                 $value = (string) $parameternode;
                 //TODO: ltrim line-by-line
                 $trigger->parameter->setValue($key, $value);
             }
             $channel->setTrigger($trigger);
         }
         foreach ($channelnode->action as $actionnode) {
             $classname = (string) $actionnode['class'];
             $action = new $classname();
             foreach ($actionnode->parameter as $actionnode) {
                 $key = (string) $actionnode['key'];
                 $value = (string) $actionnode;
                 //TODO: ltrim line-by-line
                 $action->parameter->setValue($key, $value);
             }
             $channel->addAction($action);
         }
         $tangler->addChannel($channel);
     }
 }