本文整理汇总了PHP中application类的典型用法代码示例。如果您正苦于以下问题:PHP application类的具体用法?PHP application怎么用?PHP application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructing crypt object
*
* @param string $db_link
* @param string $class
*/
public function __construct($crypt_link = null, $class = null, $options = [])
{
// if we need to use default link from application
if ($crypt_link == null) {
$crypt_link = application::get(['flag', 'global', 'crypt', 'default_crypt_link']);
if (empty($crypt_link)) {
throw new Exception('You must specify crypt link!');
}
}
// get object from factory
$temp = factory::get(['crypt', $crypt_link]);
// if we have class
if (!empty($class) && !empty($crypt_link)) {
// replaces in case we have it as submodule
$class = str_replace('.', '_', trim($class));
// creating new class
unset($this->object);
$this->object = new $class($crypt_link, $options);
factory::set(['crypt', $crypt_link], ['object' => $this->object, 'class' => $class]);
} else {
if (!empty($temp['object'])) {
$this->object = $temp['object'];
} else {
throw new Exception('You must specify crypt link and/or class!');
}
}
}
示例2: init
public function init()
{
if ($this->_inited) {
return;
}
$this->_inited = true;
$config = application::get_instance()->config->user;
$config->model = array();
$config->model->user = isset($config->model->user) ? $config->model->user : $this->default_model_user;
$this->model_user = 'model_' . $config->model->user;
if (class_exists($this->model_user)) {
$this->model_user = new $this->model_user();
$this->_key = 'user_' . $this->model_user->name;
}
$this->model_usersoc = 'model_' . (isset($config->model->usersoc) ? $config->model->usersoc : $this->default_model_usersoc);
$this->model_usersoc = class_exists($this->model_usersoc) ? new $this->model_usersoc() : null;
if ($config->acl) {
$this->model_role = 'model_' . (isset($config->model->role) ? $config->model->role : $this->default_model_role);
$this->model_role = class_exists($this->model_role) ? new $this->model_role() : null;
$this->model_rule = 'model_' . (isset($config->model->rule) ? $config->model->rule : $this->default_model_rule);
$this->model_rule = class_exists($this->model_rule) ? new $this->model_rule() : null;
$this->model_resource = 'model_' . (isset($config->model->resource) ? $config->model->resource : $this->default_model_resource);
$this->model_resource = class_exists($this->model_resource) ? new $this->model_resource() : null;
$this->model_role2role = 'model_' . (isset($config->model->role2role) ? $config->model->role2role : $this->default_model_role2role);
$this->model_role2role = class_exists($this->model_role2role) ? new $this->model_role2role() : null;
$this->model_rule2role = 'model_' . (isset($config->model->rule2role) ? $config->model->rule2role : $this->default_model_rule2role);
$this->model_rule2role = class_exists($this->model_rule2role) ? new $this->model_rule2role() : null;
$this->model_rule2resource = 'model_' . (isset($config->model->rule2resource) ? $config->model->rule2resource : $this->default_model_rule2resource);
$this->model_rule2resource = class_exists($this->model_rule2resource) ? new $this->model_rule2resource() : null;
$this->init_acl();
}
$this->salt = $config->salt;
$this->login_auto();
}
示例3: __get
function __get($k)
{
if ($k == 'view') {
return $this->view;
}
// Смысл класса сущности - в создании виртуальных переменных класса, не связанных с данными сущности. Виртуальная переменная транслируется в метод get_имя_паременной класса сущности, который должен вернуть ее значение
$method = 'get_' . $k;
$k_replaced = preg_replace('/\\_(valid|control|lang)$/i', '', $k);
if (method_exists($this, $method)) {
$ret = $this->{$method}();
} else {
$ret = $this->get($k);
if ($ret === null && $k != $k_replaced) {
$ret = $this->get($k_replaced);
}
}
if ($k != $k_replaced) {
$reg = application::get_instance()->controller->view->lang(true);
if ($reg && array_key_exists('ml_' . $k_replaced . '_' . $reg->id, $this->_data)) {
$ret_lang = $this->get('ml_' . $k_replaced . '_' . $reg->id);
if (strlen($ret_lang) == 0) {
if (array_key_exists('ml_' . $k_replaced . '_' . application::get_instance()->controller->view->lang()->default->id, $this->_data)) {
$ret_lang = $this->get('ml_' . $k_replaced . '_' . application::get_instance()->controller->view->lang()->default->id);
if (strlen($ret_lang) > 0) {
$ret = $ret_lang;
}
}
} else {
$ret = $ret_lang;
}
}
}
return $ret;
}
示例4: build
/**
* URL组装,兼容各种路由模式
*
* @param string $url 如:admin://system/msg/send/username/args2 或者 system/msg/send/username/args2
* @param array $params 参数
* @param string $fragment 锚点名称或者框架名称
* @return string 完整的url
*/
public static function build($uri, $params = array(), $fragment = '')
{
$uri = trim($uri, '/');
//去掉开头结尾的 / 符号,或者去掉分隔符
if (strpos($uri, '://') === false) {
$uri = router::application() . '://' . $uri;
}
$uris = parse_url($uri);
$paths = explode('/', trim($uris['path'], '/'));
$urls = array();
$urls['base'] = $uris['scheme'] == router::application() ? url::base() : application::settings($urls['scheme'], 'base');
$urls['module'] = $uris['host'];
$urls['controller'] = $paths[0];
$urls['action'] = $paths[1];
//zotop::dump($urls);
if (zotop::config('zotop.url.model') == 0) {
} else {
$url = $urls['base'];
if (zotop::config('zotop.url.model') == 2) {
$url = $url . '?zotop=';
//开启兼容模式
}
$url = $url . '/' . $urls['module'] . '/' . $urls['controller'] . '/' . $urls['action'];
if (!empty($params)) {
foreach ($params as $key => $value) {
$url .= '/' . $value;
}
}
}
if (!empty($fragment)) {
$url .= '#' . $fragment;
}
return url::clean($url);
}
示例5: action_index
public function action_index()
{
// clear buffer
helper_ob::clean_all();
// validating
do {
$options = application::get('flag.numbers.backend.cron.base');
// token
if (!empty($options['token']) && request::input('token') != $options['token']) {
break;
}
// ip
if (!empty($options['ip']) && !in_array(request::ip(), $options['ip'])) {
break;
}
// get date parts
$date_parts = format::now('parts');
print_r($date_parts);
echo "GOOD\n";
} while (0);
// we need to validate token
//$token = request::input('token');
echo "OK\n";
// exit
exit;
}
示例6: connect
/**
* Connect
*
* @param array $options
* @return array
*/
public function connect($options)
{
$result = ['success' => false, 'error' => []];
$this->options = $options;
// for deployed code the directory is different because we relate it based on code
if (!empty($this->options['dir']) && application::is_deployed()) {
$temp = $this->options['dir'][0] . $this->options['dir'][1];
if ($temp == './') {
$this->options['dir'] = './.' . $this->options['dir'];
} else {
$this->options['dir'] = '../';
}
}
// check if we have valid directory
if (empty($this->options['dir'])) {
$result['error'][] = 'Storage directory does not exists or not provided!';
} else {
// fixing path
$this->options['dir'] = rtrim($this->options['dir'], '/') . '/';
// we need to create directory
if (!empty($this->cache_key)) {
$this->options['dir'] .= $this->cache_key . '/';
}
// we need to create cache directory
if (!is_dir($this->options['dir'])) {
if (!helper_file::mkdir($this->options['dir'], 0777)) {
$result['error'][] = 'Unable to create caching directory!';
return $result;
}
}
$result['success'] = true;
}
return $result;
}
示例7: __construct
/**
* Constructing cache object
*
* @param string $cache_link
* @param string $class
*/
public function __construct($cache_link = null, $class = null)
{
// if we need to use default link from application
if (empty($cache_link)) {
$cache_link = application::get(['flag', 'global', 'cache', 'default_cache_link']);
if (empty($cache_link)) {
throw new Exception('You must specify cache link and/or class!');
}
}
// get object from factory
$temp = factory::get(['cache', $cache_link]);
// if we have class
if (!empty($class) && !empty($cache_link)) {
// replaces in case we have it as submodule
$class = str_replace('.', '_', trim($class));
// if we are replacing database connection with the same link we
// need to manually close connection
if (!empty($temp['object']) && $temp['class'] != $class) {
$object = $temp['object'];
$object->close();
unset($this->object);
}
$this->object = new $class($cache_link);
// putting every thing into factory
factory::set(['cache', $cache_link], ['object' => $this->object, 'class' => $class]);
} else {
if (!empty($temp['object'])) {
$this->object = $temp['object'];
} else {
throw new Exception('You must specify cache link and/or class!');
}
}
}
示例8: get_url_valid
function get_url_valid()
{
if ($this->url) {
return $this->url;
}
$route = $this->route ? $this->route : 'default';
$p = array('controller' => $this->controller, 'action' => $this->action);
if ($this->param) {
if (is_string($this->param)) {
$param = explode(',', $this->param);
$map = is_string($this->map) ? explode(',', $this->map) : array();
if ($map) {
foreach ($map as $n => $el) {
$el = trim($el);
if ($el) {
$p[$el] = trim(@$param[$n]);
}
}
}
} else {
$pp = clone $this->param;
if ($pp instanceof data) {
$pp = $pp->to_array();
}
$p = array_merge($p, $pp);
}
}
$view = application::get_instance()->controller->view;
$href = $view->url($p, $route);
return $href;
}
示例9: init
/**
* Initializing i18n
*
* @param array $options
*/
public static function init($options = [])
{
$i18n = application::get('flag.global.i18n') ?? [];
$i18n = array_merge_hard($i18n, $options ?? []);
// determine final language
$languages = factory::model('numbers_backend_i18n_languages_model_languages')->get();
$final_language = application::get('flag.global.__language_code') ?? session::get('numbers.entity.format.language_code') ?? $i18n['language_code'] ?? 'sys';
if (empty($languages[$final_language])) {
$final_language = 'sys';
$i18n['rtl'] = 0;
}
// put settings into system
if (!empty($languages[$final_language])) {
foreach ($languages[$final_language] as $k => $v) {
$k = str_replace('lc_language_', '', $k);
if (in_array($k, ['code', 'inactive'])) {
continue;
}
if (empty($v)) {
continue;
}
$i18n[$k] = $v;
}
}
$i18n['language_code'] = $final_language;
self::$options = $i18n;
session::set('numbers.entity.format.language_code', $final_language);
application::set('flag.global.i18n', $i18n);
self::$initialized = true;
// initialize the module
return factory::submodule('flag.global.i18n.submodule')->init($i18n);
}
示例10: init
public function init()
{
if ($this->data) {
return;
}
$lang = application::get_instance()->config->translate->lang;
if (file_exists(PATH_ROOT . '/' . DIR_LIBRARY . '/translate/' . $lang . '.php')) {
$data = (include PATH_ROOT . '/' . DIR_LIBRARY . '/translate/' . $lang . '.php');
if ($data) {
$this->data = array_merge($this->data, $data);
}
}
if (file_exists(PATH_ROOT . '/' . DIR_APPLICATION . '/translate/' . $lang . '.php')) {
$data = (include PATH_ROOT . '/' . DIR_APPLICATION . '/translate/' . $lang . '.php');
if ($data) {
$this->data = array_merge($this->data, $data);
}
}
if (class_exists('model_translate')) {
$m = new model_translate();
$data_db = $m->fetch_all();
if ($data_db) {
$data_array = array();
foreach ($data_db as $el) {
$data_array[$el->key] = $el->value_lang;
}
$this->data = array_merge($this->data, $data_array);
}
}
}
示例11: release
/**
* Release the lock
*
* @param string $id
* @return boolean
*/
public static function release($id)
{
$temp_dir = application::get(array('directory', 'temp'));
if (isset($temp_dir['dir'])) {
return unlink($temp_dir['dir'] . '__lock_' . $id);
}
return true;
}
示例12: add
/**
* Add library to the application
*
* @param string $library
*/
public static function add($library)
{
$connected = application::get('flag.global.library.' . $library . '.connected');
if (!$connected) {
factory::submodule('flag.global.library.' . $library . '.submodule')->add();
application::set('flag.global.library.' . $library . '.connected', true);
}
}
示例13: call
public static function call($message = 'Application Error', $code = 500)
{
$_SERVER['REQUEST_URI'] = '/error';
header('HTTP/1.1 ' . $code . ' ' . $message);
application::$instance = new application();
application::get_instance()->bootstrap()->run();
exit;
}
示例14: getTemplatePath
public function getTemplatePath($action = '')
{
if (empty($this->template)) {
$path = application::template($action);
return $path;
}
return $this->template;
}
示例15: template
public function template($path = '')
{
$path = trim($path, '/');
if (empty($path)) {
$path = application::module() . '/' . application::controller() . '/' . application::action() . '.php';
}
$template = ZOTOP_PATH_THEMES . DS . application::theme() . DS . 'template' . DS . str_replace('/', DS, $path);
return $template;
}