Exemplo n.º 1
0
 public function testReadWrittenFile()
 {
     $reader = new Reader(__DIR__ . '/../data/write.csv');
     $results = $reader->getAll()->toPrimitiveArray();
     $expected = array(array('column1' => '1test1', 'column2' => '1test2ing this out', 'column3' => '1test3'), array('column1' => '2test1', 'column2' => '2test2 ing this out ok', 'column3' => '2test3'));
     $this->assertEquals($expected, $results);
 }
Exemplo n.º 2
0
 /**
  * Get a list of properties and the access that are given to them for given object.
  *
  * @param array  $properties The properties of the object to read.
  * @param Reader $annotationReader The annotation reader to use.
  *
  * @return array The list of properties and their access.
  */
 public static function getAccessProperties($properties, $annotationReader)
 {
     $objectAccessProperties = array();
     foreach ($properties as $propertyName => $property) {
         if (empty($objectAccessProperties[$propertyName])) {
             $objectAccessProperties[$propertyName] = array();
         }
         // Getters / Setters related annotations
         $propertyAccessAnnotation = $annotationReader->getPropertyAnnotation($property, self::$accessAnnotationClass);
         $accessProperties = array();
         if ($propertyAccessAnnotation !== null) {
             $accessProperties = $propertyAccessAnnotation->getAccessProperties();
         }
         // Collection related annotations
         $collectionAnnotation = null;
         foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) {
             $collectionAnnotation = $annotationReader->getPropertyAnnotation($property, $annotationClass);
             if ($collectionAnnotation !== null) {
                 break;
             }
         }
         $collectionMethods = array();
         if ($collectionAnnotation !== null) {
             $collectionMethods = $collectionAnnotation->getMethods();
         }
         // Merge and save the two arrays
         $objectAccessProperties[$propertyName] = array_merge($accessProperties, $collectionMethods);
     }
     return $objectAccessProperties;
 }
Exemplo n.º 3
0
 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']);
 }
Exemplo n.º 4
0
 public static function unserialize($data, $simple = false)
 {
     $stream = new BytesIO($data);
     $reader = new Reader($stream, $simple);
     $result = $reader->unserialize();
     $stream->close();
     return $result;
 }
Exemplo n.º 5
0
 /**
  * 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());
 }
Exemplo n.º 6
0
function buildForms($code)
{
    $lexer = new Lexer();
    $reader = new Reader();
    $builder = new FormTreeBuilder();
    $tokens = $lexer->tokenize($code);
    $ast = $reader->parse($tokens);
    return $builder->parseAst($ast);
}
Exemplo n.º 7
0
 public function testReadClassDefinition()
 {
     $baseDirectory = __DIR__ . '/../Resources/finder/basemodel';
     $fileName = 'model.yml';
     $rym = new Reader();
     $rym->readYaml($baseDirectory . '/' . $fileName);
     $testEnumProperties = $rym->getClassDefinitionAttributes('TestEnum');
     $this->assertEquals('Yoghi\\Bundle\\Madda\\Domain\\ValueObject', $testEnumProperties['namespace'], 'namespace non letto corretamente');
 }
Exemplo n.º 8
0
 public function find(Query $query, Result $result)
 {
     while ($nextLine = $this->parser->nextLine()) {
         if ($query->matches($nextLine)) {
             $result->addLogLine($nextLine);
         }
         if ($result->hasEnoughLogsInPage()) {
             break;
         }
     }
     return $result;
 }
Exemplo n.º 9
0
    /**
     * This particular xml body caused the parser to go into an infinite loop.
     * Need to know why.
     */
    function testDeserialize()
    {
        $body = '<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test">
  <d:set><d:prop></d:prop></d:set>
  <d:set><d:prop></d:prop></d:set>
</d:propertyupdate>';
        $reader = new Reader();
        $reader->elementMap = ['{DAV:}set' => 'Sabre\\Xml\\Element\\KeyValue'];
        $reader->xml($body);
        $output = $reader->parse();
        $this->assertEquals(['name' => '{DAV:}propertyupdate', 'value' => [['name' => '{DAV:}set', 'value' => ['{DAV:}prop' => null], 'attributes' => []], ['name' => '{DAV:}set', 'value' => ['{DAV:}prop' => null], 'attributes' => []]], 'attributes' => []], $output);
    }
