public function room($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\RoomItem $roomMapper) { if (isset($urlParameters[0])) { $app->setCurrentRoom($urlParameters[0]); } $this->act($urlParameters, $http, $app, $db, $roomMapper); }
public static function start() { // 注册autoload方法 spl_autoload_register('\\Core\\Loader::autoload'); $app = new Application(); $app->run(); }
/** * Generate a Response object for the given {$template} * @param string $template * @param array $data * @return \Psr\Http\Message\ResponseInterface */ protected function view($template, $data = []) { try { return $this->app->view->render($this->app->response, $template, $this->getTemplateData($data)); } catch (\Twig_Error $e) { $this->app->notFound(); } }
public function render(array $appData, $templateName, \Core\Application $app, \Core\Registry $registry) { $site_root = $registry->get(REG_SITE_ROOT); $nav_items = array(array('caption' => 'Book It!', 'link' => $site_root . BOOK_URL)); if ($app->isAdmin()) { $nav_items[] = array('caption' => 'Employee List', 'link' => $site_root . EMPLOYEE_LIST_URL); } return (new \Utility\Template())->parse($templateName, array('nav_items' => $nav_items)); }
public function render(array $appData, $templateName, \Core\Application $app, \Core\Database $db, \DBMappers\RoomItem $roomMapper, \Core\Registry $registry) { $rooms = $roomMapper->getAll($db); $nav_items = array(); foreach ($rooms as $room) { $nav_items[] = array('caption' => $room->getRoomName(), 'link' => $registry->get(REG_SITE_ROOT) . BROWSE_URL . "/room/" . $room->getId(), 'selected' => false); } $nav_items[] = array('caption' => 'Settings', 'link' => $registry->get(REG_SITE_ROOT) . 'employee/edit/' . $app->getEmpId(), 'selected' => false); $nav_items[] = array('caption' => 'Logout', 'link' => $registry->get(REG_SITE_ROOT) . LOGIN_URL, 'selected' => false); return (new \Utility\Template())->parse($templateName, array('nav_items' => $nav_items)); }
public function render(array $appData, $templateName, \Core\Application $app, \Core\Registry $registry) { $cur_per = $app->getCurrentPeriod(); $period_now = $cur_per->format('F Y'); $first_day = (new \DateTime())->setDate($cur_per->format('Y'), $cur_per->format('n'), 1); $next_per = (new \DateTime())->setTimeStamp($first_day->getTimestamp()); $next_per->add(new \DateInterval('P1M')); $prev_per = (new \DateTime())->setTimeStamp($first_day->getTimestamp()); $prev_per->sub(new \DateInterval('P1M')); return (new \Utility\Template())->parse($templateName, array('period_navigator_now' => $period_now, 'period_left_link' => $registry->get(REG_SITE_ROOT) . BROWSE_URL . "?year=" . $prev_per->format('Y') . "&month=" . $prev_per->format('n'), 'period_right_link' => $registry->get(REG_SITE_ROOT) . BROWSE_URL . "?year=" . $next_per->format('Y') . "&month=" . $next_per->format('n'))); }
/** This method sets the application timezone @access public @throws Exception object @static @return void */ public static function set_timezone() { try { date_default_timezone_set(Application::config("general->application_timezone")); } catch (Exception $e) { throw $e; } }
/** * @return \Core\Database */ public static function database() { static $database = NULL; if (is_null($database)) { $config = \Core\Application::config()->database['master']; $database = new \Core\Database($config['db_target'], $config['user_name'], $config['password'], $config['params']); } return $database; }
/** * 配置cookie参数 * * @param array $config */ public static function init_cookie_params() { $config = \Core\Application::config()->cookie; foreach (self::$config as $key => $val) { if (isset($config[$key])) { self::$config[$key] = $config[$key]; } } }
/** * 初始化 */ public function __construct() { $config = \Core\Application::config()->redcash; $this->appid = $config['appid']; $this->cert = $config['cert']; $this->ca = $config['ca']; $this->key = $config['key']; $this->api_key = $config['api_key']; $this->mchid = $config['mchid']; }
/** * 配置微信接口参数 * * @param array $config * @return \WX\Platform\Common */ public static function init_config_params() { static $singleton = null; if (is_null($singleton)) { $config = \Core\Application::config()->weixin; $model = get_called_class(); $singleton = new $model($config['appid'], $config['appsecret'], $config['token']); } return $singleton; }
/** * 初始化 * @param int $corp_agent_id * @param string $corp_id * @param string $corp_secret * @param string $token * @param string $open_log */ public function __construct() { $config = \Core\Application::config()->enterprise; $this->corpid = $config['corpid']; $this->corpsecret = $config['corpsecret']; $this->corpagentid = $config['corpagentid']; $this->token = $config['token']; $this->encodingaeskey = $config['encodingaeskey']; $this->open_log = $config['open_log']; }
/** * Get the base URL for the request. * * @param string $scheme * @param string $root * @return string */ protected function getRootUrl($scheme, $root = null) { if (is_null($root)) { if (is_null($this->cachedRoot)) { $request = $this->app->make('request'); $this->cachedRoot = rtrim($request->getSchemeAndHttpHost() . $request->getBaseUrl(), '/'); } $root = $this->cachedRoot; } $start = starts_with($root, 'http://') ? 'http://' : 'https://'; return preg_replace('~' . $start . '~', $scheme, $root, 1); }
/** * array to path * @param array $arr * @param string $domain */ public static function a2p($arr) { $path = '/'; $module = \Core\Application::get_module(); if (!empty($module)) { $path .= $module . '/'; } foreach ($arr as $key => $val) { $path .= $key . '/' . $val . '/'; } return rtrim($path, '/'); }
public function render(array $appData, $templateName, \Core\Application $app, \Core\Database $db, \DBMappers\RoomItem $roomMapper, \DBMappers\EmpItem $empMapper) { $current_room = $app->getCurrentRoom(); if ($current_room === false) { $rooms = $roomMapper->getAll($db); $app->setCurrentRoom($rooms[0]->getId()); $current_room = $app->getCurrentRoom(); } $roomItem = $roomMapper->getById($current_room, $db); $emps = $empMapper->getAll($db); if (isset($appData['book_crossings'])) { $message = 'Can\'t add appointment, it crosses existing appointments: '; foreach ($appData['book_crossings'] as $cross) { $empItem = $empMapper->getById($cross->getEmpId(), $db); $message .= $empItem->getName(); $message .= ' ' . $cross->getTimeStart()->format('M-j-Y H:i'); $message .= '-' . $cross->getTimeEnd()->format('H:i') . ';'; } } return (new \Utility\Template())->parse($templateName, array('book_hour_mode' => $app->getHourMode(), 'book_room_name' => $roomItem->getRoomName(), 'book_emps' => $emps, 'book_values' => isset($appData['book_values']) ? $appData['book_values'] : null, 'book_errors' => isset($appData['book_errors']) ? $appData['book_errors'] : null)); }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empMapper) { $app->reopenSession(); if (isset($http->post()['login'])) { $loginValue = $http->post()['login']; //error_log("\nPOST:" . print_r($http->post(), true), 3, 'my_errors.txt'); $empItem = $empMapper->getByLogin($loginValue, $db); if (!$empItem) { $this->setWrongLoginState($app, $loginValue); return; } if (!$empItem->isPasswordEqual($http->post()['password'])) { $this->setWrongLoginState($app, $loginValue); return; } $app->setAuthorized($empItem->getId(), $empItem->isAdmin(), $empItem->getFirstDay(), $empItem->getHourMode()); $app->setStateRedirect(BROWSE_URL); } else { $app->setStateLogin(array()); } }
/** * 分发到控制器 * 1. 检验action是否允许执行,如果不允许执行则抛出异常,中断执行,否则执行下一步,注:[controller 的私有方法&&保留方法&&静态方法不可执行(view调用controller方法专用)], * 2. 进行初始化 * 3. 执行action * 4. 执行send输出 * @param string * @throws \Exception */ public function run($method) { // 检测action是否可以执行 $bool = method_exists($this, $method) && ($reflector = new \ReflectionMethod($this, $method)); if (!$bool || !$reflector->isPublic() || $reflector->isStatic() || $method == 'run' || $method == 'initialize' || $method == 'send') { \Core\Application::abort(404, 'action not exits!'); } // 如果不想让他顺序进行抛出异常即可中断 $this->initialize(); $this->{$method}(); $this->send(); }
/** * 如果没有配置日志路径则不写日志, * 使用php内置的error_log记录错误日志 * * @param string $message * @return bool */ function log_message($message, $dir = NULL) { if (is_null($dir)) { $dir = \Core\Application::config()->log_dir; } $client_ip = client_ip(); if (!is_dir($dir)) { @mkdir($dir, 0755, TRUE); } $file = $dir . '/' . date('Y-m-d') . '.log'; return error_log(date('H:i:s ') . $client_ip . " {$message}\n", 3, $file); }
public function __construct() { parent::__construct(); // Instances from core $this->view = new \Core\View(); $this->model = new \Core\Model(); $this->load = new \Core\Loader(); $this->uri = new \Core\Uri(); // Instances from libraries $this->sessionHandler = new \Libraries\SessionHandler(); // Instances from helpers $this->formHelper = new \Helpers\FormHelper(); }
/** * 获取后台控制菜单 * @param array $menu */ function get_menu(&$menu) { $tpl = '<a href="%s"><li class="list-group-item %s"><span class="badge">%s</span><span class="glyphicon %s"></span> %s</li></a>'; $html = ''; $controller_name = \Core\Application::get_controller(true); foreach ($menu as &$val) { if (stripos($val['link'], $controller_name)) { $val['is_active'] = true; } $active = $val['is_active'] ? 'select' : ''; $html .= sprintf($tpl, $val['link'], $active, $val['badge'], $val['ico'], $val['name']); } return $html; }
} /** This method sets the database property array @access private @throws Exception object @param string $ke @param array $arrValue @return void */ private function set_database($key, $arrValue) { try { if (is_string($arrValue["enabled"]) && Utility::check_bool($arrValue["enabled"]) && filter_var($arrValue["enabled"], FILTER_VALIDATE_BOOLEAN)) { $this->Databases[$key] = new PDOHandler($arrValue['dbms'], $arrValue['host'], $arrValue['user'], $arrValue['password'], $arrValue['database_name']); }
/** * 获取上传的文件 */ public function picture() { $file = \Ext\Uploader::get('file'); if (!empty($file)) { if ($file->is_successed()) { $to_path_file = '/' . time() . '.' . $file->file_ext(); $file->move(\Core\Application::config()->upload_dir . $to_path_file); echo json_encode(array('link' => \Core\Application::config()->upload_url . $to_path_file)); } else { echo $file->error_code(); } } exit; }
/** * 执行 */ public static function dispatch($pattern_map, $url) { $class_action = \Core\Router::match_all($pattern_map, $url); $parts = explode('::', $class_action); $class_file = strtolower(W_APPLICATION_PATH . $parts[0] . W_EXT); if (file_exists($class_file)) { $parts[0] = str_replace('/', '\\', $parts[0]); $class = new $parts[0](); $path = explode('/', $parts[1]); $action = array_shift($path); $class->run($action); } else { \Core\Application::abort(404, 'dispatch 404'); } }
public function registration() { Application::instance()->log('register'); $user = new \models\User('create'); if (!empty($_POST)) { $user->login = $_POST['login']; $user->password = $_POST['password']; $user->password_retype = $_POST['password_retype']; if ($user->validate()) { $user->password = password_hash($user->password, PASSWORD_BCRYPT); unset($user->password_retype); if ($user->save()) { $this->redirect('/user/login'); } } } $this->render('registration', ['user' => $user]); }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empItemMapper) { if ($app->isAuthorized()) { $empItem = $empItemMapper->getById($app->getEmpId(), $db); if ($empItem->isPasswordEqual(null)) { $app->setStateRedirect(EMPLOYEE_URL . '/edit/' . $empItem->getId()); } else { $app->setStateRedirect(BROWSE_URL); } } else { $app->setStateRedirect(LOGIN_URL); } }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\AppointmentItem $appMapper, \DBMappers\EmpItem $empItemMapper) { if ($http->getRequestMethod() == 'GET') { $app->setStateBook(array()); } else { if ($http->getRequestMethod() == 'POST') { $bookErrors = array(); $bookValues = array_merge(array(), $http->post()); $bookingOrder = new \Application\BookingOrder(); $this->validateForm($bookValues, $bookErrors, $bookingOrder, $app->getHourMode()); //error_log("\nbookingData:" . print_r($bookingOrder, true), 3, 'my_errors.txt'); if ($this->isEmptyValues($bookErrors)) { $appMatcher = new \Application\AppointmentMatcher(); $chain = $appMatcher->makeChain($bookingOrder, $app->getEmpId(), $app->getCurrentRoom()); $crossings = $appMatcher->getCrossingAppointments($chain, $appMapper, $db); // test for crossing appointments if (count($crossings) > 0) { $message = \Utility\HtmlHelper::MakeCrossingMessage($crossings, $empItemMapper, $db); $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => $message, 'book_crossings' => $crossings)); } else { $max_chain_id = $appMapper->getMaxChainId($db); if ($max_chain_id === false) { $max_chain_id = 1; } else { ++$max_chain_id; } $chain->setChainId($max_chain_id); foreach ($chain as $appointment) { $appMapper->save($appointment, $db); } $chain->rewind(); $message = \Utility\HtmlHelper::MakeSuccessAppCreationMessage($chain->current(), $app->getHourMode()); $app->setMessage($message); $app->setStateRedirect(BROWSE_URL); } } else { $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => isset($bookErrors['common']) ? $bookErrors['common'] : null)); } } } }
/** * Initialize this backend. */ public function __construct() { parent::__construct(); $this->name = 'backend'; }
<?php ini_set('display_errors', "On"); date_default_timezone_set('Asia/Chongqing'); // 定义框架使用的常量和方法 require realpath(__DIR__ . '/../library/core/application.php'); // 定义框架使用的常量和方法 require realpath(__DIR__ . '/../library/core/uri.php'); // manage 后台管理模块 if (\Core\URI::part(0) == 'manage') { // 设置模块url别名和操作系统路径 \Core\Application::bind_module('manage', realpath(__DIR__ . '/../manage')); } else { // 设置模块url别名和操作系统路径 \Core\Application::bind_module('', realpath(__DIR__ . '/../application')); } // 设置自动加载目录 \Core\Application::init_include_path(array(W_APPLICATION_PATH, W_LIBRARY_PATH)); //初始化自动加载 \Core\Application::init_autoload(); // 分发请求 \Core\Application::dispatch(\Core\Application::config()->route_maps, \Core\URI::get_url_path());
set_include_path('./library'); spl_autoload_extensions('.php'); spl_autoload_register(); use Core\Application; use Core\Config; use Core\Setting; use Utils\Menu; use Manage\Authentification; if (Config::Get('debug')) { error_reporting(-1); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } $app = new Application(); $auth = new Authentification(); $navbar = new Menu(); $navbar->item($app->URL(), 'Share')->item($app->URL('review'), 'Review')->item($app->URL('details'), 'Details'); $navbar_right = new Menu(); if ((new Setting('api_display_doc'))->getValue() || $auth->isLogged()) { $navbar_right->item($app->URL('api'), 'API'); } else { if ((new Setting('api_requests'))->getValue()) { $navbar_right->item($app->URL('api/request'), 'API'); } } $app->register(Menu::NAVBAR, $navbar); $app->register(Menu::NAVBAR_RIGHT, $navbar_right); // let's party hard $app->run();
<?php $app = \Core\Application::getInstance(); $app->get('/', 'HomeController:index'); $app->get('/rsvp', 'HomeController:rsvp');