Пример #1
0
 /**
  * Return random database resource object
  * @param string $group Group name
  * @return boolean|\Sonic\Model\PDO
  */
 public static function &_getRandomDbResource($group)
 {
     $obj = FALSE;
     while (Sonic::countResourceGroup($group) > 0) {
         $name = Sonic::selectRandomResource($group);
         $obj =& Sonic::getResource(array($group, $name));
         // If a PDO object
         if ($obj instanceof \PDO) {
             // Attempt to connect to the resource
             // This will throw an exception if it fails or break the loop if it succeeds
             if ($obj instanceof Resource\Db) {
                 try {
                     $obj->Connect();
                     // Set as default group object for persistence
                     Sonic::setSelectedResource($group, $name);
                     break;
                 } catch (\PDOException $e) {
                     // Do nothing
                 }
             } else {
                 break;
             }
         }
         // Remove resource from the framework as its not valid
         // then continue to the next object
         Sonic::removeResource($group, $name);
         $obj = FALSE;
     }
     return $obj;
 }
Пример #2
0
 /**
  * Deal with an exception
  * @param Exception $exception Exception
  * @return void
  */
 public function Exception($exception)
 {
     // Auditlog
     $auditlog = Sonic::getResource('auditlog');
     if ($auditlog instanceof Resource\Audit\Log) {
         $auditlog::_Log(get_called_class() . '\\' . $this->action, 7, $this->request, array('file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $exception->getMessage()));
     }
     // Display message
     echo 'Uncaught exception `' . $exception->getMessage() . '` in ' . $exception->getFile() . ' on line ' . $exception->getLine();
 }