本文整理汇总了PHP中IoC::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP IoC::singleton方法的具体用法?PHP IoC::singleton怎么用?PHP IoC::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IoC
的用法示例。
在下文中一共展示了IoC::singleton方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _isUnread
private function _isUnread()
{
if (Auth::guest()) {
return false;
}
$markAsReadAfter = value(Config::get('forums::forums.mark_as_read_after'));
if (!IoC::registered('topicsview')) {
IoC::singleton('topicsview', function () use($markAsReadAfter) {
return Forumview::where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter))->where('user_id', '=', Auth::user()->id)->lists('topic_id');
});
}
$tv = IoC::resolve('topicsview');
$nb = count($tv);
$view = Forumtopic::where('forumcategory_id', '=', $this->id)->where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter));
if ($nb > 0) {
$view = $view->where_not_in('id', $tv);
}
$view = $view->count();
if ($nb == 0 && $view > 0) {
return true;
}
if ($view > 0) {
return true;
}
return false;
}
示例2: testSingletonsAreCreatedOnce
/**
* Test that singletons are created once.
*
* @group laravel
*/
public function testSingletonsAreCreatedOnce()
{
IoC::singleton('foo', function () {
return new StdClass();
});
$object = IoC::resolve('foo');
$this->assertTrue($object === IoC::resolve('foo'));
}
示例3: path
<?php
Autoloader::map(array('SimplePie' => path('bundle') . 'rssparser/libraries/simplepie/SimplePie.php', 'rssparser' => path('bundle') . 'rssparser/rssparser.php'));
Autoloader::underscored(array('SimplePie' => path('bundle') . 'rssparser/libraries/simplepie/SimplePie'));
IoC::singleton('simplepie', function () {
$sp = new SimplePie();
return $sp;
});
示例4: function
<?php
/**
* @link https://github.com/lordcoste/analytics-s2s
* @author Colao Stefano < lordcoste@gmail.com >
*/
const BUNDLE_NAME = 'analytics-s2s';
Autoloader::map(array('Analytics' => Bundle::path(BUNDLE_NAME) . 'Analytics.php', 'AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'AnalyticsService.php', 'Google_Client' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'Google_Client.php', 'Google_AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'contrib' . DS . 'Google_AnalyticsService.php'));
IoC::singleton('google-analytics', function () {
$prefix = Bundle::prefix(BUNDLE_NAME);
if (!File::exists(Config::get($prefix . 'google.certificate_path'))) {
throw new Exception("Can't find the .p12 certificate in: " . Config::get($prefix . 'google.certificate_path'));
}
$config = array('oauth2_client_id' => Config::get($prefix . 'google.client_id'), 'use_objects' => Config::get($prefix . 'google.use_objects'));
$google = new Google_Client($config);
$google->setAccessType('offline');
$google->setAssertionCredentials(new Google_AssertionCredentials(Config::get($prefix . 'google.service_email'), array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents(Config::get($prefix . 'google.certificate_path'))));
return new AnalyticsService($google);
});
Analytics::init(IoC::resolve('google-analytics'));
示例5: function
/**
* laravel-directadmin
*
* Laravel bundle to access the DirectAdmin API
*
* @author Chris Schalenborgh <chris.s@kryap.com>
* @version 0.1
* @package laravel-directadmin
* @link http://www.directadmin.com/api.html
* @license BSD License
*/
// configure autoloader
Autoloader::map(array('HTTPSocket' => Bundle::path('directadmin') . 'lib' . DS . 'DirectAdmin.php'));
// Register a mailer in the IoC container
IoC::singleton('DirectAdmin', function () {
// instantiate new directadmin
$sock = new HTTPSocket();
// load settings
$config = Config::get('directadmin::settings', array());
// set host/port
if (!empty($config['host']) && !empty($config['port'])) {
$sock->connect($config['host'], $config['port']);
}
// set login/password
if (!empty($config['login']) && !empty($config['password'])) {
$sock->set_login($config['login'], $config['password']);
}
// Return the instance.
return $sock;
});
示例6: _isUnread
public function _isUnread()
{
if (Auth::guest()) {
return false;
}
$markAsReadAfter = value(Config::get('forums::forums.mark_as_read_after'));
// is the topic > delay, then return false;
if (strtotime($this->updated_at) < $markAsReadAfter) {
return false;
}
if (!IoC::registered('topicsview')) {
IoC::singleton('topicsview', function () use($markAsReadAfter) {
return Forumview::where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter))->where('user_id', '=', Auth::user()->id)->lists('topic_id');
});
}
if (array_search($this->id, IoC::resolve('topicsview')) !== false) {
return false;
}
return true;
}
示例7: file_get_contents
|--------------------------------------------------------------------------
| Start / Load The User Session
|--------------------------------------------------------------------------
|
| Sessions allow the web, which is stateless, to simulate state. In other
| words, sessions allow you to store information about the current user
| and state of your application. Here we'll just fire up the session
| if a session driver has been configured.
|
*/
if (!Request::cli() and Config::get('session.driver') !== '') {
Session::load();
}
// @todo move this into a config file
if (Request::is_env('production')) {
Config::set('error.detail', false);
}
Config::set('deploy_timestamp', file_get_contents('deploy_timestamp.txt'));
Auth::extend('rfpez', function () {
return new RfpezAuth();
});
IoC::singleton('yaml_parser', function () {
return new \Symfony\Component\Yaml\Parser();
});
IoC::singleton('yaml_dumper', function () {
return new \Symfony\Component\Yaml\Dumper();
});
Event::listen('laravel.language.loader', function () {
return array('asdfadsf' => 'asdf');
});
require path('base') . 'application/libraries/htmLawed.php';
示例8: function
/*
|--------------------------------------------------------------------------
| Auto-Loader Mappings
|--------------------------------------------------------------------------
|
| Laravel uses a simple array of class to path mappings to drive the class
| auto-loader. This simple approach helps avoid the performance problems
| of searching through directories by convention.
|
| Registering a mapping couldn't be easier. Just pass an array of class
| to path maps into the "map" function of Autoloader. Then, when you
| want to use that class, just use it. It's simple!
|
*/
Autoloader::map(array('Theme' => Bundle::path('theme') . "theme.php"));
/*
|--------------------------------------------------------------------------
| Auto-Loader Directories
|--------------------------------------------------------------------------
|
| The Laravel auto-loader can search directories for files using the PSR-0
| naming convention. This convention basically organizes classes by using
| the class namespace to indicate the directory structure.
|
*/
Autoloader::directories(array());
IoC::singleton('Theme', function () {
$config = array('theme_path' => 'themes');
return $theme = new Theme("admin", $config);
});
示例9: function
<?php
// Register mogreet in the IoC container
IoC::singleton('mogreet', function () {
require_once Bundle::path('mogreet') . 'src' . DS . 'Mercury.class.php';
require_once Bundle::path('mogreet') . 'src' . DS . 'Response.class.php';
$config = Config::get('mogreet::mogreet', array());
$mogreet = new \Mogreet\Mercury($config['client_id'], $config['token']);
return $mogreet;
});
示例10: function
<?php
/*
|--------------------------------------------------------------------------
| Forms Library
|--------------------------------------------------------------------------
|
| Map Forms Library using PSR-0 standard namespace.
*/
Autoloader::namespaces(array('Themes\\Model' => Bundle::path('themes') . 'models' . DS, 'Themes' => Bundle::path('themes') . 'libraries' . DS));
IoC::singleton('Theme', function () {
$config = array('theme_path' => '');
return $theme = new Themes\Theme('base', $config);
});
示例11: function
<?php
require_once 'src/facebook.php';
IoC::singleton('fb', function () {
$active_app = Config::get('fb::active.app');
return new Facebook(Config::get("fb::apps.{$active_app}"));
});
foreach (Config::get('fb::apps') as $app => $keys) {
IoC::singleton("fb.{$app}", function () use($keys) {
return new Facebook($keys);
});
}
示例12: get_excluded_tags
}
/**
* Gets an array of tages to be excluded from
* the elcude param
* @param int $exclude What to gets excluded from i.e. SBBCodeParser_BBCode::AUTO_DETECT_EXCLUDE_EMOTICON
* @return array
*/
private function get_excluded_tags($exclude)
{
$ret = array();
foreach ($this->bbcodes as $bbcode) {
if ($bbcode->auto_detect_exclude() & $exclude) {
$ret[] = $bbcode->tag();
}
}
return $ret;
}
}
IoC::singleton('BBCodeDocParser', function () {
$instance = new SBBCodeParser_Document();
$instance->add_emoticons(array(":)" => URL::to_asset('bundles/forums/emoticons/smile.png'), "=)" => URL::to_asset('bundles/forums/emoticons/smile.png'), "=]" => URL::to_asset('bundles/forums/emoticons/smile.png'), ":angel:" => URL::to_asset('bundles/forums/emoticons/angel.png'), ":angry:" => URL::to_asset('bundles/forums/emoticons/angry.png'), "8-)" => URL::to_asset('bundles/forums/emoticons/cool.png'), ":'(" => URL::to_asset('bundles/forums/emoticons/cwy.png'), "='(" => URL::to_asset('bundles/forums/emoticons/cwy.png'), "='[" => URL::to_asset('bundles/forums/emoticons/cwy.png'), ":ermm:" => URL::to_asset('bundles/forums/emoticons/ermm.png'), ":D" => URL::to_asset('bundles/forums/emoticons/grin.png'), "=D" => URL::to_asset('bundles/forums/emoticons/grin.png'), "<3" => URL::to_asset('bundles/forums/emoticons/heart.png'), ":(" => URL::to_asset('bundles/forums/emoticons/sad.png'), ":O" => URL::to_asset('bundles/forums/emoticons/shocked.png'), ":P" => URL::to_asset('bundles/forums/emoticons/tongue.png'), "=(" => URL::to_asset('bundles/forums/emoticons/sad.png'), "=[" => URL::to_asset('bundles/forums/emoticons/sad.png'), "=O" => URL::to_asset('bundles/forums/emoticons/shocked.png'), "=P" => URL::to_asset('bundles/forums/emoticons/tongue.png'), ";)" => URL::to_asset('bundles/forums/emoticons/wink.png'), ":alien:" => URL::to_asset('bundles/forums/emoticons/alien.png'), ":blink:" => URL::to_asset('bundles/forums/emoticons/blink.png'), ":blush:" => URL::to_asset('bundles/forums/emoticons/blush.png'), ":cheerful:" => URL::to_asset('bundles/forums/emoticons/cheerful.png'), ":devil:" => URL::to_asset('bundles/forums/emoticons/devil.png'), ":dizzy:" => URL::to_asset('bundles/forums/emoticons/dizzy.png'), ":getlost:" => URL::to_asset('bundles/forums/emoticons/getlost.png'), ":happy:" => URL::to_asset('bundles/forums/emoticons/happy.png'), ":kissing:" => URL::to_asset('bundles/forums/emoticons/kissing.png'), ":ninja:" => URL::to_asset('bundles/forums/emoticons/ninja.png'), ":pinch:" => URL::to_asset('bundles/forums/emoticons/pinch.png'), ":pouty:" => URL::to_asset('bundles/forums/emoticons/pouty.png'), ":sick:" => URL::to_asset('bundles/forums/emoticons/sick.png'), ":sideways:" => URL::to_asset('bundles/forums/emoticons/sideways.png'), ":silly:" => URL::to_asset('bundles/forums/emoticons/silly.png'), ":sleeping:" => URL::to_asset('bundles/forums/emoticons/sleeping.png'), ":unsure:" => URL::to_asset('bundles/forums/emoticons/unsure.png'), ":woot:" => URL::to_asset('bundles/forums/emoticons/w00t.png'), ":wassat:" => URL::to_asset('bundles/forums/emoticons/wassat.png')));
return $instance;
});
class BBCodeParser
{
public static function parse($elements)
{
$parser = IoC::resolve('BBCodeDocParser');
return $parser->parse($elements)->detect_links()->detect_emails()->detect_emoticons()->get_html();
}
}
示例13: function
| Include FirePHP class as FireAnbu dependency.
|
*/
Autoloader::map(array('FirePHP' => Bundle::path('fireanbu') . 'vendors' . DS . 'FirePHPCore' . DS . 'FirePHP.class' . EXT));
/*
|--------------------------------------------------------------------------
| FireAnbu IoC
|--------------------------------------------------------------------------
|
| Register FirePHP singleton using IoC, in case you need to overwrite the
| implementation in your application.
|
*/
IoC::singleton('fireanbu', function () {
$fb = new FirePHP();
$fb->setEnabled(Config::get('fireanbu::fireanbu.profiler', true));
return $fb;
});
/*
|--------------------------------------------------------------------------
| Listen to `laravel.log` events
|--------------------------------------------------------------------------
*/
Event::listen('laravel.log', function ($type, $message) {
$fb = IoC::resolve('fireanbu');
switch (Str::upper($type)) {
case FirePHP::INFO:
case FirePHP::WARN:
case FirePHP::LOG:
case FirePHP::ERROR:
$fb->{$type}($message);
示例14: foreach
<?php
require __DIR__ . '/libraries/upload.class.php';
foreach (Config::get('jupload::settings') as $key => $val) {
$options[$key] = $val;
}
IoC::singleton('UploadHandler', function () use($options) {
return new UploadHandler($options);
});