/** * @return object */ public function load() { //retrieve an array from a json file stored in the system. $json = $this->files->retrieve($this->path); $array = json_decode($json, true); try { $loader = new ClassLoader(); $object = $loader->load($array); if (method_exists($object, 'fromArray')) { $object->fromArray($array); } else { throw new ReportNotPersistableException("This report type ({$array['class']}) is not able to be persisted or loaded from a file."); } return $object; } catch (\Exception $e) { die($e->getMessage() . "\r\n"); } }
public function fromArray($array) { if (!array_key_exists('filters', $array)) { throw new MalformedPersistenceFileException('This persistence file to load in this filter collection does not have a filters key'); } foreach ($array['filters'] as $name => $filterParams) { $classLoader = new ClassLoader(); $object = $classLoader->load($filterParams['filter']); if (method_exists($object, 'fromArray')) { $object->fromArray($filterParams['filter']); } $this->addFilter($name, $object, $filterParams['condition']); } if (array_key_exists('filterString', $array)) { $this->filterString = $array['filterString']; } }
/** * @param $array */ public function fromArray($array) { $loader = new ClassLoader(); $filters = $loader->load($array['filterCollection']); $filters->fromArray($array['filterCollection']); $resultSet = $loader->load($array['resultSet']); $resultSet->fromArray($array['resultSet']); if ($array['db']) { $db = $loader->load(['class' => $array['db']]); } $this->db = $db; $this->filterCollection = $filters; $this->resultSet = $resultSet; }