Пример #1
0
 public function read($id)
 {
     atsumi_Debug::startTimer('SESSION_READ');
     $result = $this->cache->get($id, null, 'SESSION');
     if (is_null($result)) {
         return '';
     }
     atsumi_Debug::record('Session loaded from cache', sf('Session ID: %s', $id), $result, 'SESSION_READ', atsumi_Debug::AREA_SESSION, $result);
     return $result;
 }
Пример #2
0
 /**
  * Constructor - Must use getInstance to get a session singalton object
  */
 protected function __construct($options = array())
 {
     // Start timer for constructor complete time
     atsumi_Debug::startTimer();
     $this->configure($options);
     // Fetch the session storage handler
     $storage = isset($options['storage']) ? $options['storage'] : self::DEFAULT_STORAGE;
     if (is_subclass_of($storage, 'session_AbstractStorage')) {
         $this->storage = new $storage($options);
     }
     // Start the session
     $this->start($options);
     // Add debug information
     atsumi_Debug::record('Session Created', 'The atsumi session constructor completed', null, true, atsumi_Debug::AREA_SESSION);
 }
Пример #3
0
 public function write($id, $sessionData)
 {
     try {
         if ($this->database->exists('session', 'checksum = %i AND session_id = %s', crc32($id), $id)) {
             atsumi_Debug::record('Updating Session', sf('The session(%s) is being updated to the DB', $id), atsumi_Debug::AREA_SESSION, base64_encode($sessionData));
             $this->database->update('session', 'checksum = %i AND session_id = %s', crc32($id), $id, 'data = %s', base64_encode($sessionData), 'last_active	= NOW()');
         } else {
             atsumi_Debug::record('Inserting Session', sf('The atsumi(%s) is being inserted to the DB: ', $id), atsumi_Debug::AREA_SESSION, $sessionData);
             $this->database->insert('session', 'checksum		= %i', crc32($id), 'session_id		= %s', $id, 'data			= %s', base64_encode($sessionData), 'last_active	= NOW()');
         }
         return true;
         /* this is a little drastic but will most likley segfault if Exception bubbles up */
     } catch (Exception $e) {
         die('Could not write session to database.');
     }
 }
Пример #4
0
 public function render($options = array())
 {
     // If elementOnly is specified, only the form element itself is returned
     if (isset($options['elementOnly']) && $options['elementOnly']) {
         $out = $this->renderElement();
     } else {
         $out = $this->preRender();
         $out .= sfl('<div class="row%s%s%s row_%s"%s>', $this->style ? " " . $this->style : "", $this->cssClass ? " " . $this->cssClass : "", $this->submitted && !$this->validates ? " error" : "", $this->name, $this->cssStyle ? " style='" . $this->cssStyle . "'" : "");
         try {
             $out .= sf('%s%s<div class="element">%s</div>', $this->renderErrors(), ($this->label != '' || $this->getRequired()) && (!array_key_exists('label', $options) || $options['label'] !== false) ? $this->renderLabel() : '', $this->renderElement());
         } catch (Exception $e) {
             // if in debug mode display exception details
             if (atsumi_Debug::getActive()) {
                 $out .= sfl('Element Exception "%s": %s #%s', $e->getMessage(), $e->getFile(), $e->getLine());
             }
             // fire error listeners
             Atsumi::error__listen($e);
         }
         $out .= '</div>';
         $out .= $this->postRender();
     }
     return $out;
 }
Пример #5
0
 public function __construct()
 {
     atsumi_Debug::setActive(false);
 }