Exemplo n.º 10
0
 public function run()
 {
     $reader = new Reader();
     $render = new Render();
     if (Index::requireIndexing()) {
         $format = $render->attach(new Index());
         $reader->open(Config::xml_file());
         $render->execute($reader);
         $render->detach($format);
     }
     $render->attach($this->format);
     $reader->open(Config::xml_file());
     $render->execute($reader);
 }
Exemplo n.º 11
0
    public function testParse()
    {
        $reader = new Reader();
        $content = <<<EOT
    <meta property="og:title" content="The Rock" />
    <meta property="og:type" content="video.movie" />
    <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
    <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
EOT;
        $result = $reader->parse($content);
        $this->assertCount(4, $result);
        $this->assertEquals(array('property' => 'og:title', 'content' => 'The Rock'), $result[0]->attributes());
        $this->assertEquals(array('property' => 'og:type', 'content' => 'video.movie'), $result[1]->attributes());
    }
Exemplo n.º 12
0
    function testWorkaround()
    {
        // See https://github.com/fruux/sabre-vobject/issues/36
        $event = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:Titel
SEQUENCE:1
TRANSP:TRANSPARENT
RRULE:FREQ=YEARLY
LAST-MODIFIED:20130323T225737Z
DTSTAMP:20130323T225737Z
UID:1833bd44-188b-405c-9f85-1a12105318aa
CATEGORIES:Jubiläum
X-MOZ-GENERATION:3
RECURRENCE-ID;RANGE=THISANDFUTURE;VALUE=DATE:20131013
DTSTART;VALUE=DATE:20131013
CREATED:20100721T121914Z
DURATION:P1D
END:VEVENT
END:VCALENDAR
ICS;
        $obj = Reader::read($event);
        // If this does not throw an exception, it's all good.
        $it = new Recur\EventIterator($obj, '1833bd44-188b-405c-9f85-1a12105318aa');
        $this->assertInstanceOf('Sabre\\VObject\\Recur\\EventIterator', $it);
    }
Exemplo n.º 13
0
 /**
  * Finds and returns the previous start code. Start codes are reserved bit
  * patterns in the video file that do not otherwise occur in the video
  * stream.
  *
  * All start codes are byte aligned and start with the following byte
  * sequence: 0x00 0x00 0x01.
  *
  * @return integer
  */
 protected final function prevStartCode()
 {
     $buffer = '    ';
     $start;
     $position = $this->_reader->getOffset();
     while ($position > 0) {
         $start = 0;
         $position = $position - 512;
         if ($position < 0) {
             require_once 'Zend/Media/Mpeg/Exception.php';
             throw new Zend_Media_Mpeg_Exception('Invalid data');
         }
         $this->_reader->setOffset($position);
         $buffer = $this->_reader->read(512) . substr($buffer, 0, 4);
         $pos = 512 - 8;
         while ($pos > 3) {
             list(, $int) = unpack('n*', substr($buffer, $pos + 1, 2));
             if (ord($buffer[$pos]) == 0 && $int == 1) {
                 list(, $int) = unpack('n*', substr($buffer, $pos + 3, 2));
                 if ($pos + 2 < 512 && $int == 0 && ord($buffer[$pos + 5]) == 1) {
                     $pos--;
                     continue;
                 }
                 $this->_reader->setOffset($position + $pos);
                 return ord($buffer[$pos + 3]) & 0xff | 0x100;
             }
             $pos--;
         }
         $this->_reader->setOffset($position = $position + 3);
     }
     return 0;
 }
    function testGetDTEnd()
    {
        $ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=America/New_York:20070925T170000
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART;TZID=America/New_York:20070925T160000
CREATED:20071004T144642Z
RRULE:FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU
END:VEVENT
END:VCALENDAR
ICS;
        $vObject = Reader::read($ics);
        $it = new RecurrenceIterator($vObject, (string) $vObject->VEVENT->UID);
        while ($it->valid()) {
            $it->next();
        }
        // If we got here, it means we were successful. The bug that was in teh
        // system before would fail on the 5th tuesday of the month, if the 5th
        // tuesday did not exist.
    }
