コード例 #1
0
ファイル: session.php プロジェクト: biggtfish/anchor-cms
 /**
  * Read the current session using the driver set in the config file
  */
 public static function read()
 {
     if (is_null(static::$cargo)) {
         $driver = static::factory(Config::session());
         static::$cargo = new Cargo($driver, Config::app('key'));
     }
     static::instance()->read();
 }
コード例 #2
0
ファイル: cookie.php プロジェクト: hpaul/Google-short
 /**
  * Save a session.
  *
  * @param  array  $session
  * @return void
  */
 public function save($session)
 {
     if (!headers_sent()) {
         extract(Config::get('session'));
         $payload = $this->crypter->encrypt(serialize($session));
         \System\Cookie::put('session_payload', $payload, $lifetime, $path, $domain, $https, $http_only);
     }
 }
コード例 #3
0
ファイル: memcached.php プロジェクト: biggtfish/anchor-cms
 public function __construct($config)
 {
     $this->config = $config;
     $this->key = Config::app('key');
     // setup the memcache server
     extract(Config::cache('memcached'));
     $this->server = new M();
     $this->server->addServer($host, $port);
 }
コード例 #4
0
ファイル: database.php プロジェクト: anchorcms/anchor-cms
 /**
  * Get a database connection by name r return the default
  *
  * @param string
  * @return object
  */
 public static function connection($name = null)
 {
     // use the default connection if none is specified
     if (is_null($name)) {
         $name = Config::db('default');
     }
     // if we have already connected just return the instance
     if (isset(static::$connections[$name])) {
         return static::$connections[$name];
     }
     // connect and return
     return static::$connections[$name] = static::factory(Config::db('connections.' . $name));
 }
コード例 #5
0
ファイル: connector.php プロジェクト: biggtfish/anchor-cms
 /**
  * A simple database query wrapper
  *
  * @param string
  * @param array
  * @return array
  */
 public function ask($sql, $binds = array())
 {
     try {
         if (Config::db('profiling')) {
             $this->queries[] = compact('sql', 'binds');
         }
         $statement = $this->instance()->prepare($sql);
         $result = $statement->execute($binds);
         return array($result, $statement);
     } catch (Exception $e) {
         $error = 'Database Error: ' . $e->getMessage() . '</code></p><p><code>SQL: ' . trim($sql);
         throw new Exception($error, 0, $e);
     }
 }
コード例 #6
0
ファイル: DB.php プロジェクト: DenchikBY/Simple-MVC-app
 public static function getConnection($connection = null)
 {
     $connection = $connection ?: self::$currentConnection ?: Config::get('db.default');
     if (!isset(self::$connections[$connection])) {
         $config = Config::get('db.connections.' . $connection);
         self::$connections[$connection] = new PDO($config['driver'] . ':host=' . $config['host'] . ';dbname=' . $config['database'], $config['username'], $config['password']);
         if ($config['driver'] == 'mysql') {
             self::$connections[$connection]->exec('set names utf8');
         }
         self::$connections[$connection]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     }
     $return =& self::$connections[$connection];
     return $return;
 }
