コード例 #1
0
ファイル: Parser.php プロジェクト: anunatak/postal
 /**
  * Parses the stored remote data
  * 
  * @return void
  */
 protected function parse()
 {
     // only perform actions when we have a file
     if (Storage::exists('postal/data.txt')) {
         // get the contents from storage
         $data = Storage::get('postal/data.txt');
         // add a header
         $data = "Code1\tPlace1\tCode2\tPlace2\tType\n" . $data;
         // convert to utf-8
         $data = iconv('ISO-8859-1', "UTF-8", $data);
         // set parser settings
         $this->parser->encoding('UTF-8');
         $this->parser->delimiter = "\t";
         // parse the data
         $this->parser->parse($data);
         // get the parsed csv
         $parsed = $this->parser->data;
         // empty arrays
         $codes = array();
         // loop items
         foreach ($parsed as $parse) {
             $codes[] = array('code' => $parse['Code1'], 'place' => S::toTitleCase($parse['Place1']));
             $codes[] = array('code' => $parse['Code2'], 'place' => S::toTitleCase($parse['Place2']));
         }
         $this->data = $codes;
     }
 }
コード例 #2
0
 /**
  * @dataProvider toTitleCaseProvider()
  */
 public function testToTitleCase($expected, $str, $encoding = null)
 {
     $result = S::toTitleCase($str, $encoding);
     $this->assertInternalType('string', $result);
     $this->assertEquals($expected, $result);
 }