Exemplo n.º 15
0
    function testRead()
    {
        $input = <<<VCF
BEGIN:VCARD
VERSION:2.1
N:Doe;Jon;;;
FN:Jon Doe
EMAIL;X-INTERN:foo@example.org
UID:foo
END:VCARD
VCF;
        $vcard = Reader::read($input);
        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $vcard);
        $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30);
        $vcard = $vcard->serialize();
        $converted = Reader::read($vcard);
        $converted->validate();
        $this->assertTrue(isset($converted->EMAIL['X-INTERN']));
        $version = Version::VERSION;
        $expected = <<<VCF
BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject {$version}//EN
N:Doe;Jon;;;
FN:Jon Doe
EMAIL;X-INTERN=:foo@example.org
UID:foo
END:VCARD

VCF;
        $this->assertEquals($expected, str_replace("\r", "", $vcard));
    }
Exemplo n.º 16
0
 /**
  * Constructs the ID3v1 class with given file. The file is not mandatory
  * argument and may be omitted. A new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string $filename The path to the file.
  */
 public function __construct($filename = false)
 {
     if (($this->_filename = $filename) === false || file_exists($filename) === false) {
         return;
     }
     $this->_reader = new Reader($filename);
     if ($this->_reader->getSize() < 128) {
         return;
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != "TAG") {
         $this->_reader = false;
         // reset reader, see write
         return;
     }
     $this->_title = rtrim($this->_reader->readString8(30), " ");
     $this->_artist = rtrim($this->_reader->readString8(30), " ");
     $this->_album = rtrim($this->_reader->readString8(30), " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = rtrim($this->_reader->readString8(28), " ");
     /* ID3v1.1 support for tracks */
     $v11_null = $this->_reader->read(1);
     $v11_track = $this->_reader->read(1);
     if (ord($v11_null) == 0 && ord($v11_track) != 0) {
         $this->_track = ord($v11_track);
     } else {
         $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " ");
     }
     $this->_genre = $this->_reader->readInt8();
 }
Exemplo n.º 17
0
 /**
  * fgetcsvの代替メソッド
  * @param string $d = ',' CSV区切り文字
  * @param string $e = '"' CSV文字列囲み文字
  * @return array 読み出したCSV配列
  * @access private
  */
 private function fgetcsv_reg($d = ',', $e = '"')
 {
     $d = preg_quote($d);
     $e = preg_quote($e);
     $_line = "";
     while ($eof != true) {
         $__line = parent::read();
         if ($__line === false) {
             break;
         } else {
             $_line .= $__line;
         }
         $itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy);
         if ($itemcnt % 2 == 0) {
             $eof = true;
         }
     }
     $_csv_line = preg_replace('/(?:\\r\\n|[\\r\\n])?$/', $d, trim($_line));
     $_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '|[^' . $d . ']*)' . $d . '/';
     preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);
     $_csv_data = $_csv_matches[1];
     for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) {
         $_csv_data[$_csv_i] = preg_replace('/^' . $e . '(.*)' . $e . '$/s', '$1', $_csv_data[$_csv_i]);
         $_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]);
     }
     return preg_replace('/(?:\\r\\n|[\\r\\n])?$/', '', trim($_line)) === '' ? false : $_csv_data;
 }
