예제 #1
0
 /**
  * Find and return records from database by param
  *
  * @access public
  * @static
  *
  * @param string $record
  *
  * @return array|ActiveRecord
  * @throws \Framework\Exception\DataBaseException
  * @throws \Framework\Exception\ServiceException
  */
 public static function find($record)
 {
     if (!isset(static::$database)) {
         self::$database = Service::get('dataBase');
     }
     if ($record == static::ALL_RECORDS) {
         $allRecords = self::$database->selectAll(static::getTable());
         $posts = array();
         foreach ($allRecords as $rec) {
             $posts[] = new static($rec);
         }
         return $posts;
     } else {
         $record = self::$database->select(static::getTable(), array('*'), array('id' => $record));
         return new static($record);
     }
 }
예제 #2
0
 /**
  * Application constructor
  *
  * @access public
  *
  * @param $config
  */
 public function __construct($config)
 {
     try {
         Service::setSimple('config', $this->config = (require_once $config));
         Service::set('request', 'Framework\\Request\\Request');
         Service::setSingleton('router', $this->router = new Router());
         Service::setSingleton('session', Sessions::getInstance());
         Service::setSingleton('dataBase', DataBase::getInstance());
         Service::set('security', 'Framework\\Security\\Security');
         Service::setSingleton('flushMessenger', 'Framework\\FlushMessenger\\FlushMessenger');
         Service::set('app', $this);
     } catch (ServiceException $e) {
     } catch (\Exception $e) {
     } finally {
         if (isset($e)) {
             $code = isset($code) ? $code : 500;
             $errorMessage = isset($errorMessage) ? $errorMessage : 'Sorry for the inconvenience. We are working
             to resolve this issue. Thank you for your patience.';
             $responce = MainException::handleForUser($e, array('code' => $code, 'message' => $errorMessage));
             $responce->send();
         }
     }
 }