コード例 #1
0
ファイル: Base.php プロジェクト: menofearthereaper/HCCP
 /**
  * constructor.
  * @param array $params - assoc array of properties
  * @throws \Exception
  */
 public function __construct($params)
 {
     try {
         foreach (get_object_vars($this) as $varName => $val) {
             // sanity check that all the params exist for the model class obj
             if (array_key_exists($varName, $params)) {
                 $this->__set($varName, $params[$varName]);
             } else {
                 throw new \LogicException("Required parameter [{$varName}] missing.");
             }
         }
     } catch (\Exception $e) {
         // Dump the params to log file so we can see what went BOOM! then rethrow exception
         Logger::getInstance()->write(ERROR, 'Failed to create instance of ' . get_class($this) . '. ' . $e->getMessage(), $params);
         throw $e;
     }
 }
コード例 #2
0
ファイル: Company.php プロジェクト: menofearthereaper/HCCP
 /**
  * Function takes the html fetched from the asx pages and fetches the table rows out of the first table found
  * This would need a ton of hardening
  * @param $html
  * @return \DOMNodeList
  * @throws \LogicException - if the html is empty
  * @throws \Exception - if there is html but something is awry with it
  */
 private function getTableRows($html)
 {
     $dom = new DOMDocument();
     if (!empty($html)) {
         libxml_use_internal_errors(true);
         @$dom->loadHTML($html);
         $dom->preserveWhiteSpace = false;
         /** @var \DOMElement $table */
         if ($table = $dom->getElementsByTagName('table')->item(0)) {
             return $table->getElementsByTagName('tr');
         } else {
             // if item(0) is null throw exception
             $message = 'Could not locate a table in html';
             // TODO - remove this Logger entry once things are stable - leave the exception tho!
             // lets log the HTML for now so we can track why things went snap! all current tables have rows so to
             // trip this exception something had to have gone "bad-a-boom"
             Logger::getInstance()->write(ERROR, $message, $html);
             throw new \Exception($message);
         }
     } else {
         throw new \LogicException('html should not be empty.');
     }
 }