Exemplo n.º 18
0
 /**
  * This method tests wether two vcards or icalendar objects are
  * semantically identical.
  *
  * It supports objects being supplied as strings, streams or
  * Sabre\VObject\Component instances.
  *
  * PRODID is removed from both objects as this is often changes and would
  * just get in the way.
  *
  * CALSCALE will automatically get removed if it's set to GREGORIAN.
  *
  * Any property that has the value **ANY** will be treated as a wildcard.
  *
  * @param resource|string|Component $expected
  * @param resource|string|Component $actual
  * @param string $message
  */
 function assertVObjEquals($expected, $actual, $message = '')
 {
     $self = $this;
     $getObj = function ($input) use($self) {
         if (is_resource($input)) {
             $input = stream_get_contents($input);
         }
         if (is_string($input)) {
             $input = Reader::read($input);
         }
         if (!$input instanceof Component) {
             $this->fail('Input must be a string, stream or VObject component');
         }
         unset($input->PRODID);
         if ($input instanceof Component\VCalendar && (string) $input->CALSCALE === 'GREGORIAN') {
             unset($input->CALSCALE);
         }
         return $input;
     };
     $expected = $getObj($expected)->serialize();
     $actual = $getObj($actual)->serialize();
     // Finding wildcards in expected.
     preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\\r$|m', $expected, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $actual = preg_replace('|^' . preg_quote($match[1], '|') . ':(.*)\\r$|m', $match[1] . ':**ANY**' . "\r", $actual);
     }
     $this->assertEquals($expected, $actual, $message);
 }
Exemplo n.º 19
0
 function rewind()
 {
     parent::rewind();
     rewind($this->_file_handler);
     if (($this->_header = fgetcsv($this->_file_handler, 0, $this->_delimiter)) == false) {
         throw new \Exception("Reading of Header was failed");
     }
 }
Exemplo n.º 20
0
 /**
  * Constructs the class with given parameters and options.
  *
  * @param Reader $reader  The reader object.
  * @param Array  $options The options array.
  */
 public function __construct($reader, &$options = array())
 {
   $this->_reader = $reader;
   $this->_options = $options;
   $this->_offset = $this->_reader->getOffset();
   $this->_id = $this->_reader->readGUID();
   $this->_size = $this->_reader->readInt64LE();
 }
 /**
  * @param string $filepath
  *
  * @return bool
  */
 public function build($filepath)
 {
     if ($this->reader->isValid() && is_dir($this->reader->getPath())) {
         $prepared = preg_replace_callback('/%.*%/U', function ($m) {
             if ($m[0] === '%phpdoc%') {
                 $string = '/**';
                 foreach ($this->reader->getComponents() as $name => $classes) {
                     $string .= PHP_EOL . ' * @property ' . implode('|', $classes) . ' $' . $name;
                 }
                 $string .= PHP_EOL . ' */';
                 return $string;
             }
         }, require __DIR__ . '/template.php');
         return (bool) file_put_contents($filepath, $prepared);
     }
     return false;
 }
Exemplo n.º 22
0
 function testRead()
 {
     $vcard = Reader::read(file_get_contents(dirname(__FILE__) . '/issue64.vcf'));
     $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30);
     $vcard = $vcard->serialize();
     $converted = Reader::read($vcard);
     $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $converted);
 }
Exemplo n.º 23
0
 function generate_uml()
 {
     //creating instance of the reader class, passing in the file name path.  example "Java_Test_Files/outer.java
     $reader = new Reader($this->get_passed_in_file_name());
     //$reader = $this->get_reader_object();
     //set var equal to the text file array
     $start_file_array = $reader->get_file_text_array();
     //creating instance of the parser class, passing in the read in file array
     $parser = new Parser($start_file_array);
     //launching the parser controller method
     $parser->parse_controller();
     //start of mapper section
     $mapper = new Mapper($parser->get_parsed_file());
     //launching the mapper controller method, the mapper controller method returns the produced uml table
     //this return statement is used to return the produced table.  Where the table can then be displayed play
     //simple echo statement.
     return $mapper->mapper_controller();
 }
