Exemplo n.º 1
0
 function next()
 {
     if (($this->_entity = fgets($this->_file_handler)) == false) {
         throw new \Exception("Error: product failed on read");
     }
     if (($this->_entity = json_decode($this->_entity, true)) === null) {
         throw new \Exception("Error: unrecognized type");
     }
     parent::next();
 }
Exemplo n.º 2
0
    function testGetClarkNoNS()
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root />
BLA;
        $reader = new Reader();
        $reader->xml($input);
        $reader->next();
        $this->assertEquals('{}root', $reader->getClark());
    }
Exemplo n.º 3
0
 function next()
 {
     if (($this->_entity = fgetcsv($this->_file_handler, 0, $this->_delimiter)) == false) {
         throw new \Exception("Error: product failed on read");
     }
     // Handling blamk row
     if (empty(implode($this->_entity))) {
         throw new \Exception("Error: Record is empty");
     }
     $this->_entity = array_combine($this->_header, $this->_entity);
     parent::next();
 }
Exemplo n.º 4
0
    /**
     * @depends testMappedElement
     */
    function testParseInnerTree()
    {
        $input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
  <elem1>
     <elem1 />
  </elem1>
</root>
BLA;
        $reader = new Reader();
        $reader->elementMap = ['{http://sabredav.org/ns}elem1' => function (Reader $reader) {
            $innerTree = $reader->parseInnerTree(['{http://sabredav.org/ns}elem1' => function (Reader $reader) {
                $reader->next();
                return "foobar";
            }]);
            return $innerTree;
        }];
        $reader->xml($input);
        $output = $reader->parse();
        $expected = ['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}elem1', 'value' => [['name' => '{http://sabredav.org/ns}elem1', 'value' => 'foobar', 'attributes' => []]], 'attributes' => []]], 'attributes' => []];
        $this->assertEquals($expected, $output);
    }
Exemplo n.º 5
0
 public function read()
 {
     static $seeked = 0;
     static $currently_reading = false;
     static $currently_skipping = false;
     static $arrayPartial = array();
     static $arraySkip = array();
     $ignore = false;
     while ($ret = parent::read()) {
         $id = $this->getAttributeNs("id", self::XMLNS_XML);
         $currentPartial = end($arrayPartial);
         $currentSkip = end($arraySkip);
         if (isset($this->partial[$id])) {
             if ($currentPartial == $id) {
                 v("%s done", $id, VERBOSE_PARTIAL_READING);
                 unset($this->partial[$id]);
                 --$seeked;
                 $currently_reading = false;
                 array_pop($arrayPartial);
             } else {
                 v("Starting %s...", $id, VERBOSE_PARTIAL_READING);
                 $currently_reading = $id;
                 ++$seeked;
                 $arrayPartial[] = $id;
             }
             return $ret;
         } elseif (isset($this->skip[$id])) {
             if ($currentSkip == $id) {
                 v("%s done", $id, VERBOSE_PARTIAL_READING);
                 unset($this->skip[$id]);
                 $currently_skipping = false;
                 $ignore = false;
                 array_pop($arraySkip);
             } else {
                 v("Skipping %s...", $id, VERBOSE_PARTIAL_READING);
                 $currently_skipping = $id;
                 $ignore = true;
                 $arraySkip[] = $id;
             }
         } elseif ($currently_skipping && $this->skip[$currently_skipping]) {
             if ($currentSkip == $id) {
                 v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
             } else {
                 v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
             }
             $ignore = true;
         } elseif ($currently_reading && $this->partial[$currently_reading]) {
             if ($currentPartial == $id) {
                 v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
             } else {
                 v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
             }
             return $ret;
         } elseif (empty($this->partial)) {
             return false;
         } else {
             // If we are used by the indexer then we have no clue about the
             // parents :)
             if ($id && $this->parents) {
                 // If this id isn't one of our ancestors we can jump
                 // completely over it
                 if (!in_array($id, $this->parents)) {
                     parent::next();
                 }
             }
             $ignore = true;
         }
     }
     return $ret;
 }
Exemplo n.º 6
0
 /**
  * Realiza la revision del archivo
  *
  * @param string $fileName
  */
 protected function initialize(Reader $reader)
 {
     $this->checkCsvFile($reader->getFilename());
     if (count($this->rules) === 0) {
         throw new Exception(' No se puede revistar el documento sin antes haber definido reglas @ ' . __LINE__);
     }
     $index = $reader->getHeaders();
     if (count($this->index) > 0) {
         $faltan = array_diff($this->index, $index);
         if (count($faltan)) {
             $this->addError('Se detectaron columnas faltantes en el archivo, se necesitan ' . implode(', ', $this->index) . ' y se encontraron ' . implode(', ', $index) . ' Faltando ' . implode(', ', $faltan) . '');
         }
     }
     $reader->rewind();
     while ($reader->valid()) {
         $this->applyRules($reader->current(), $reader->getLineNumber());
         $reader->next();
     }
 }