コード例 #7
0
ファイル: UploadedFile.php プロジェクト: shlappdev/framework
 /**
  * Menyimpan file ke direktori
  * @param string $destination folder tujuan disarankan menggunakan ResourcesPath()
  * @param string $fileName    nama file (optional)
  */
 public static function save($destination, $fileName = '')
 {
     $extension = self::getExtension();
     if (!empty($fileName)) {
         self::$name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fileName) . "." . $extension;
     }
     if (file_exists(removeMultiple($destination . "/" . self::$name)) && self::$overwrite == FALSE) {
         //echo RemoveMultiple($destination . "/" . self::$Name);
         trigger_error("File already exist, to overwrite file set you can use \\UploadedFile::Overwrite(TRUE)", E_USER_ERROR);
     }
     if (self::$removeSpaces) {
         self::$name = str_replace(" ", "", self::$name);
     }
     // Jika nama file di encrypt
     if (self::$encryptName) {
         self::$name = md5(date("Y-m-d G:i:s" . Config::Get('App', 'AppKey')) . self::$name) . "." . $extension;
     }
     if (in_array($extension, self::$imageExtension)) {
         //move_uploaded_file(self::$File['tmp_name'], RemoveMultiple($destination . "/" . self::$Name));
         switch (strtolower($extension)) {
             case 'jpg':
             case 'jpeg':
                 $img = imagecreatefromjpeg(self::$file['tmp_name']);
                 imagejpeg($img, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'png':
                 $imgSource = imagecreatefrompng(self::$file['tmp_name']);
                 $width = imagesx($imgSource);
                 $height = imageSY($imgSource);
                 $im = imagecreatetruecolor($width, $height);
                 imagealphablending($im, false);
                 $colorTransparent = imagecolorallocatealpha($im, 0, 0, 0, 0x7fff0000);
                 imagefill($im, 0, 0, $colorTransparent);
                 imagesavealpha($im, true);
                 imagecopyresized($im, $imgSource, 0, 0, 0, 0, $width, $height, $width, $height);
                 imagepng($im, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'gif':
                 $img = imagecreatefromgif(self::$file['tmp_name']);
                 imagegif($img, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'bmp':
                 $img = imagecreatefromwbmp(self::$file['tmp_name']);
                 imagewbmp($img, removeMultiple($destination . "/" . self::$name));
                 break;
             default:
                 move_uploaded_file(self::$file['tmp_name'], removeMultiple($destination . "/" . self::$name));
                 break;
         }
         $imageSize = getimagesize(removeMultiple($destination . "/" . self::$name));
         $img = Image::make(removeMultiple($destination . "/" . self::$name));
         self::$tmpPath = removeMultiple($destination . "/" . self::$name);
         if (!empty(self::$resize)) {
             $img->resize(self::$resize['Width'], self::$resize['Height']);
             $img->save(removeMultiple($destination . "/" . self::$name));
         } else {
             if ($imageSize[0] > self::$maxImageSize['Width']) {
                 $img->resize(self::$maxImageSize['Width'], null, function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 $img->save(removeMultiple($destination . "/" . self::$name));
             } else {
                 if ($imageSize[1] > self::$maxImageSize['Height']) {
                     $img->resize(null, self::$maxImageSize['Height'], function ($constraint) {
                         $constraint->aspectRatio();
                     });
                     $img->save(removeMultiple($destination . "/" . self::$name));
                 }
             }
         }
     } else {
         move_uploaded_file(self::$file['tmp_name'], removeMultiple($destination . "/" . self::$name));
     }
     self::reset();
     return new self();
 }
コード例 #8
0
 /**
  * Remove the relative path from the uri set in the application config
  *
  * @param string
  * @return string
  */
 public static function remove_relative_uri($uri)
 {
     // remove base url
     if ($base = Config::app('url')) {
         $uri = static::remove(rtrim($base, '/'), $uri);
     }
     // remove index
     if ($index = Config::app('index')) {
         $uri = static::remove('/' . $index, $uri);
     }
     return $uri;
 }
コード例 #9
0
ファイル: apc.php プロジェクト: hpaul/Google-short
 /**
  * Delete an item from the cache.
  *
  * @param  string  $key
  * @return void
  */
 public function forget($key)
 {
     apc_delete(Config::get('cache.key') . $key);
 }
コード例 #10
0
ファイル: loader.php プロジェクト: hpaul/Google-short
 /**
  * Get all of the routes for the application.
  *
  * To improve performance, this operation will only be performed once. The routes
  * will be cached and returned on every subsequent call.
  *
  * @param  bool    $reload
  * @param  string  $path
  * @return array
  */
 public static function all($reload = false, $path = APP_PATH)
 {
     if (!is_null(static::$routes) and !$reload) {
         return static::$routes;
     }
     // Merge all of the module paths in with the specified path so that all
     // active module routes will also be loaded. So, by default, this method
     // will search the application path and all active module paths for routes.
     $paths = array_merge(array($path), array_map(function ($module) {
         return MODULE_PATH . $module . '/';
     }, Config::get('application.modules')));
     $routes = array();
     foreach ($paths as $path) {
         if (file_exists($path . 'routes' . EXT)) {
             $routes = array_merge($routes, require $path . 'routes' . EXT);
         }
         if (is_dir($path . 'routes')) {
             // Since route files can be nested deep within the route directory, we need to
             // recursively spin through the directory to find every file.
             $directoryIterator = new \RecursiveDirectoryIterator($path . 'routes');
             $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
             foreach ($recursiveIterator as $file) {
                 if (filetype($file) === 'file' and strpos($file, EXT) !== false) {
                     $routes = array_merge($routes, require $file);
                 }
             }
         }
     }
     return static::$routes = $routes;
 }
コード例 #11
0
ファイル: db.php プロジェクト: hpaul/Google-short
 /**
  * Get a session database query.
  *
  * @return Query
  */
 private function table()
 {
     return \System\DB::connection()->table(Config::get('session.table'));
 }
コード例 #12
0
ファイル: memcached.php プロジェクト: hpaul/Google-short
 /**
  * Save a session.
  *
  * @param  array  $session
  * @return void
  */
 public function save($session)
 {
     Cache::driver('memcached')->put($session['id'], $session, Config::get('session.lifetime'));
 }
コード例 #13
0
ファイル: Route.php プロジェクト: shlappdev/shl-framework
 public static function middleware()
 {
     $config = Config::get('App', 'Middleware');
     $global = $config['Global'];
     if (count($global) == 0) {
         $result = call_user_func_array([Request::$controller, Request::$function], Request::$parameters);
         print_r($result);
         return;
     }
     $controller = Request::$controller;
     Request::$middleware = array_merge($global, $controller->getMiddleware(), Request::$middleware);
     $middleware = 'App\\Middleware\\' . Request::$middleware[0];
     if (!class_exists($middleware)) {
         trigger_error("Middleware with the name '" . Request::$middleware[0] . "' not found", E_USER_ERROR);
     }
     array_shift(Request::$middleware);
     $middle = new $middleware();
     $middle();
 }
コード例 #14
0
ファイル: FileCache.php プロジェクト: shlappdev/framework
 /**
  * Mendapatkan file dan juga path cache
  * @param string $key
  */
 private static function getCacheFile($key)
 {
     $config = Config::get("Cache", "Configuration");
     $directory = removeMultiple($config['File']['Path']);
     $fileName = $config['File']['EncryptFileName'] ? md5($key) : $key;
     return removeMultiple($directory . "/" . $fileName . ".cache");
 }
コード例 #15
0
ファイル: response.php プロジェクト: biggtfish/anchor-cms
 /**
  * Sends the final headers cookies and output
  */
 public function send()
 {
     // dont send headers for CLI
     if (!Request::cli()) {
         // create a status header
         Status::create($this->status)->header();
         // always make sure we send the content type
         if (!array_key_exists('content-type', $this->headers)) {
             $this->headers['content-type'] = 'text/html; charset=' . Config::app('encoding', 'UTF-8');
         }
         // output headers
         foreach ($this->headers as $name => $value) {
             header($name . ': ' . $value);
         }
         // send any cookies we may have stored in the cookie class
         foreach (Cookie::$bag as $cookie) {
             call_user_func_array('setcookie', array_values($cookie));
         }
     }
     // output the final content
     if ($this->output) {
         echo $this->output;
     }
 }
コード例 #16
0
ファイル: handler.php プロジェクト: hpaul/Google-short
 /**
  * Log the exception using the logger closure specified in the error configuration.
  *
  * @return void
  */
 private function log()
 {
     $parameters = array($this->exception->severity(), $this->exception->message(), $this->exception->getTraceAsString());
     call_user_func_array(Config::get('error.logger'), $parameters);
 }
コード例 #17
0
ファイル: Cache.php プロジェクト: shlappdev/framework
 /**
  * Menghapus seluruh cache
  */
 public static function flush()
 {
     $cache = Config::get("Cache", "Cache");
     $config = Config::get("Cache", "Configuration");
     switch ($cache) {
         case 'File':
             return FileCache::flush();
             break;
         default:
             # code...
             break;
     }
 }
コード例 #18
0
ファイル: Form.php プロジェクト: shlappdev/framework
 /**
  * Menampilkan dropdown yang berisi hari, sumber data berasal dari Config
  * @param string    $name          nama input
  * @param string    $selected      option yang akan terpilih
  * @param array     $attributes    attribute input
  */
 public static function dropDownDay($name, $selected, $attributes)
 {
     return self::dropDown($name, Config::Get("Config", "Form")['DropDownDay'], $selected, $attributes);
 }
コード例 #19
0
ファイル: memcached.php プロジェクト: hpaul/Google-short
 /**
  * Delete an item from the cache.
  *
  * @param  string  $key
  * @return void
  */
 public function forget($key)
 {
     \System\Memcached::instance()->delete(Config::get('cache.key') . $key);
 }
コード例 #20
0
ファイル: error.php プロジェクト: anchorcms/anchor-cms
 /**
  * Exception logger
  *
  * Log the exception depending on the application config
  *
  * @param object The exception
  */
 public static function log($e)
 {
     if (is_callable($logger = Config::error('log'))) {
         call_user_func($logger, $e);
     }
 }