Exemplo n.º 24
0
 public static function get_user_logged_in()
 {
     if (isset($_SESSION['user'])) {
         $id = $_SESSION['user'];
         $reader = Reader::find($id);
         return $reader;
     }
     return null;
 }
Exemplo n.º 25
0
 public static function handleSignin()
 {
     $params = filter_input_array(INPUT_POST);
     $attributes = array('name' => $params['name'], 'password' => $params['password']);
     $reader = new Reader($attributes);
     $errors = $reader->errors();
     //Let's check that user has entered the same password in both fields
     $oneErr = $reader->passwordFieldsAreSame($params['again']);
     if ($oneErr) {
         $errors[] = $oneErr;
     }
     if (count($errors) == 0) {
         $reader->saveNewReader();
         Redirect::to('/', array('message' => 'Olet luonut käyttäjätunnuksen. Kirjaudu seuraavaksi sisään.'));
     } else {
         View::make('/reader/signin.html', array('errors' => $errors, 'attributes' => $attributes));
     }
 }
Exemplo n.º 26
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();
     }
 }
Exemplo n.º 27
0
 /**
  * Returns the location object of the current parsed element. It describes
  * the location of the element within the XML file (line, char)
  *
  * @return object the location of the current parser
  */
 public function getLocation()
 {
     if ($this->file !== null) {
         $path = $this->file->getAbsolutePath();
     } else {
         $path = $this->reader->getResource();
     }
     $this->location = new Location($path, xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser));
     return $this->location;
 }
Exemplo n.º 28
0
 public function export_to_file_handle($fh)
 {
     $entries = array_filter($this->entries, array($this, 'is_entry_good_for_export'));
     ksort($entries);
     $magic = 0x950412de;
     $revision = 0;
     $total = count($entries) + 1;
     // all the headers are one entry
     $originals_lenghts_addr = 28;
     $translations_lenghts_addr = $originals_lenghts_addr + 8 * $total;
     $size_of_hash = 0;
     $hash_addr = $translations_lenghts_addr + 8 * $total;
     $current_addr = $hash_addr;
     fwrite($fh, pack('V*', $magic, $revision, $total, $originals_lenghts_addr, $translations_lenghts_addr, $size_of_hash, $hash_addr));
     fseek($fh, $originals_lenghts_addr);
     // headers' msgid is an empty string
     fwrite($fh, pack('VV', 0, $current_addr));
     $current_addr++;
     $originals_table = chr(0);
     $reader = new Reader();
     foreach ($entries as $entry) {
         $originals_table .= $this->export_original($entry) . chr(0);
         $length = $reader->strlen($this->export_original($entry));
         fwrite($fh, pack('VV', $length, $current_addr));
         $current_addr += $length + 1;
         // account for the NULL byte after
     }
     $exported_headers = $this->export_headers();
     fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr));
     $current_addr += strlen($exported_headers) + 1;
     $translations_table = $exported_headers . chr(0);
     foreach ($entries as $entry) {
         $translations_table .= $this->export_translations($entry) . chr(0);
         $length = $reader->strlen($this->export_translations($entry));
         fwrite($fh, pack('VV', $length, $current_addr));
         $current_addr += $length + 1;
     }
     fwrite($fh, $originals_table);
     fwrite($fh, $translations_table);
     return true;
 }
Exemplo n.º 29
0
    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')));
    }
Exemplo n.º 30
0
 public static function get_admin_logged_in()
 {
     if (isset($_SESSION['user'])) {
         $user_id = $_SESSION['user'];
         if ($user_id == 1) {
             $user = Reader::findOne($user_id);
             return $user;
         }
         return NULL;
     }
     return NULL;
 }