本文整理汇总了PHP中ServiceLocator类的典型用法代码示例。如果您正苦于以下问题:PHP ServiceLocator类的具体用法?PHP ServiceLocator怎么用?PHP ServiceLocator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceLocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(ServiceLocator $sl, $path)
{
$this->request = $sl->get('request');
$this->response = $sl->get('response');
$this->path = $path;
// …
}
示例2: create
/**
* @return TestDbAcle;
*/
public static function create(\Pdo $pdo, $factoryOverrides = array(), $factories = null)
{
if (is_null($factories)) {
$factories = new Config\DefaultFactories();
}
$testDbAcle = new TestDbAcle();
$serviceLocator = new ServiceLocator($factories->getFactories($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)));
$serviceLocator->addFactories($factoryOverrides);
$serviceLocator->setService('pdo', $pdo);
$testDbAcle->setServiceLocator($serviceLocator);
return $testDbAcle;
}
示例3: __construct
public function __construct()
{
parent::__construct();
$userRepository = new UserRepository();
$user = ServiceLocator::GetServer()->GetUserSession();
$this->_presenter = new ManageSchedulesPresenter($this, new ScheduleAdminManageScheduleService(new ScheduleAdminScheduleRepository($userRepository, $user), new ScheduleRepository(), new ResourceAdminResourceRepository($userRepository, $user)), new GroupRepository());
}
示例4: PageLoad
public function PageLoad()
{
ob_clean();
$this->presenter->PageLoad();
$config = Configuration::Instance();
$feed = new FeedWriter(ATOM);
$title = $config->GetKey(ConfigKeys::APP_TITLE);
$feed->setTitle("{$title} Reservations");
$url = $config->GetScriptUrl();
$feed->setLink($url);
$feed->setChannelElement('updated', date(DATE_ATOM, time()));
$feed->setChannelElement('author', array('name' => $title));
foreach ($this->reservations as $reservation) {
/** @var FeedItem $item */
$item = $feed->createNewItem();
$item->setTitle($reservation->Summary);
$item->setLink($reservation->ReservationUrl);
$item->setDate($reservation->DateCreated->Timestamp());
$item->setDescription($this->FormatReservationDescription($reservation, ServiceLocator::GetServer()->GetUserSession()));
// sprintf('<div><span>Start</span> %s</div>
// <div><span>End</span> %s</div>
// <div><span>Organizer</span> %s</div>
// <div><span>Description</span> %s</div>',
// $reservation->DateStart->ToString(),
// $reservation->DateEnd->ToString(),
// $reservation->Organizer,
// $reservation->Description));
$feed->addItem($item);
}
$feed->genarateFeed();
}
示例5: GetList
/**
* Returns a limited query based on page number and size
* If nulls are passed for both $pageNumber, $pageSize then all results are returned
*
* @param SqlCommand $command
* @param callback $listBuilder callback to for each row of results
* @param int|null $pageNumber
* @param int|null $pageSize
* @param string|null $sortField
* @param string|null $sortDirection
* @return PageableData
*/
public static function GetList($command, $listBuilder, $pageNumber = null, $pageSize = null, $sortField = null, $sortDirection = null)
{
$total = null;
$totalCounter = 0;
$results = array();
$db = ServiceLocator::GetDatabase();
$pageNumber = intval($pageNumber);
$pageSize = intval($pageSize);
if (empty($pageNumber) && empty($pageSize) || $pageSize == PageInfo::All) {
$resultReader = $db->Query($command);
} else {
$totalReader = $db->Query(new CountCommand($command));
if ($row = $totalReader->GetRow()) {
$total = $row[ColumnNames::TOTAL];
}
$pageNumber = empty($pageNumber) ? 1 : $pageNumber;
$pageSize = empty($pageSize) ? 1 : $pageSize;
$resultReader = $db->LimitQuery($command, $pageSize, ($pageNumber - 1) * $pageSize);
}
while ($row = $resultReader->GetRow()) {
$results[] = call_user_func($listBuilder, $row);
$totalCounter++;
}
$resultReader->Free();
return new PageableData($results, is_null($total) ? $totalCounter : $total, $pageNumber, $pageSize);
}
示例6: __construct
protected function __construct($titleKey = '', $pageDepth = 0)
{
$this->SetSecurityHeaders();
$this->path = str_repeat('../', $pageDepth);
$this->server = ServiceLocator::GetServer();
$resources = Resources::GetInstance();
ExceptionHandler::SetExceptionHandler(new WebExceptionHandler(array($this, 'RedirectToError')));
$this->smarty = new SmartyPage($resources, $this->path);
$userSession = ServiceLocator::GetServer()->GetUserSession();
$this->smarty->assign('Charset', $resources->Charset);
$this->smarty->assign('CurrentLanguage', $resources->CurrentLanguage);
$this->smarty->assign('HtmlLang', $resources->HtmlLang);
$this->smarty->assign('HtmlTextDirection', $resources->TextDirection);
$appTitle = Configuration::Instance()->GetKey(ConfigKeys::APP_TITLE);
$pageTile = $resources->GetString($titleKey);
$this->smarty->assign('Title', (empty($appTitle) ? 'Booked' : $appTitle) . (empty($pageTile) ? '' : ' - ' . $pageTile));
$this->smarty->assign('CalendarJSFile', $resources->CalendarLanguageFile);
$this->smarty->assign('LoggedIn', $userSession->IsLoggedIn());
$this->smarty->assign('Version', Configuration::VERSION);
$this->smarty->assign('Path', $this->path);
$this->smarty->assign('ScriptUrl', Configuration::Instance()->GetScriptUrl());
$this->smarty->assign('UserName', !is_null($userSession) ? $userSession->FirstName : '');
$this->smarty->assign('DisplayWelcome', $this->DisplayWelcome());
$this->smarty->assign('UserId', $userSession->UserId);
$this->smarty->assign('CanViewAdmin', $userSession->IsAdmin);
$this->smarty->assign('CanViewGroupAdmin', $userSession->IsGroupAdmin);
$this->smarty->assign('CanViewResourceAdmin', $userSession->IsResourceAdmin);
$this->smarty->assign('CanViewScheduleAdmin', $userSession->IsScheduleAdmin);
$this->smarty->assign('CanViewResponsibilities', !$userSession->IsAdmin && ($userSession->IsGroupAdmin || $userSession->IsResourceAdmin || $userSession->IsScheduleAdmin));
$allowAllUsersToReports = Configuration::Instance()->GetSectionKey(ConfigSection::REPORTS, ConfigKeys::REPORTS_ALLOW_ALL, new BooleanConverter());
$this->smarty->assign('CanViewReports', $allowAllUsersToReports || $userSession->IsAdmin || $userSession->IsGroupAdmin || $userSession->IsResourceAdmin || $userSession->IsScheduleAdmin);
$timeout = Configuration::Instance()->GetKey(ConfigKeys::INACTIVITY_TIMEOUT);
if (!empty($timeout)) {
$this->smarty->assign('SessionTimeoutSeconds', max($timeout, 1) * 60);
}
$this->smarty->assign('ShouldLogout', $this->GetShouldAutoLogout());
$this->smarty->assign('CssExtensionFile', Configuration::Instance()->GetKey(ConfigKeys::CSS_EXTENSION_FILE));
$this->smarty->assign('UseLocalJquery', Configuration::Instance()->GetKey(ConfigKeys::USE_LOCAL_JQUERY, new BooleanConverter()));
$this->smarty->assign('EnableConfigurationPage', Configuration::Instance()->GetSectionKey(ConfigSection::PAGES, ConfigKeys::PAGES_ENABLE_CONFIGURATION, new BooleanConverter()));
$this->smarty->assign('ShowParticipation', !Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_PREVENT_PARTICIPATION, new BooleanConverter()));
$this->smarty->assign('LogoUrl', 'booked.png');
if (file_exists($this->path . 'img/custom-logo.png')) {
$this->smarty->assign('LogoUrl', 'custom-logo.png');
}
if (file_exists($this->path . 'img/custom-logo.gif')) {
$this->smarty->assign('LogoUrl', 'custom-logo.gif');
}
if (file_exists($this->path . 'img/custom-logo.jpg')) {
$this->smarty->assign('LogoUrl', 'custom-logo.jpg');
}
$this->smarty->assign('CssUrl', 'null-style.css');
if (file_exists($this->path . 'css/custom-style.css')) {
$this->smarty->assign('CssUrl', 'custom-style.css');
}
$logoUrl = Configuration::Instance()->GetKey(ConfigKeys::HOME_URL);
if (empty($logoUrl)) {
$logoUrl = $this->path . Pages::UrlFromId($userSession->HomepageId);
}
$this->smarty->assign('HomeUrl', $logoUrl);
}
示例7: PageLoad
public function PageLoad()
{
$this->Set('DefaultTitle', Resources::GetInstance()->GetString('NoTitleLabel'));
$this->presenter->SetSearchCriteria(ServiceLocator::GetServer()->GetUserSession()->UserId, ReservationUserLevel::ALL);
$this->presenter->PageLoad();
$this->Display('upcoming_reservations.tpl');
}
示例8: update
/**
* Update method to register message sending events.
*
* @access public
* @param $args['news_id'] Newsletter identifier refferring to the event.
* * @param $args['msg_id'] Message identifier refferring to the event.
* @return false if something wrong.
* @since 0.6
*/
function update(&$args)
{
jincimport('utility.servicelocator');
$servicelocator = ServiceLocator::getInstance();
$logger = $servicelocator->getLogger();
if (!isset($args['news_id']) || !isset($args['msg_id'])) {
return false;
}
$news_id = (int) $args['news_id'];
$msg_id = (int) $args['msg_id'];
$dbo =& JFactory::getDBO();
$query = 'UPDATE #__jinc_newsletter SET lastsent = now() ' . 'WHERE id = ' . (int) $news_id;
$dbo->setQuery($query);
$logger->debug('SentMsgEvent: executing query: ' . $query);
if (!$dbo->query()) {
$logger->error('SentMsgEvent: error updating last newsletter dispatch date');
return false;
}
$query = 'UPDATE #__jinc_message SET datasent = now() ' . 'WHERE id = ' . (int) $msg_id;
$dbo->setQuery($query);
$logger->debug('SentMsgEvent: executing query: ' . $query);
if (!$dbo->query()) {
$logger->error('SentMsgEvent: error updating last message dispatch date');
return false;
}
return true;
}
示例9: __construct
public function __construct($user = null)
{
$this->user = $user;
if ($this->user == null) {
$this->user = ServiceLocator::GetServer()->GetUserSession();
}
}
示例10: setup
function setup()
{
$this->_db = new FakeDatabase();
ServiceLocator::SetDatabase($this->_db);
$this->newEncryption = new PasswordEncryption();
$this->oldEncryption = new RetiredPasswordEncryption();
}
示例11: __construct
/**
* @param IReservationViewRepository $reservationViewRepository
* @param IReservationAuthorization $authorization
* @param IReservationHandler $reservationHandler
* @param IUpdateReservationPersistenceService $persistenceService
*/
public function __construct(IReservationViewRepository $reservationViewRepository, $authorization = null, $reservationHandler = null, $persistenceService = null)
{
$this->reservationViewRepository = $reservationViewRepository;
$this->reservationAuthorization = $authorization == null ? new ReservationAuthorization(PluginManager::Instance()->LoadAuthorization()) : $authorization;
$this->persistenceService = $persistenceService == null ? new UpdateReservationPersistenceService(new ReservationRepository()) : $persistenceService;
$this->reservationHandler = $reservationHandler == null ? ReservationHandler::Create(ReservationAction::Update, $this->persistenceService, ServiceLocator::GetServer()->GetUserSession()) : $reservationHandler;
}
示例12: display
function display($tpl = null)
{
$layout = $this->getLayout();
if ($layout == 'multisubscription') {
$this->newsletters = array();
if (isset($this->mmsg)) {
jincimport('utility.servicelocator');
$servicelocator = ServiceLocator::getInstance();
$logger = $servicelocator->getLogger();
jincimport('core.newsletterfactory');
$ninstance = NewsletterFactory::getInstance();
foreach ($this->mmsg as $news_id => $text) {
if ($newsletter = $ninstance->loadNewsletter($news_id, true)) {
$this->newsletters[$news_id] = $newsletter;
}
}
}
} else {
$news_id = JRequest::getInt('id', 0);
jincimport('core.newsletterfactory');
$ninstance = NewsletterFactory::getInstance();
if ($newsletter = $ninstance->loadNewsletter($news_id, true)) {
$this->newsletter = $newsletter;
}
}
parent::display($tpl);
}
示例13: __construct
public function __construct()
{
parent::__construct();
$userRepository = new UserRepository();
$this->presenter = new ManageReservationsPresenter($this, new ScheduleAdminManageReservationsService(new ReservationViewRepository(), $userRepository, new ReservationAuthorization(PluginManager::Instance()->LoadAuthorization())), new ScheduleAdminScheduleRepository($userRepository, ServiceLocator::GetServer()->GetUserSession()), new ResourceAdminResourceRepository($userRepository, ServiceLocator::GetServer()->GetUserSession()), new AttributeService(new AttributeRepository()), new UserPreferenceRepository());
$this->SetPageId('manage-reservations-schedule-admin');
}
示例14: ProcessPageLoad
public function ProcessPageLoad()
{
$this->presenter->PageLoad();
$this->Set('priorities', range(1, 10));
$this->Set('timezone', ServiceLocator::GetServer()->GetUserSession()->Timezone);
$this->Display('Admin/manage_announcements.tpl');
}
示例15: Notify
/**
* @param ReservationSeries $reservationSeries
* @return void
*/
public function Notify($reservationSeries)
{
$resourceAdmins = array();
$applicationAdmins = array();
$groupAdmins = array();
if ($this->SendForResourceAdmins($reservationSeries)) {
$resourceAdmins = $this->userViewRepo->GetResourceAdmins($reservationSeries->ResourceId());
}
if ($this->SendForApplicationAdmins($reservationSeries)) {
$applicationAdmins = $this->userViewRepo->GetApplicationAdmins();
}
if ($this->SendForGroupAdmins($reservationSeries)) {
$groupAdmins = $this->userViewRepo->GetGroupAdmins($reservationSeries->UserId());
}
$admins = array_merge($resourceAdmins, $applicationAdmins, $groupAdmins);
if (count($admins) == 0) {
// skip if there is nobody to send to
return;
}
$owner = $this->userRepo->LoadById($reservationSeries->UserId());
$resource = $reservationSeries->Resource();
$adminIds = array();
/** @var $admin UserDto */
foreach ($admins as $admin) {
$id = $admin->Id();
if (array_key_exists($id, $adminIds) || $id == $owner->Id()) {
// only send to each person once
continue;
}
$adminIds[$id] = true;
$message = $this->GetMessage($admin, $owner, $reservationSeries, $resource);
ServiceLocator::GetEmailService()->Send($message);
}
}