/** * @return mixed */ public function getData() { if (!$this->dataLoaded) { $this->data = (array) $this->loader->load($this->path); $this->dataLoaded = TRUE; } return $this->data; }
public static function instance($model_name, $action) { Loader::load('mutator', self::get_file_name($model_name, $action)); $mutation_name = $action . $model_name; $reflection = new ReflectionClass($mutation_name); return $reflection->newInstance($model_name, $action); }
/** * Constructor. * Acts as mini Router that picks up at the Controller level, post-routing. * Searches for files in directory relative to delegating class. * * Uses argument already set in Router as provided in URL. * * The URL parameter that would ordinarily be the method is now the subdirectory * The URL parameter that would be the first method parameter is now the controller. * The URL paramter that would be the second method parameter is now the method. * * Any remaining URL parameters are passed along as method parameters for the * Subcontroller invoked. */ public function __construct() { // Find the file in the directory relative to the original Controller. $subdirectory = dirname($this->file) . '/' . Router::$method; $file = strtolower(array_shift(Router::$arguments)); $path = $subdirectory . '/' . $file . FILE_EXTENSION; $default_path = $subdirectory . '/' . Router::$method . FILE_EXTENSION; if (file_exists($path)) { Loader::load($path); $controller = ucfirst($file) . '_Controller'; if (count(Router::$arguments)) { Router::$method = array_shift(Router::$arguments); } else { Router::$method = Registry::$config['core']['default_controller_method']; } Core::run_controller($controller); } elseif (file_exists($default_path)) { // Check for a default file of the same name as the directory, and load that with the default method. Loader::load($default_path); $controller = ucfirst(strtolower(Router::$method)) . '_Controller'; Router::$method = Registry::$config['core']['default_controller_method']; Core::run_controller($controller); } else { // No matches. Core::error_404(); } // Exit to prevent Router from continuing in Core. exit; }
/** * 初始化函数 * * @access public * @param string $driver 驱动名称 * @param array $option 实例化驱动时需要的参数 * @return void **/ public static function init($driver, $option) { Loader::load('parse.driver.' . ucfirst(strtolower($driver)) . 'Driver'); $class = ucfirst($driver) . 'Driver'; $instance = new ReflectionClass($class); self::$_driver = $instance->newInstanceArgs($option); }
function activate() { $setup = Config::get('RPC'); $class = URL::getPathPart($setup['class']); $method = URL::getPathPart($setup['method']); list($action, $type) = explode('.', URL::getPathPart($setup['action']), 2); $path = $setup["path"] . "/" . $class . "/" . ucwords($method) . ucwords($action) . "Controller"; if (file_exists(Loader::getPath("controller", $path))) { Debugger::log("CONTROLLER: <span style=\"color: #990000\">" . ucwords($method) . ucwords($action) . "Controller</span>"); $controller = Loader::loadNew("controller", $path); $controller->activate(); if (is_callable(array($controller, $type))) { echo $controller->{$type}(); } return; } $controller_class = ucwords($class) . ucwords($method) . ucwords($action) . "Controller"; Debugger::log("CONTROLLER: <span style=\"color: #990000\">{$controller_class}</span>"); if (file_exists(Loader::getPath("controller", "{$setup['path']}/{$controller_class}"))) { $controller = Loader::loadNew("controller", "{$setup['path']}/{$controller_class}"); $controller->activate(); } else { Loader::load("utility", "Server"); $ip = Server::getIP(); $self = Server::getSelf(); Debugger::log("Possible RPC Injection: RPC call to non-existent controller at path {$setup["path"]}/{$controller_class} {$ip} {$self}"); error_log("Possible RPC Injection: RPC call to non-existent controller at path {$setup['path']}/{$controller_class} {$ip} {$self}"); } }
/** * 初始化Loader * @return Object */ public static function init() { if (!is_object(self::$load)) { self::$load = new Loader(); } return self::$load; }
/** * 装载业务模型文件 * * @param string $name */ public function load($name) { if (isset($this->models[$name])) { return true; } $this->models[$name] = 1; Loader::load('app/Models/' . $name . $this->getFileSubfix()); }
public function activate() { $this->set_data(); $this->set_footer(); Loader::load('view', 'part/Head', $this->data_array['head']); Loader::load('view', "body/{$this->body_view}", $this->data_array['body']); Loader::load('view', 'part/Foot', $this->data_array['foot']); }
function __construct($find_router = true) { Loader::load('utility', 'router/SiteRouter'); Loader::load('controller', '/controller/Controller'); if ($find_router) { $this->findRouter(); } }
public function getSession() { if (!isset($this->passinggreensession)) { Loader::load("model", "com/passinggreen/PassinggreenSession"); $this->passinggreensession = new PassinggreenSession($this->getDBValue(self::$SESSION_ID)); } return $this->passinggreensession; }
/** * register instance * * @param string $name * @return object */ public function instance($name) { if ($this->exists($name)) { return $this->get($name); } $class = ucfirst($name); Loader::load($this->getPath($class)); return $this->set($name, new $class()); }
public static function dependencies() { \Loader::load('actions/controller', 'helper'); \Loader::load('actions/module', 'helper'); \Loader::load('actions/testers', 'helper'); \Loader::load('app/controller', 'interface'); \Loader::load('app/event', 'interface'); \Loader::load('app/model', 'interface'); \Loader::load('app/view', 'interface'); }
public function Output($template) { if (file_exists(dirname(__FILE__) . DS . "template" . DS . $template)) { Loader::load(dirname(__FILE__) . DS . "template" . DS . $template); $this->TemplateFile = new TemplateFile(); print_r($this->TemplateFile->FinalTemplate($this->Header(), $this->HtmlDir(), $this->HtmlTitle(), $this->RtlCss(), $this->drawBackground(), $this->drawLogo(), $this->drawPaidWatermark(), $this->drawInvoiceType(), $this->drawInvoiceInfo(), $this->drawReturnAddress(), $this->drawAddress(), $this->drawLineHeader(), $this->drawInvoice(), $this->SubTotals(), $this->Taxes(), $this->Totals(), $this->PublicNotes(), $this->drawPayments(), $this->drawTerms(), $this->Footer(), $this->PrintBtn(), $this->DownloadBtn(), $this->PaymentBtn(), $this->EditBtn())); } else { throw new Exception("Template : " . $template . " not found"); } }
/** * import file * * @param string $name */ public static function import($name) { $type = false !== strpos($name, '/') ? '' : 'Libraries/'; $file = 'app/' . $type . $name; if (Loader::checkPath($file)) { return Loader::load($file); } elseif (Loader::checkPath('vendor/Imp/' . $type . '/' . $name)) { return Loader::load('vendor/Imp/' . $type . '/' . $name); } }
/** * 判断是否有用户自定义的业务逻辑 **/ public function custom_fetch($path, $ext) { $hooks = Loader::load_config('hooks', false); if ($hooks && $hooks['parse']) { Loader::load('parse.' . strtolower($hooks['parse']['class'])); $obj = new $hooks['parse']['class'](); $args = array($this, $path, $ext); call_user_func_array(array($obj, $hooks['parse']['method']), $args); } }
/** * 判断是否有用户自定义的业务逻辑 **/ public function custom_fetch($url, $ext) { $hooks = Loader::load_config('hooks', false); if ($hooks && isset($hooks['crawl'])) { Loader::load('crawl.' . strtolower($hooks['crawl']['class'])); $obj = new $hooks['crawl']['class'](); $args = array($this, $url, $ext); call_user_func_array(array($obj, $hooks['crawl']['method']), $args); return true; } return false; }
function __construct($uuid = null) { if (!isset($uuid)) { Loader::load("vendor", "phpcassa/columnfamily.php"); $this->uuid = CassandraUtil::uuid1(); //Loader::load("vendor","uuid/uuid"); // $this->uuid = UUID::TimeUUIDType(); // $this->uuid_binary = UUID::generate(UUID::UUID_TIME,UUID::FMT_BINARY); $this->data = new stdclass(); } else { $this->uuid = $uuid; } }
/** * @param string $path * @param string $file * @return \WCM\WPStarter\Env\Env|static */ public static function load($path, $file = '.env') { if (is_null(self::$loaded)) { self::wpConstants(); if (!is_string($file)) { $file = '.env'; } $filePath = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file; $loader = new Loader($filePath, true); $loader->load(); self::$loaded = new static($loader->allVarNames()); } return self::$loaded; }
/** * Initializes the BuycPanel Api and returns an instance of that object with the given account information set * * /DONE/ */ private function getApi($hostname, $user, $realm, $password, $port) { Loader::load(dirname(__FILE__) . DS . "apis" . DS . "pve2_api.class.php"); # Check hostname resolves. if (gethostbyname($hostname) == $hostname && !filter_var($hostname, FILTER_VALIDATE_IP)) { $this->Input->setErrors(array('proxmox' => array('resolvehost' => Language::_("Proxmoxv2.!error.failed_hostname", true, $hostname)))); //return $pve2 ; } if ($port < 1 || $port > 65535) { $this->Input->setErrors(array('proxmox' => array('checkport' => Language::_("Proxmoxv2.!error.failed_port", true, $port)))); } $pve2 = new PVE2_API($hostname, $user, $realm, $password, (int) $port); return $pve2; }
/** * Load a plugin for uploading * * @param string plugin name like "Picasa", "Imageshack", "Imgur" or empty or NULL * If plugin name is not empty, the method will make a REMOTE uploader * @return object Uploader instance like ChipVN_Image_Uploader_Picasa * @throws Exception if cannot load the plugin */ public static function factory($pluginName = NULL) { if (empty($pluginName)) { $pluginName = 'Local'; } else { $pluginName = 'Remote_' . ucfirst($pluginName); if (!class_exists('\\ChipVN\\Image_Uploader\\Remote', FALSE)) { Loader::load(__CLASS__ . '\\Remote'); } } $className = __CLASS__ . '\\' . $pluginName; Loader::load($className); return new $className(); }
/** * @param string $path * @param string $file * @return \WCM\WPStarter\Env\Env|static */ public static function load($path, $file = '.env') { if (is_null(self::$loaded)) { self::wpConstants(); if (!is_string($file)) { $file = '.env'; } $filePath = rtrim(str_replace('\\', '/', $path), '/') . '/' . $file; $loader = new Loader($filePath, true); $loader->load(); self::$loaded = new static($loader->allVarNames()); } return self::$loaded; }
/** * 解析视图文件 * * @param string $file */ public function renderFile($file) { // 开启smarty模版引擎后, 实例化smarty对象 switch (Imp::app()->instance('config')->get('template')) { case 'smarty': Loader::load('vendor/Imp/Core/Template'); $smartyObject = new Template(); $this->smarty = $smartyObject->smarty; $this->smarty->assign($this->tpl_var); $this->smarty->display($file); break; default: echo $this->readFileContent($file); break; } }
/** * Run the scrapers. */ public function scrape() { // TODO: This should be read from the ``shelter_pages'' table $mhsDog = new MhsDogScraper("http://montanapets.org/mhs/residentdog.html"); $mhsCat = new MhsCatScraper("http://montanapets.org/mhs/residentcat.html"); $packer = new Packer(); $packer->pack($mhsDog->scrape()); $packer->pack($mhsCat->scrape()); $loader = new Loader($packer->getPackedPets()); $loader->checkActive(); $loader->load(); // temporary fix for the slashes in some breeds // @todo: this should be done in the scraper $db = new Database(Site::getInstance()->getDbConf()); $db->execute("update animals set breed = replace(breed, '/', '-')"); }
protected function get_introduction_image($id) { Loader::load('collector', 'image/PhotoCollector'); $photo_result = PhotoCollector::getRow($id); if($photo_result == null) return; $name = $photo_result->name; $category = $photo_result->category; $size = 'medium'; $height = 375; $width = 500; $description = $photo_result->description; return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); }
private function __construct($session_id = null) { //TODO: is there a better place for these ini settings? ini_set("session.cookie_path", "/"); Loader::load("utility", "url/URL"); $parts = explode(".", URL::getCurrentArr('host')); $domain = implode(".", array_slice($parts, -2)); ini_set("session.cookie_domain", $domain); ini_set("session.use_only_cookies", "1"); //forces users to accept cookies, but more secure //ini_set("session.use_trans_sid", "0"); //Do not enable this! Session IDs in the URL are bad, m'kay? if (!is_null($session_id)) { session_id($session_id); //must be set BEFORE starting a session, if null, session id will pull from COOKIE, if no COOKIE, a new session si created } session_start(); //we call this in the constructor as it is vital this is done before any kind of output is generated }
protected function check_for_special_redirect($uri) { if(preg_match('@^/post_([0-9]{4}-[0-9]{2}-[0-9]{2})_([a-z0-9-]+)(/?)$@', $uri, $matches)) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post = $repository->findPostByPath($matches[2]); if(!$post) { Loader::loadNew('controller', '/Error404Controller') ->activate(); } Loader::load('utility', 'Content'); $uri = Content::instance('URLSafe', "/{$post['category']}/{$post['path']}/")->activate(); } else { $post_uri = URLDecode::getPiece(1); if($post_uri !== null) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post = $repository->findPostByPath($post_uri); if($post != false) { Loader::load('utility', 'Content'); $uri = Content::instance('URLSafe', "/{$post['category']}/{$post['path']}/")->activate(); } } } if($uri == '/search/') { if(Request::getGet('submit') == 'Submit Search' && Request::getGet('search')) { $uri .= Request::getGet('search'); $uri .= '/'; } } return $uri; }
/** * 实例 db 对象 * * @param array $config */ public static function getInstance($config = array()) { if (empty($config)) { $configs = Imp::app()->instance('config')->get('database'); $config = $configs['default']; } // 当前db id $dbID = md5($config['host'] . $config['port'] . $config['dbname']); if (!isset(self::$instances[$dbID])) { // 加载数据库驱动类 $class = ucfirst($config['type']); $driveFile = 'vendor/Imp/Database/' . $class . '/' . $class; Loader::load($driveFile); // 实例化数据库 $class = strtolower($class) == 'mysqli' ? 'Mysql' : $class; self::$instances[$dbID] = new $class($config); } return self::$instance = self::$instances[$dbID]; }
private function login() { Loader::load('utility', 'session/Session'); Loader::load('model', 'com/passinggreen/member/Member'); $member = Member::findMemberWithEmail(addslashes(Request::getPost('email'))); $valid = false; if (isset($member) && $member->isValid() && ($member->getLevel() == 'admin' || $member->getLevel() == 'superadmin' || $member->getLevel() == 'developer')) { $valid = $member->validatePassword(Request::getPost('password')); } if ($valid) { $member->recordLogin(); Session::instance()->setModelDefault($member); Debugger::log('valid'); } else { Debugger::log('invalid'); $this->setPageData('error', 'Incorrect username or password.'); $this->show_form(); } }
private function get_thumb($string, $is_absolute, $size) { list($category, $file_name) = explode('/', $string); list($photo, $extension) = explode('.', $file_name); $file_path = $this->get_file_path($category, $photo, $size, $extension); $file_size = getimagesize($file_path); Loader::load('collector', 'image/PhotoCollector'); $photo_result = PhotoCollector::fetchRow($category, $photo); if ($photo_result == false) { return ''; } $height = $file_size[1]; $width = $file_size[0]; $description = $photo_result->description; $domain = '/'; if ($is_absolute) { $domain = Loader::getRootURL(URLDecode::getSite()); } return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); }
function detect_fatal_error() { $last_error = error_get_last(); if ($last_error && ($last_error['type'] == E_ERROR || $last_error['type'] == E_PARSE) && class_exists('Loader')) { try { Loader::load('utility', 'Template'); if (file_exists(Loader::getPath('view', 'FatalError'))) { Debugger::log("Type {$last_error["type"]}: {$last_error["message"]} in {$last_error["file"]} on line {$last_error["line"]}"); ob_clean(); header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); Template::insert('FatalError'); error_log("[Error Caught] {$last_error['message']} in {$last_error['file']} on line {$last_error['line']}"); ob_end_flush(); } } catch (Exception $e) { //echo "We've encountered an error. Please go back and try again."; } } }