public static function cmd($str, $root = false) { $las = \Las\Library\Arr::from_model(Settings::find(array('status = ' . Settings::ACTIVE)), 'category', array('name' => 'value')); if ($root) { $crypt = \Phalcon\DI::getDefault()->getShared('crypt'); exec('echo ' . $crypt->decryptBase64($las['general']['rootPassword']) . ' | su -c ' . '"' . $str . '"', $results); } else { exec($str, $results); } if ($las['general']['debugCmd']) { $results = Dump::one($results, 'output'); $results .= Dump::one($str, 'commands'); } return $results; }
/** * Display Real SQL Statement * * <code> * $eventsManager = new \Phalcon\Events\Manager(); * $eventsManager->attach('db', new \Las\Extension\Listener()); * $this->db->setEventsManager($eventsManager); * * $query = $this->db->convertBoundParams('SELECT * FROM `users` WHERE `user_id` = :user_id:', array(':user_id' => 1)); * $user = $this->db->fetchAll($query['sql'], \Phalcon\Db::FETCH_ASSOC, $query['params']); * </code> * * @package las * @version 1.0 */ public function beforeQuery($event, $connection, $params) { $statement = $connection->getSQLStatement(); // If params is not empty if (!empty($params)) { // Check if params is assoc array if (array_keys($params) !== range(0, count($params) - 1)) { // Real SQL Statement $statement = str_replace(array_keys($params), array_values($params), $statement); } else { // Real SQL Statement after convertBoundParams foreach ($params as $param) { $statement = preg_replace('/\\?/', '"' . $param . '"', $statement, 1); } } } echo Dump::all($statement); }
/** * Catch the exception and log it, display pretty view * * @package las * @version 1.0 * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output echo Dump::all($errors); } else { // Display pretty view of the error $di = new \Phalcon\DI\FactoryDefault(); $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->setViewsDir(ROOT_PATH . '/app/frontend/views/'); $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di)); echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config)); // Log errors to file and send email with errors to admin \Las\Bootstrap::log($errors); } }