Example #1
0
 /**
  * Parse the input data, return an array of data
  * @param string $data
  * @return array
  */
 public function parse($data)
 {
     $lines = explode("\n", $data);
     $retval = [];
     for ($i = 0; $i < count($lines); $i += 4) {
         $itemObj = new Item();
         $itemObj->setId($lines[$i]);
         $itemObj->setName($lines[$i + 1]);
         $itemObj->setQuantity($lines[$i + 2]);
         $itemObj->setCategories($this->parseCategories($lines[$i + 3]));
         if ($itemObj->isValid() === true) {
             $retval[] = $itemObj;
         }
     }
     return $this->filterById(new Collection($retval));
 }
Example #2
0
 /**
  * Parse the input data, return an array of data
  * @param string $data
  * @return array
  */
 public function parse($data)
 {
     $lines = explode("\n", $data);
     $retval = array();
     foreach ($lines as $idx => $line) {
         $lineCol = str_getcsv($line);
         $itemObj = new Item();
         $itemObj->setId($lineCol[0]);
         $itemObj->setName($lineCol[1]);
         $itemObj->setQuantity($lineCol[2]);
         $itemObj->setCategories($this->parseCategories($lineCol[3]));
         $validation = $itemObj->isValid();
         if ($validation === true) {
             $retval[] = $itemObj;
         }
     }
     $retval = new Collection($retval);
     return $this->filterById($retval);
 }