static function register($table, $key, $value = "") { // create the global config object if not available if (!array_key_exists('config', $GLOBALS)) { $GLOBALS['config'] = array(); } // exit now if variable already available $key_exists = array_key_exists($table, $GLOBALS['config']) && array_key_exists($key, $GLOBALS['config'][$table]) && !(empty($GLOBALS['config'][$table][$key]) && is_null($GLOBALS['config'][$table][$key])); if ($key_exists) { return; } // then check if the table exists if (empty($GLOBALS['config'][$table])) { $config = new Config(0, $table); // FIX: The id needs to be setup as autoincrement //$config->create_table($table, "id INTEGER PRIMARY KEY ASC," . implode(",", array_keys( $config->rs )) ); $config->create_table($table, "id INTEGER PRIMARY KEY ASC, key, value"); $GLOBALS['config'][$table] = array(); } // we already know the key doesn't exist - just create it $config = new Config(0, $table); $config->set('key', "{$key}"); // FIX: special case for admin password (use cipher if available) $cipher = is_null(CIPHER) ? $value : CIPHER; $value = $key == "admin_password" ? crypt($value, $cipher) : $value; $config->set('value', "{$value}"); $config->create(); // save in the global object $GLOBALS['config'][$table][$key] = $value; }
public function __construct(Config $config = null) { $this->config = $config; if (!$config) { $this->config = Config::create(); } }
/** * เรียกใช้งาน Class แบบสามารถเรียกได้ครั้งเดียวเท่านั้น * * @param array $config ค่ากำหนดของ แอพพลิเคชั่น * @return Singleton */ public function __construct() { /* display error */ if (defined('DEBUG') && DEBUG === true) { /* ขณะออกแบบ แสดง error และ warning ของ PHP */ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); } else { /* ขณะใช้งานจริง */ error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); } /* config */ self::$cfg = \Config::create(); /* charset default UTF-8 */ ini_set('default_charset', self::$char_set); if (extension_loaded('mbstring')) { mb_internal_encoding(self::$char_set); } /* inint Input */ Input::normalizeRequest(); // template ที่กำลังใช้งานอยู่ Template::inint(Input::get($_GET, 'skin', self::$cfg->skin)); /* time zone default Thailand */ @date_default_timezone_set(self::$cfg->timezone); }
public function __construct() { $conf = Config::create()->getConf(); $this->host = $conf['host']; $this->database = $conf['database']; $this->login = $conf['login']; $this->password = $conf['password']; $this->connect(); }
public function init($name) { if (self::STATUS_EMPTY != $this->status) { throw new Exception('a mydbvc library already exists.'); } if (!Config::create($this->root . 'mydbvc.yaml', $name) || !$this->repair()) { return false; } return true; }
/** * @param array $keys * @param User $user * @param int $profile_id * * @return array */ public static function getByKeysAsArray($keys, $user, $profile_id) { $config = Config::create()->where('key', $keys[0])->get(1); $return = array(); $available_configs = $config->available_config->get()->all_to_array(); foreach ($available_configs as $available_config) { $tokens = Access_token::getAllByTypeAndUserIdAndProfileIdAsArray($available_config['type'], $user->id, $profile_id); $config = new Config($available_config['config_id']); $config = $config->to_array(); foreach ($tokens as $token) { $_element = array('token' => $token, 'config' => $config, 'values' => array()); foreach ($keys as $key) { $_element['values'][$key] = $user->ifUserHasConfigValue($key, $token['id']); } $return[$available_config->type][] = $_element; } } return $return; }
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['restless' => TRUE]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['root_directory' => 'external/testing/views']);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['disabled' => FALSE, 'map' => ['default' => ['namespace' => 'App\\Model', 'connection' => ['driver' => NULL, 'dbname' => NULL, 'host' => NULL, 'port' => NULL, 'user' => NULL, 'password' => NULL, 'charset' => 'utf-8']]]]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\View', 'root_directory' => 'user/views', 'helper_directory' => 'library/helpers/view', 'extension_map' => [], 'cache_mode' => NULL, 'cache_directory' => 'assets/cache', 'asset_filters' => ['css' => [], 'js' => []]]);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['active_domain' => NULL, 'execution_mode' => 'development', 'write_directory' => 'writable', 'display_errors' => NULL, 'error_level' => E_ALL & ~E_STRICT, 'error_email_to' => NULL, 'cache' => ['type' => 'apc'], 'default_timezone' => 'America/Los_Angeles', 'date_formats' => ['console_date' => 'M jS, Y', 'console_time' => 'g:ia', 'console_timestamp' => 'M jS, Y @ g:ia'], 'aliases' => ['Core' => 'Dotink\\Flourish\\Core', 'Date' => 'Dotink\\Flourish\\Date', 'Directory' => 'Dotink\\Flourish\\Directory', 'File' => 'Dotink\\Flourish\\File', 'JSON' => 'Dotink\\Flourish\\JSON', 'Text' => 'Dotink\\Flourish\\Text', 'Time' => 'Dotink\\Flourish\\Time', 'Timestamp' => 'Dotink\\Flourish\\Timestamp', 'URL' => 'Dotink\\Flourish\\URL', 'UTF8' => 'Dotink\\Flourish\\UTF8']]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['auto_scaffold' => TRUE, 'root_directory' => 'external/testing/models']);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['types' => [], 'map' => ['default' => ['connection' => ['driver' => 'pdo_sqlite', 'dbname' => NULL, 'path' => implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'external', 'testing', 'sample.db'])], 'types' => []]]]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\Model', 'auto_scaffold' => FALSE, 'auto_load' => TRUE, 'root_directory' => 'user/models']);
<?php namespace Dotink\Inkwell; // // Redirect maps take the following format: // // type = [ // route => translation // ] // // The route is defined exactly as it is in the routes configuration with a valid route // pattern such as: // // /articles/[!:slug] // // The translation is similar, but does not require a pattern token. All matching tokens from // the route will be placed in the translation at the specified points: // // /blog/articles/[slug] // // Full Example: // // 301 => [ // '/articles/[!:slug]' => '/blog/articles/[slug]' // ] // // The above would redirect /articles/my_awesome_article to /blog/articles/my_awesome_article // return Config::create(['Core'], [HTTP\REDIRECT_PERMANENT => [], HTTP\REDIRECT_TEMPORARY => []]);
// // Example: // // /map/[%:longitude]/[%:latitude] // // Match URLs: // // /map/0.3509/2.2742 // /map/-3.2357/45.2352 // // Example: // // /articles/[#:year]-[#:month]-[#:day]/[!:slug] // // Match URLs: // // /articles/2009-08-17/how_i_met_your_mother // // The pattern can optionally be a regular expression if it is wrapped in parenthesis, however // if you need to group internal patterns be sure to specify a non-capturing set. // // The parameter name is allowed to contain any character except for the ':' and ']'. Although // you should probably be sane with it. // // The action (i.e. the value in the key/value pair), can be a valid PHP function name, // closure, class::method string callback, or array callback. It is important to note that // classes will be instantiated by the router prior to calling the method, even if the string // callback takes on the form of a static method. // return Config::create(['Core'], ['base_url' => '/', 'actions' => [], 'handlers' => []]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\Router', 'restless' => FALSE, 'word_separator' => '_']);
<?php $name = $_POST['name']; if (0 === Config::create($name)) { echo $name; }
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\Response', 'default_type' => 'text/html', 'states' => [HTTP\OK => ['code' => 200, 'body' => NULL], HTTP\CREATED => ['code' => 201, 'body' => NULL], HTTP\ACCEPTED => ['code' => 202, 'body' => NULL], HTTP\NO_CONTENT => ['code' => 204, 'body' => NULL], HTTP\BAD_REQUEST => ['code' => 400, 'body' => 'The request could not be understood'], HTTP\NOT_AUTHORIZED => ['code' => 401, 'body' => 'The requested resource requires authorization'], HTTP\FORBIDDEN => ['code' => 403, 'body' => 'You do not have permission to view the requested resource'], HTTP\NOT_FOUND => ['code' => 404, 'body' => 'The requested resource could not be found'], HTTP\NOT_ALLOWED => ['code' => 405, 'body' => 'The requested resource does not support this method'], HTTP\NOT_ACCEPTABLE => ['code' => 406, 'body' => 'The requested resource is not available in the accepted parameters'], HTTP\SERVER_ERROR => ['code' => 500, 'body' => 'The requested resource is not available due to an internal error'], HTTP\UNAVAILABLE => ['code' => 503, 'body' => 'The requested resource is temporarily unavailable']]]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\Scaffolder', 'root_directory' => 'user/scaffolding', 'scope' => ['vendor' => 'Vendor', 'module' => 'Project', 'author' => 'Jamie Doe', 'copyright' => 'Acme, Inc.', 'tag' => 'user', 'email' => '*****@*****.**']]);
/** * ตรวจสอบการ login เมื่อมีการเรียกใช้ class new Login * action=logout ออกจากระบบ * มาจากการ submit ตรวจสอบการ login * ถ้าไม่มีทั้งสองส่วนด้านบน จะตรวจสอบการ login จาก session และ cookie ตามลำดับ * * @return \Login */ public static function create() { $obj = new static(); // ค่าที่ส่งมา $save = Input::filter($_POST); // ตรวจสอบการ login if (Input::get($_GET, 'error') === 'EMAIL_EXISIS') { // facebook login error มี email อยู่แล้ว self::$login_message = Language::get('This email is already registered'); } elseif (empty($save) && Input::get($_GET, 'action') === 'logout') { // logout ลบ session และ cookie unset($_SESSION['login']); $time = time(); setCookie('login_email', '', $time, '/'); setCookie('login_password', '', $time, '/'); self::$login_message = Language::get('Logout successful'); } elseif (isset($save['action']) && $save['action'] === 'forgot') { // ลืมรหัสผ่าน return $obj->forgot(); } else { // ตรวจสอบค่าที่ส่งมา if (isset($save['remember'])) { $login_remember = $save['remember']; } elseif (isset($_COOKIE['login_remember'])) { $login_remember = $_COOKIE['login_remember'] == 1 ? 1 : 0; } else { $login_remember = 0; } $pw = new Password(Config::create()->get('password_key')); foreach (array('login_email', 'login_password') as $name) { $key = str_replace('login_', '', $name); if (!isset($save[$key])) { foreach (array($_SESSION, $_COOKIE) as $var) { if (isset($var[$name])) { if ($var == $_COOKIE) { ${$name} = $pw->decode($var[$name]); } else { ${$name} = trim($var[$name]); } break; } } } else { ${$name} = $save[$key]; } } } if (isset($login_email) && isset($login_password)) { self::$text_email = $login_email; self::$text_password = $login_password; // ตรวจสอบการกรอก if (empty($login_email)) { self::$login_message = Language::get('Please fill out') . ' ' . Language::get('Email'); self::$login_input = 'text_email'; } elseif (empty($login_password)) { self::$login_message = Language::get('Please fill out') . ' ' . Language::get('Password'); self::$login_input = 'text_password'; } else { // ตรวจสอบการ login กับฐานข้อมูล $login_result = $obj->checkLogin($login_email, $login_password); if (is_string($login_result)) { // ข้อความผิดพลาด self::$login_input = $login_result == 'Incorrect password' ? 'text_password' : 'text_email'; self::$login_message = Language::get($login_result); } else { // save login session foreach ($login_result as $key => $value) { $_SESSION['login'][$key] = $value; } $_SESSION['login']['password'] = $login_password; // save login cookie $time = time() + 2592000; // password $pw = new Password(self::$cfg->password_key); if ($login_remember == 1) { setcookie('login_email', $pw->encode($login_result->email), $time, '/'); setcookie('login_password', $pw->encode($login_password), $time, '/'); setcookie('login_remember', $login_remember, $time, '/'); } setcookie('login_id', $login_result->id, $time, '/'); } } } // คืนค่า \Login return $obj; }
/** * Creates instance of App class and initialize the application * * @param array $params initialization parameters * @return void * @static */ public static function create(array $params = null) { self::$app_mode = self::MODE_DEVELOPMENT; if (is_null(self::$instance)) { self::$instance = new self(); } // setting up autoloader spl_autoload_register(array('App', 'autoload')); try { // setup config Config::create(isset($params['config']) ? $params['config'] : null); Config::setVar($params); // application mode self::setMode(Config::getVar('mode', self::MODE_DEVELOPMENT)); // our error handler if (!self::isDevMode()) { set_error_handler(array('App', 'handleErrors')); } // language specific params if (function_exists('mb_internal_encoding')) { mb_internal_encoding(Config::getVar('app_encoding', 'UTF-8')); } if (function_exists('date_default_timezone_set')) { date_default_timezone_set(Config::getVar('app_timezone', 'UTC')); } setlocale(LC_CTYPE, Config::getVar('app_locale', 'en_US.UTF-8')); // creating base objects Log::create(); Request::create(); // saving application params self::$params = $params; // unregister globals if (ini_get('register_globals')) { self::unregisterGlobals(array('_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES')); ini_set('register_globals', false); } } catch (Exception $e) { self::$instance->handleDefaultException($e); } }
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['root_directory' => 'external/testing/controllers']);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['filters' => [], 'methods' => ['Dotink\\Inkwell\\View' => 'make', 'Dotink\\Flourish\\Image' => 'output', 'Dotink\\Flourish\\JSON' => 'compose']]);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['actions' => ['/system_information' => 'phpinfo', '/test/' => 'TestController::main', '/test/[!:action]' => 'TestController::[action]', '/' => 'HomeController::main']]);
<?php namespace Dotink\Inkwell; return Config::create(['Library'], ['class' => __NAMESPACE__ . '\\Controller', 'auto_scaffold' => FALSE, 'auto_load' => TRUE, 'root_directory' => 'user/controllers', 'default_accept_types' => ['text/plain', 'text/html']]);
<?php namespace Dotink\Inkwell; return Config::create(['Core'], ['standards' => ['IW' => __NAMESPACE__ . '\\IW::transformClassToIW', 'PSR0' => __NAMESPACE__ . '\\IW::transformClassToPSR0'], 'map' => []]);