Пример #6
0
 /**
  * Actually executes a sql string on the connected database.
  *
  * Direct use is not recommened.
  * @param string $sql
  * @throws db_NoConnectionException Thrown if there is no database connection.
  * @throws db_QueryFailedException Thrown if the query failed.
  */
 public function queryReal($sql)
 {
     if (!$this->connected) {
         throw new db_NoConnectionException('No Database Connection');
     }
     if ($this->debug) {
         $startTime = time() + microtime();
     }
     $this->affectedRows = null;
     try {
         $return = $this->pdo->query($sql);
         if ($return === false) {
             $error = $this->pdo->errorInfo();
             throw new PDOException(isset($error[2]) ? $error[2] : 'Database Error: ' . $error[0]);
         }
         $data = $return->fetchAll(PDO::FETCH_ASSOC);
         $this->affectedRows = count($data);
         if (!is_array($data)) {
             throw new PDOException('Failed to return data array');
         }
         if ($this->debug) {
             if (count($this->queryTimes) > 100) {
                 $this->queryTimes = null;
                 $this->debug = false;
                 atsumi_Debug::record('Too many queries to debug', 'Atsumi has disabled query debugging for this script as too many queries were fired.', atsumi_Debug::AREA_DATABASE, null);
             } else {
                 $this->queryTimes[] = array('sql' => $sql, 'time' => time() + microtime() - $startTime, 'row_count' => count($data));
             }
         }
         return $data;
     } catch (PDOException $e) {
         throw new db_QueryFailedException($e->getMessage() . "<h4>SQL:</h4>" . $sql);
     }
 }
 function preProcess()
 {
     parent::preProcess();
     atsumi_Debug::setActive(false);
 }
Пример #8
0
 /**
  * Initalises the application handler object used by Atsumi to process the developers
  * application as well as setting up any debug related items if debug is enabled
  * @param atsumi_AbstractAppSettings $settings
  */
 public function _initApp(atsumi_AbstractAppSettings $settings)
 {
     if ($settings->getDebug()) {
         atsumi_Debug::setActive(true);
         atsumi_Debug::setConfig($settings);
         $this->testEnviroment();
     } else {
         $this->errorHandler->setDisplayErrors(false);
     }
     $this->appHandler = new atsumi_AppHandler($settings, $this->errorHandler);
 }
Пример #9
0
 /**
  * Calls render on the processed controller
  * Note: process method must be execute before this method
  * @access public
  */
 public function render()
 {
     // Time and execute the pre render
     atsumi_Debug::startTimer('app:controller:preRender');
     $this->controller->publishFlashData();
     $this->controller->preRender();
     atsumi_Debug::record('Controller PreRender', 'Before rendering was processed the pre-render function was executed', null, 'app:controller:preRender');
     $viewHandler = $this->controller->getViewHandler();
     $view = $this->controller->getView();
     if (!in_array('mvc_ViewHandlerInterface', class_implements($viewHandler))) {
         throw new Exception('View handler must implement mvc_ViewHandlerInterface');
     }
     if (is_string($viewHandler)) {
         $viewHandler = new $viewHandler();
     }
     if (is_null($view)) {
         throw new mvc_NoViewSpecifiedException('A view has not been declared', $this->parserData['method']);
     }
     // Get the debugger and start a timer for rendering
     atsumi_Debug::startTimer('app:controller:rendering');
     $viewData = $this->controller->getViewData();
     atsumi_Debug::setViewData($viewData);
     // Time and execute the view handler
     atsumi_Debug::startTimer('app:controller:render');
     $viewHandler->render($view, $viewData);
     atsumi_Debug::record('Rendering', sf('Rendering was performed by the %s view handler', get_class($viewHandler)), null, 'app:controller:render');
     // tell the debug to print if required as connection will be closed by __destruct
     atsumi_Debug::printIfRequired();
     // Time and execute the post render
     atsumi_Debug::startTimer('app:controller:postRender');
     $this->controller->postRender();
     atsumi_Debug::record('Controller PostRender', 'After the rendering was processed the post-render function was executed', null, 'app:controller:postRender');
     // Log the whole processing time
     atsumi_Debug::record('Rendering Complete', 'All rendering was completed successfully', null, 'app:controller:rendering');
 }
Пример #10
0
 /**
  * Clears the cache store of all stored values
  * @access public
  * @return boolen True on success or, False on failure
  */
 public final function flush()
 {
     try {
         return $this->_flush();
     } catch (Exception $e) {
         atsumi_Debug::record('Cache Handler failed to flush', $e->getMessage(), false, atsumi_Debug::AREA_CACHE);
         return false;
     }
 }