Inheritance: extends CI_Model
 public function testWriteAndRead()
 {
     $config = new Config(array('default' => array('test' => 'foo')));
     $this->writer->toFile($this->getTestAssetFileName(), $config);
     $config = $this->reader->fromFile($this->getTestAssetFileName());
     $this->assertEquals('foo', $config['default']['test']);
 }
Exemple #2
0
 /**
  * @covers Itkg\Batch\State::setException
  */
 public function testSetException()
 {
     $e = new \Exception();
     $this->object->setException($e);
     $this->assertEquals($e, $this->object->getException());
     $this->assertEquals(1, $this->object->getStatus());
 }
 public static function serialize($var, $simple = false)
 {
     $stream = new BytesIO();
     $writer = new Writer($stream, $simple);
     $writer->serialize($var);
     return $stream->toString();
 }
 public function run()
 {
     $writer = new Writer($this->config['parameters'], $this->config['dataFolder']);
     $tables = $this->config['storage']['input']['tables'];
     foreach ($tables as $table) {
         $writer->write($table);
     }
 }
Exemple #5
0
 /**
  * test formatBatch
  */
 public function testFormatBatch()
 {
     $text = "it's a test";
     $text2 = "it's another test";
     $record = array('message' => $text);
     $record2 = array('message' => $text2);
     $this->assertEquals($text . $text2, $this->object->formatBatch(array($record, $record2)));
 }
 /**
  * Strip statements
  *
  * @expectOutputRegex #echo 'bar';#
  */
 public function exampleStripNodes()
 {
     $reader = new Reader("<?php require 'Foo.php'; echo 'bar';");
     $writer = new Writer();
     $writer->apply(new Action\NodeStripper('Expr_Include'));
     // Outputs the echo statement
     echo $writer->write($reader->readAll());
 }
 /**
  * Dispatch all raised events.
  *
  * @param array $events
  */
 public function dispatch(array $events)
 {
     foreach ($events as $event) {
         $eventName = $this->getEventName($event);
         $this->event->fire($eventName, $event);
         $this->log->info("{$eventName} was fired.");
     }
 }
Exemple #8
0
 public function testPhpParserException()
 {
     $traverser = $this->getMock('PhpParser\\NodeTraverser');
     $traverser->expects($this->once())->method('traverse')->will($this->throwException(new \PhpParser\Error('error')));
     $writer = new Writer($traverser);
     $this->setExpectedException('hanneskod\\classtools\\Exception\\RuntimeException');
     $writer->write([]);
 }
Exemple #9
0
 public function testWriteIntegers()
 {
     $w = new Writer(tmpfile(), array('hasHeader' => true));
     $numbers = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5);
     $w->write($numbers);
     foreach ($w as $line) {
         $this->assertEquals($line, $numbers);
     }
 }
Exemple #10
0
 public function generate()
 {
     $parseData = \EventController::callFilter(self::EventName, $this->data->getValue());
     $view = new View($this->tpl->getValue());
     $view->addHelper(new ViewHelper());
     $view->set($parseData);
     $content = $view->render();
     $writer = new Writer($this->url->getValue());
     $writer->write($content);
 }
Exemple #11
0
 public function testRender()
 {
     $writer = new Writer();
     $property = new \ReflectionProperty($writer, 'collection');
     $property->setAccessible(true);
     $meta = new Meta(array('test' => 'fun'));
     $writer->add($meta);
     $writer->add($meta);
     $this->assertEquals("<meta test=\"fun\" />\n<meta test=\"fun\" />\n", $writer->render());
 }
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     if ($oOptions->output == 'display') {
         header("Content-Disposition: attachment; filename=survey_" . $survey->id . "_R_syntax_file.R");
         header("Content-type: application/download; charset=UTF-8");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Pragma: public");
         $this->handle = fopen('php://output', 'w');
     } elseif ($oOptions->output == 'file') {
         $this->handle = fopen($this->filename, 'w');
     }
     $this->out('data <- read.csv("survey_' . $survey->id . '_R_data_file.csv", quote = "\'\\"", na.strings=c("", "\\"\\""), stringsAsFactors=FALSE)');
     $this->out("");
     $this->out("");
     $oOptions->headingFormat = 'code';
     // Always use fieldcodes
     // R specific stuff
     Yii::app()->loadHelper("export");
     $tmpFieldmap = SPSSFieldMap($survey->id);
     foreach ($tmpFieldmap as $field => $values) {
         $fieldmap[$values['title']] = $values;
         if (array_key_exists('sql_name', $values)) {
             $fieldmap[$values['sql_name']] = $values;
         }
     }
     $this->customFieldmap = $fieldmap;
 }
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     $this->survey = $survey;
     if ($oOptions->output == 'display') {
         //header("Content-Disposition: attachment; filename=results-survey".$survey->id.".html");
         header("Content-type: text/html; charset=UTF-8");
         $this->handle = fopen('php://output', 'w');
     } elseif ($oOptions->output == 'file') {
         $this->handle = fopen($this->filename, 'w');
     }
     $this->groupMap = array();
     $index = 0;
     foreach ($oOptions->selectedColumns as $column) {
         if (isset($survey->fieldMap[$column])) {
             $question = $survey->fieldMap[$column];
         } else {
             // Token field
             $question = array('gid' => 0, 'qid' => '');
         }
         $question['index'] = $index;
         $this->groupMap[intval($question['gid'])][] = $question;
         $index++;
     }
 }
