public function __construct() { $this->config = (require 'app/config/database.php'); $driver = $this->config['connections'][$this->config['default']]; $username = isset($driver['user']) ? $driver['user'] : null; $password = isset($driver['password']) ? $driver['password'] : null; $options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]; try { switch ($driver['driver']) { case 'mysql': $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database']; break; case 'pgsql': $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database'] . ';port=' . $driver['port']; break; case 'sqlite': $options = null; $dsn = $driver['driver'] . ':' . $driver['database']; break; default: $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database']; } parent::__construct($dsn, $username, $password, $options); $this->pdo = new TraceablePDO($this); Config::getInstance()->set(array('pdo' => $this->pdo)); } catch (PDOException $e) { throw new Exception($e->getMessage()); } }
/** * Twig::render() * * @param mixed $name * @param mixed $vars_array */ public function render($name, $vars_array = array()) { if (DEBUGING === true) { $debugBar = new DebugBar(); $debugBar->addCollector(new MessagesCollector()); $debugBar->addCollector(new ConfigCollector(Config::get())); $doctrine = Config::get('doctrine'); if ($doctrine) { $debugBar->addCollector(new DoctrineCollector($doctrine)); } $debugBar->addCollector(new TimeDataCollector()); $debugBar->addCollector(new RequestDataCollector()); $debugBar->addCollector(new MemoryCollector()); } $twig = $this->getInstance(); $content = $twig->loadTemplate($name . '.html.twig'); if (DEBUGING === true) { $debugBarRender = $debugBar->getJavascriptRenderer(); $bar['bar']['head'] = $debugBarRender->renderHead(); $bar['bar']['body'] = $debugBarRender->render(); $vars_array = array_merge($vars_array, $bar); } $args = array_merge($this->getGlobalArgs(), $vars_array); echo $content->render($args); }
public static function create_hash($data) { $hash = Config::get('hash'); $context = hash_init($hash['hash_algorithm'], HASH_HMAC, $hash['hash_general_key']); hash_update($context, $data); return hash_final($context); }
public function __construct() { // Get configs $this->config = Config::get(); // Create View $this->view = new Twig(); $doctrine = new DoctrineBridge(); $this->em = $doctrine->getEm(); }
public static function app_backup() { $config = Config::get(); $destination = $config['backup']['path']; $zip = new Zip(); $zip->setArchiveName($destination . '/' . 'backup_' . date('d.m.Y')); $zip->setPath('/'); $zip->zip(); }
public static function send($to, $subject, $message, $charset = 'utf-8') { $email = Config::get('email'); $from = Config::get('from') ? Config::get('from') : null; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset={$charset}\r\n"; $headers .= "From: {$from} <{$email}>\r\n"; mail($to, $subject, $message, $headers); }
public function __construct($path_to_image, $output) { $config = Config::get('image'); $this->max_width = $config['max_width']; $this->max_height = $config['max_height']; $this->quality = $config['quality']; $this->imagesource = $path_to_image; $file = pathinfo($this->imagesource); $this->imagefullname = $file['basename']; $this->imagename = $file['filename']; $this->imagepath = $file['dirname']; list($this->original_width, $this->original_height) = getimagesize($this->imagesource); $this->ratio = $this->original_width / $this->original_height; if ($output) { $this->output = $this->imagepath . DIRECTORY_SEPARATOR . $output; } else { $this->output = $this->imagepath . DIRECTORY_SEPARATOR . $this->imagefullname; } }
public function addLangVars($lang = null) { $views = Config::get('settings', 'modules'); foreach ($views as $view) { $dir = explode('/', $view); $lang_dir = 'app/' . $dir[0] . '/lang'; $di = new Dirs(); if (is_dir($lang_dir) && !$di->isEmptyDirectory($lang_dir)) { if (is_file($lang_dir . '/' . $lang . '.php')) { $vars = (require_once $lang_dir . '/' . $lang . '.php'); } elseif (is_file($lang_dir . '/' . $this->config['default_lang'] . '.php')) { $vars = (require_once $lang_dir . '/' . $this->config['default_lang'] . '.php'); } else { $files = $di->getFiles(); $vars = (require_once $lang_dir . '/' . $files[0]); } $this->lang_var = array_merge($this->lang_var, $vars); } } }
/** * @param $path_to_image * @param $output */ public function __construct($path_to_image, $output) { $config = Config::get('image'); $this->max_width = $config['max_width']; $this->max_height = $config['max_height']; $this->quality = $config['quality']; $this->imagesource = new Imagick($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $path_to_image); $file = pathinfo($this->imagesource->getimagefilename()); $this->imagefullname = $file['basename']; $this->imagename = $file['filename']; $this->imagepath = $file['dirname']; $size = $this->imagesource->getimagegeometry(); $this->original_width = $size['width']; $this->original_height = $size['height']; $this->ratio = $this->original_width / $this->original_height; if ($output) { $this->output = $this->imagepath . DIRECTORY_SEPARATOR . $output; } else { $this->output = $this->imagepath . DIRECTORY_SEPARATOR . $this->imagefullname; } }
public function __construct() { $config = (require 'app/config/database.php'); $driver = 'pdo_mysql'; $db_config = $config['connections'][$config['default']]; $username = isset($db_config['user']) ? $db_config['user'] : null; $password = isset($db_config['password']) ? $db_config['password'] : null; $database = isset($db_config['database']) ? $db_config['database'] : null; // set up the configuration $configDoctrine = new Configuration(); foreach (Config::get('settings', 'modules') as $controller) { if (is_dir('src/' . $controller . '/Entity')) { $paths[] = 'src/' . $controller . '/Entity'; } } $isDevMode = true; $driverImpl = $configDoctrine->newDefaultAnnotationDriver($paths, false); $configDoctrine->setMetadataDriverImpl($driverImpl); if ($isDevMode) { // set up simple array caching for development mode $cache = new ArrayCache(); } else { // set up caching with APC for production mode $cache = new ApcCache(); } $configDoctrine->setMetadataCacheImpl($cache); $configDoctrine->setQueryCacheImpl($cache); // set up proxy configuration $configDoctrine->setProxyDir('cache/Proxies'); $configDoctrine->setProxyNamespace('Proxies'); // auto-generate proxy classes if we are in development mode $configDoctrine->setAutoGenerateProxyClasses($isDevMode); // the connection configuration $dbParams = array('driver' => $driver, 'user' => $username, 'password' => $password, 'dbname' => $database, 'driverOptions' => array(1002 => 'SET NAMES utf8')); $debugStack = new DebugStack(); $this->em = EntityManager::create($dbParams, $configDoctrine); $this->getEm()->getConnection()->getConfiguration()->setSQLLogger($debugStack); Config::getInstance()->set(array('doctrine' => $this->getEm())); }
public static function readSessionFromDb($key = null) { $config = Config::get('session'); if (!$key) { $key = $config['cookie_default_key']; } if ($config['session_use_db'] === true) { $session_key = !is_null(self::getSession($key)) ? self::getSession($key) : self::getCookie($key); if ($session_key) { $db = new Database(); $result = $db->select("SELECT user_data FROM {$config['session_db_table']} WHERE session_key='{$session_key}'"); if (!empty($result)) { $user_data = unserialize($result[0]['user_data']); return $user_data; } else { return false; } } else { return false; } } return null; }
public static function get($key = null, $subkey = null) { $config = Config::getInstance()->config['database']; // If 'use_db_settings' = true, get settings from Database if ($config['use_db'] === true && $config['use_db_settings'] === true) { $db = new Database(); $settings = $db->select("SELECT data FROM {$config['table_db_settings']} WHERE 1"); // Add settings to the global config Config::getInstance()->combineSettings(array('settings' => json_decode($settings[0]['data'], true))); } foreach (Config::getInstance()->config['settings']['modules'] as $module) { if (is_file('App/' . $module . '/config/config.php')) { $config = (require 'App/' . $module . '/config/config.php'); Config::getInstance()->combineSettings(array('settings' => $config)); } } if ($key) { if (array_key_exists($key, Config::getInstance()->config)) { if ($subkey) { if (array_key_exists($subkey, Config::getInstance()->config[$key])) { return Config::getInstance()->config[$key][$subkey]; } else { return false; } } else { return Config::getInstance()->config[$key]; } } else { return null; } } else { return Config::getInstance()->config; } }
/** * Application::__construct() * * @param array $config */ public function __construct(array $config) { isset($config['debug']) ? error_reporting(E_ALL | E_STRICT) && define('DEBUGING', true) : error_reporting(0) && define('DEBUGING', false); isset($config['default_controller']) ? $this->defaultFile = trim($config['default_controller'], '/') : null; Config::getInstance()->set(array('default_controller' => $config['default_controller'])); }
public function __construct($file) { $this->file = $file; $this->config = Config::get('upload'); }