本文整理汇总了PHP中Framework\Registry类的典型用法代码示例。如果您正苦于以下问题:PHP Registry类的具体用法?PHP Registry怎么用?PHP Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$this->getLayoutView()->set("seo", Framework\Registry::get("seo"));
$view = $this->getActionView();
$alltests = Test::all(array(), array("id", "title"));
$view->set("alltests", $alltests);
}
示例2: initialize
public function initialize()
{
Events::fire("framework.database.initialize.before", array($this->type, $this->options));
if (!$this->type) {
$configuration = Registry::get("configuration");
if ($configuration) {
$configuration = $configuration->initialize();
$parsed = $configuration->parse("configuration/database");
if (!empty($parsed->database->default) && !empty($parsed->database->default->type)) {
$this->type = $parsed->database->default->type;
unset($parsed->database->default->type);
$this->options = (array) $parsed->database->default;
}
}
}
if (!$this->type) {
throw new Exception\Argument("Invalid type");
}
Events::fire("framework.database.initialize.after", array($this->type, $this->options));
switch ($this->type) {
case "mysql":
return new Database\Connector\Mysql($this->options);
break;
default:
throw new Exception\Argument("Invalid type");
break;
}
}
示例3: initialize
public function initialize()
{
$type = $this->getType();
if (empty($type)) {
$configuration = Registry::get('configuration');
if ($configuration) {
$configuration = $configuration->initialize();
$parsed = $configuration->parse('configuration/database');
if (!empty($parsed->database->default) && !empty($parsed->database->default->type)) {
$type = $parsed->database->default->type;
unset($parsed->database->default->type);
$this->__construct(array('type' => $type, 'options' => $parsed->database->default));
}
}
}
if (empty($type)) {
throw new Exception\Argument('Invalid type');
}
switch ($type) {
case 'mysql':
return new Database\Connector\MySql($this->getOptions());
break;
default:
throw new Exception\Argument('Invalid type');
break;
}
}
示例4: performance
public function performance($course)
{
$session = Registry::get("session");
$perf = Registry::get("MongoDB")->performance;
$week = (new \DateTime(date('Y-m-d')))->format("W");
$performance = array();
$classroom = self::$_classroom;
$record = $perf->findOne(array('user_id' => (int) self::$_student->user_id, 'course_id' => (int) $course->id, 'year' => date('Y'), 'classroom_id' => (int) $classroom->id));
$d = StringMethods::month_se();
$start = (int) (new \DateTime($d['start']))->format("W");
if ($start == 53) {
$start = 1;
}
$end = (int) (new \DateTime($d['end']))->format("W");
$monthly = array();
if (isset($record)) {
$performance['course'] = $course->title;
$performance['teacher'] = \User::first(array("id = ?" => $record['teacher_id']), array("name"))->name;
foreach ($record['track'] as $track) {
$week = $track['week'];
if ($week <= $end && $week >= $start) {
$monthly[] = $track['grade'];
}
$performance['tracking'][] = $track;
}
}
return array('performance' => $performance, 'monthly' => $monthly);
}
示例5: fbLogin
public function fbLogin()
{
$this->JSONview();
$view = $this->getActionView();
$session = Registry::get("session");
if (RequestMethods::post("action") == "fbLogin" && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
// process the registration
$fbid = RequestMethods::post("fbid");
$access_token = RequestMethods::post("access_token");
$user = !$this->user ? User::first(["fbid = ?" => $fbid]) : $this->user;
if (!$user) {
try {
$user = $this->_register();
} catch (\Exception $e) {
$view->set("success", false);
return;
}
}
$this->setUser($user);
$redirect = RequestMethods::post("loc", "");
if ($redirect != '') {
$token = Shared\Markup::uniqueString();
$session->set('CampaignAccessToken', $token);
$view->set("redirect", "/" . $redirect . "/{$token}");
}
$view->set("success", true);
} else {
$view->set("success", false);
}
}
示例6: __construct
public function __construct($options = array())
{
parent::__construct($options);
// connect to database
$database = Registry::get("database");
$database->connect();
// schedule: load user from session
Events::add("framework.router.beforehooks.before", function ($name, $parameters) {
$session = Registry::get("session");
$controller = Registry::get("controller");
$user = $session->get("user");
if ($user) {
$controller->user = \User::first(array("id = ?" => $user));
}
});
// schedule: save user to session
Events::add("framework.router.afterhooks.after", function ($name, $parameters) {
$session = Registry::get("session");
$controller = Registry::get("controller");
if ($controller->user) {
$session->set("user", $controller->user->id);
}
});
// schedule: disconnect from database
Events::add("framework.controller.destruct.after", function ($name) {
$database = Registry::get("database");
$database->disconnect();
});
}
示例7: initialize
public function initialize()
{
$type = $this->getType();
if (empty($type)) {
$configuration = Registry::get('configuration');
if ($configuration) {
$configuration = $configuration->initialize();
$parsed = $configuration->parse('configuration/session');
if (!empty($parsed->session->default) && !empty($parsed->session->default->type)) {
$type = $parsed->session->default->type;
unset($parsed->session->default->type);
$this->__construct(array('type' => $type, 'options' => (array) $parsed->session->default));
}
}
}
if (empty($type)) {
throw new Exception\Argument('Invalid type');
}
switch ($type) {
case 'server':
return new Session\Driver\Server($this->getOptions());
break;
default:
throw new Exception\Argument('Invalid type');
break;
}
}
示例8: initialize
public function initialize()
{
Events::fire("framework.session.initialize.before", array($this->type, $this->options));
if (!$this->type) {
$configuration = Registry::get("configuration");
if ($configuration) {
$configuration = $configuration->initialize();
$parsed = $configuration->parse("configuration/session");
if (!empty($parsed->session->default) && !empty($parsed->session->default->type)) {
$this->type = $parsed->session->default->type;
unset($parsed->session->default->type);
$this->options = (array) $parsed->session->default;
}
}
}
if (!$this->type) {
throw new Exception\Argument("Invalid type");
}
Events::fire("framework.session.initialize.after", array($this->type, $this->options));
switch ($this->type) {
case "server":
return new Session\Driver\Server($this->options);
break;
default:
throw new Exception\Argument("Invalid type");
break;
}
}
示例9: stats
/**
* See stats of a keyword
* @before _secure, memberLayout
*/
public function stats($keyword_id)
{
$keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => true));
$this->_authority($keyword);
$rank = Registry::get("MongoDB")->rank;
$r = $rank->findOne(['keyword_id' => (int) $keyword->id, 'created' => date('Y-m-d')]);
if ($keyword->live && !$r) {
try {
Shared\Service\Serp::record(array($keyword));
} catch (\Exception $e) {
}
}
$end_date = RequestMethods::get("enddate", date("Y-m-d"));
$start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
$this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
$view = $this->getActionView();
$start_time = strtotime($start_date);
$end_time = strtotime($end_date);
$i = 0;
$obj = array();
while ($start_time < $end_time) {
$start_time = strtotime($start_date . " +{$i} day");
$date = date('Y-m-d', $start_time);
$record = $rank->findOne(array('created' => $date, 'keyword_id' => (int) $keyword->id));
if (isset($record)) {
$position = $record['position'];
} else {
$position = 0;
}
$obj[] = array('y' => $date, 'a' => $position);
++$i;
}
$view->set("keyword", $keyword)->set("label", "Rank")->set("data", ArrayMethods::toObject($obj));
}
示例10: __construct
public function __construct()
{
parent::__construct();
$this->_rules = array();
$this->_errors = array();
$this->input = Registry::get('input');
}
示例11: index
/**
* @before _secure, _admin
*/
public function index()
{
$this->seo(array("title" => "Dashboard", "view" => $this->getLayoutView()));
$view = $this->getActionView();
$database = Registry::get("database");
$total = $database->query()->from("transactions", array("SUM(amount)" => "earn"))->all();
$view->set("earn", round($payments[0]["earn"], 2));
}
示例12: getTest
public function getTest()
{
$cache = Registry::get('cache');
if ($this->_ajax()) {
$test = array("Chapman");
echo json_encode($test);
}
}
示例13: __construct
public function __construct()
{
parent::__construct();
$this->session = Registry::get('session');
$this->cookie = Registry::get('cookie');
$this->input = Registry::get('input');
$this->validator = Registry::get('validator');
}
示例14: __construct
public function __construct($options = array())
{
parent::__construct($options);
$database = \Framework\Registry::get('database');
$database->_connect();
$session = \Framework\Registry::get('session');
$user = unserialize($session->get('user', null));
$this->setUser($user);
}
示例15: delete
public static function delete()
{
$database = Framework\Registry::get('database');
Framework\Test::add(function () use($database) {
$example = new Model\Example(array("id" => 2));
$example->delete();
return Model\Example::count() == 1;
}, "Model deletes rows", "Model");
}