Exemple #14
0
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     App()->setLanguage($sLanguageCode);
     if ($oOptions->output == 'display') {
         header("Content-Disposition: attachment; filename=results-survey" . $survey->id . ".doc");
         header("Content-type: application/vnd.ms-word");
     }
     $sOutput = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <style>
     table {
     border-collapse:collapse;
     }
     td, th {
     border:solid black 1.0pt;
     }
     th {
     background: #c0c0c0;
     }
     </style>';
     if ($oOptions->output == 'display') {
         echo $sOutput;
     } elseif ($oOptions->output == 'file') {
         $this->file = fopen($this->filename, 'w');
         $this->output = $sOutput;
     }
 }
 public function end()
 {
     $schemas = $this->document->getPhysicalModel()->getCatalog()->getSchemas();
     $filename = $schemas[0]->getName() . '.' . $this->document->getFormatter()->getFileExtension();
     $this->storage->save($filename, (string) $this->aggregate);
     parent::end();
 }
Exemple #16
0
 /**
  * Constructor.
  *
  * @param string $filepath a relative or absolute path to the file.
  *
  * @param string $delimiter the delimiter that separates columns in the file.
  *
  * @param string $enclosure (optional, default value is '"') the character that is used for
  *    enclosing column values.
  *
  * @param string $escape (optional, default value is '\') the character used for escaping.
  *
  * @param string $mode the file mode (see PHPs fopen() $mode parameter;
  *   http://php.net/manual/de/function.fopen.php)
  *
  * For `$delimiter`, `$enclosure`, and `$escape` see also http://php.net/manual/en/function.str-getcsv.php.
  */
 public function __construct($filepath, $delimiter, $enclosure = '"', $escape = "\\", $mode = 'w')
 {
     parent::__construct($filepath, $mode);
     $this->delimiter = $delimiter;
     $this->enclosure = $enclosure;
     $this->escape = $escape;
     $this->header = null;
 }
Exemple #17
0
 protected function set_params($params)
 {
     $this->_set_param($params, 'print_default');
     $this->_set_param($params, 'print_data');
     $this->_set_param($params, 'print_params');
     $this->_set_param($params, 'print_log');
     return parent::set_params($params);
 }
Exemple #18
0
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     $this->csvFilename = "results-survey" . $survey->id . ".csv";
     if ($oOptions->output == 'file') {
         $this->file = fopen($this->filename, 'w');
     }
 }
Exemple #19
0
 public function execute()
 {
     $iterator = new \DirectoryIterator($this->inputDir);
     $interpreter = new Interpreter();
     $operations = [];
     foreach ($iterator as $path) {
         if ($path->getExtension() === 'rst') {
             $operations[] = $interpreter->parse(file_get_contents($path->getRealPath()));
         }
     }
     $operations = array_values(array_filter($operations));
     usort($operations, function ($a, $b) {
         return strlen($a['path']) - strlen($b['path']);
     });
     $writer = new Writer($this->outputDir, $this->namespace, $operations);
     $writer->write();
 }
Exemple #20
0
 /**
  * Create a new newspaper writer Instance.
  * @param array $settings configuration settings.
  */
 public function __construct($settings)
 {
     parent::__construct($settings);
     $this->fetcher = new \mik\fetchers\Cdm($settings);
     $this->alias = $settings['WRITER']['alias'];
     $fileGetterClass = 'mik\\filegetters\\' . $settings['FILE_GETTER']['class'];
     $this->cdmSingleFileFileGetter = new $fileGetterClass($settings);
 }
Exemple #21
0
 /**
  * Create a new newspaper writer Instance
  * @param array $settings configuration settings.
  */
 public function __construct($settings)
 {
     parent::__construct($settings);
     $this->fetcher = new \mik\fetchers\Cdm($settings);
     $fileGetterClass = 'mik\\filegetters\\' . $settings['FILE_GETTER']['class'];
     $this->fileGetter = new $fileGetterClass($settings);
     $this->output_directory = $settings['WRITER']['output_directory'];
     $this->modsValidator = new \mik\filemanipulators\ValidateMods($settings);
 }
Exemple #22
0
 /**
  * Create a new newspaper writer Instance
  * @param array $settings configuration settings.
  */
 public function __construct($settings)
 {
     parent::__construct($settings);
     $this->fetcher = new \mik\fetchers\Cdm($settings);
     $fileGetterClass = 'mik\\filegetters\\' . $settings['FILE_GETTER']['class'];
     $this->fileGetter = new $fileGetterClass($settings);
     $this->output_directory = $settings['WRITER']['output_directory'];
     $this->preserve_content_filenames = $settings['WRITER']['preserve_content_filenames'];
 }
Exemple #23
0
 protected function process_data(&$signal)
 {
     $result = parent::process_data($signal);
     $file = $signal->data_element($this->default_data_key);
     if (is_null($file)) {
         return false;
     }
     $result = $this->storage_action($file);
     $this->set_jobdata($result);
     return $result;
 }
Exemple #24
0
 /**
  * Handles closing elements of the xml file.
  *
  * @param      $name The local name (without prefix), or the empty string if
  *         Namespace processing is not being performed.
  */
 public function endElement($name)
 {
     if (self::DEBUG) {
         print "endElement(" . $name . ") called\n";
     }
     if ($name == "dataset") {
         if ($this->currBuilder !== null) {
             $this->sqlWriter->write($this->currBuilder->getTableEndSql());
         }
         $this->sqlWriter->write(call_user_func(array($this->builderClazz, 'getDatabaseEndSql')));
     }
 }
Exemple #25
0
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     $sStartOutput = '{' . json_encode("responses") . ': [';
     if ($oOptions->output == 'display') {
         header("Content-type: application/json");
         echo $sStartOutput;
     } elseif ($oOptions->output == 'file') {
         $this->file = fopen($this->filename, 'w');
         fwrite($this->file, $sStartOutput);
     }
 }
    public function testSaveGlobalUseStatements()
    {
        $reader = new Reader(<<<EOF
<?php
use random\\Exception;
class ClassName
{
}
EOF
);
        $expected = <<<EOF
namespace  {
    use random\\Exception;
    class ClassName
    {
    }
}
EOF;
        $writer = new Writer();
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
Exemple #27
0
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     $this->survey = $survey;
     if ($oOptions->output == 'display') {
         //header("Content-Disposition: attachment; filename=results-survey".$survey->id.".html");
         header("Content-type: text/html; charset=UTF-8");
         $this->handle = fopen('php://output', 'w');
     } elseif ($oOptions->output == 'file') {
         $this->handle = fopen($this->filename, 'w');
     }
     $this->groupMap = $this->setGroupMap($survey, $oOptions);
 }
Exemple #28
0
    public function testWriter()
    {
        $writer = new Writer();
        $writer->addService('http://www.myopenid.com/server', array('http://specs.openid.net/auth/2.0/signon'));
        $writer->addService('http://www.myopenid.com/server', array('http://specs.openid.net/auth/2.0/signon'), 20);
        $actual = $writer->toString();
        $expected = <<<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns="xri://$xrd*($v*2.0)" xmlns:xrds="xri://$xrds">
  <XRD>
    <Service>
      <Type>http://specs.openid.net/auth/2.0/signon</Type>
      <URI>http://www.myopenid.com/server</URI>
    </Service>
    <Service priority="20">
      <Type>http://specs.openid.net/auth/2.0/signon</Type>
      <URI>http://www.myopenid.com/server</URI>
    </Service>
  </XRD>
</xrds:XRDS>
XML;
        $this->assertXmlStringEqualsXmlString($expected, $actual);
    }
Exemple #29
0
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     $this->workbook = new XLSXWriter();
     $this->workbook->setTempDir(Yii::app()->getConfig('tempdir'));
     $worksheetName = $survey->languageSettings['surveyls_title'];
     $worksheetName = substr(str_replace(array('*', ':', '/', '\\', '?', '[', ']'), array(' '), $worksheetName), 0, 31);
     // Remove invalid characters
     if ($worksheetName == '') {
         $worksheetName = 'survey_' . $survey->id;
     }
     $this->currentSheet = $worksheetName;
     $this->forceDownload = !($oOptions->output == 'file');
 }
 public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     if ($oOptions->output == 'display') {
         header("Content-Disposition: attachment; filename=survey_" . $survey->id . "_STATA.xml");
         header("Content-type: application/download; charset=US-ASCII");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Pragma: public");
         $this->handle = fopen('php://output', 'w');
     } elseif ($oOptions->output == 'file') {
         $this->handle = fopen($this->filename, 'w');
     }
     $this->headersSGQA = $oOptions->selectedColumns;
     $oOptions->headingFormat = 'code';
     // Always use fieldcodes
     $this->customFieldmap = $this->createStataFieldmap($survey, $sLanguageCode, $oOptions);
 }