本文整理匯總了PHP中Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter方法的典型用法代碼示例。如果您正苦於以下問題:PHP GlobalAdapterFeature::setStaticAdapter方法的具體用法?PHP GlobalAdapterFeature::setStaticAdapter怎麽用?PHP GlobalAdapterFeature::setStaticAdapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Db\TableGateway\Feature\GlobalAdapterFeature
的用法示例。
在下文中一共展示了GlobalAdapterFeature::setStaticAdapter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($e->getApplication()->getServiceManager()->get('Zend\\Db\\Adapter\\Adapter'));
// running access check
/* $eventManager->attach(MvcEvent::EVENT_ROUTE,
function ($e)
{
$login = $e->getRouter()->assemble(array(), array('name' => 'login'));
$match = $e->getRouteMatch();
$name = $match->getMatchedRouteName();
if ('profile' == $name){
$auth = $e->getApplication()
->getServiceManager()
->get('Zend\Authentication\AuthenticationService');
if(false === $auth->hasIdentity())
{
$response = $e->getResponse();
$response->getHeaders()
->addHeaderLine('Location', $login);
$response->setStatusCode(302);
return $response;
}
}
}, - 100);
*/
}
示例2: getServiceConfig
/**
* Get Service configuration
*/
public function getServiceConfig()
{
return array('factories' => array('Model' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($dbAdapter);
return \Emp\Model\Factory::getInstance();
}));
}
示例3: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$adapter = $e->getApplication()->getServiceManager()->get('dbBatDongSan');
GlobalAdapterFeature::setStaticAdapter($adapter);
}
示例4: prepareAdapter
/**
* Setup method -- make sure static adapter is available for testing.
*
* @return void
*/
public static function prepareAdapter()
{
try {
DbGlobalAdapter::getStaticAdapter();
} catch (\Zend\Db\TableGateway\Exception\RuntimeException $e) {
DbGlobalAdapter::setStaticAdapter(DbAdapterFactory::getAdapter());
}
}
示例5: getServiceConfig
public function getServiceConfig()
{
return array('factories' => array('Zend\\Db\\Adapter\\Adapter' => function ($serviceManager) {
$adapterFactory = new \Zend\Db\Adapter\AdapterServiceFactory();
$adapter = $adapterFactory->createService($serviceManager);
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
return $adapter;
}));
}
示例6: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// set static adapter for all module table gateways
$serviceManager = $e->getApplication()->getServiceManager();
$dbAdapter = $serviceManager->get('Zend\\Db\\Adapter\\Adapter');
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($dbAdapter);
}
示例7: onBootstrap
public function onBootstrap(MvcEvent $e)
{
// You may not need to do this if you're doing it elsewhere in your
// application
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sm = $e->getApplication()->getServiceManager();
$adapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
}
示例8: createService
/**
* @param ServiceLocatorInterface $serviceLocator
* @return \Home\Service\Store
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$adapterFactory = new \Zend\Db\Adapter\AdapterServiceFactory();
$adapter = $adapterFactory->createService($serviceLocator);
$config = $serviceLocator->get('Config');
if (isset($config['db']['profilerEnabled']) && $config['db']['profilerEnabled']) {
$adapter->setProfiler(new \Zend\Db\Adapter\Profiler\Profiler());
}
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
return $adapter;
}
示例9: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
//inherit from znZend Module
$sm = $e->getApplication()->getServiceManager();
// Set global/static db adapter for feature-enabled TableGateways such as ZnZend\Model\AbstractMapper
// For example only - up to application to set it as the service manager key for the db adapter may be different
if ($sm->has('Zend\\Db\\Adapter\\Adapter')) {
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($sm->get('Zend\\Db\\Adapter\\Adapter'));
}
}
示例10: testCreateServiceWithName
public function testCreateServiceWithName()
{
$tableName = 'foo';
$serviceLocatorMock = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface');
$moduleConfigMock = $this->getMockBuilder('T4webBase\\Module\\ModuleConfig')->disableOriginalConstructor()->getMock();
$serviceLocatorMock->expects($this->at(0))->method('get')->with($this->equalTo('ModuleName\\ModuleConfig'))->will($this->returnValue($moduleConfigMock));
$moduleConfigMock->expects($this->once())->method('getDbTableName')->with($this->equalTo('modulename-entity'))->will($this->returnValue($tableName));
$dbAdapterMock = $this->getDbAdapterMock();
GlobalAdapterFeature::setStaticAdapter($dbAdapterMock);
$tableGateway = $this->abstractFactory->createServiceWithName($serviceLocatorMock, $name = 'foo', 'ModuleName\\Entity\\TableGateway');
$this->assertInstanceOf('T4webBase\\Db\\TableGateway', $tableGateway);
$this->assertAttributeSame($tableName, 'table', $tableGateway);
}
示例11: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$sm = $app->getServiceManager();
$request = $app->getRequest();
$response = $app->getResponse();
$appConfig = $sm->get('Configuration');
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($appConfig['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
$responseHeaders = $response->getHeaders();
$requestHeaders = $request->getHeaders();
$this->checkCloudFlareHttpHeader();
$requestUriPath = $request->getUri()->getPath();
$requestExtension = pathinfo($requestUriPath, PATHINFO_EXTENSION);
if (!in_array($requestExtension, ['js', 'css'])) {
$eventManager = $app->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sharedManager = $eventManager->getSharedManager();
$sharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) use($sm) {
$controller = $e->getTarget();
$controller->getEventManager()->attachAggregate($sm->get('Visitor'));
}, 2);
$client = new RemoteAddress();
$queryParams = $request->getQuery();
$setPartnerId = (isset($queryParams['gid']) and is_numeric($queryParams['gid'])) ? ['gid' => (int) $queryParams['gid'], 'url' => $request->getUri()] : FALSE;
$setLang = (isset($queryParams['lang']) and is_string($queryParams['lang'])) ? ['lang' => $queryParams['lang'], 'url' => $request->getUri()] : FALSE;
$setCurrency = (isset($queryParams['cur']) and is_string($queryParams['cur'])) ? ['cur' => $queryParams['cur'], 'url' => $request->getUri()] : FALSE;
if ($requestHeaders->has('Accept-Language')) {
$browserLang = $requestHeaders->get('Accept-Language')->getPrioritized();
} else {
$browserLang = FALSE;
}
if ($requestHeaders->has('User-Agent')) {
$userAgent = $requestHeaders->get('User-Agent')->getFieldValue();
} else {
$userAgent = FALSE;
}
if ($requestHeaders->has('Referer')) {
$referer = $requestHeaders->get('Referer');
} else {
$referer = FALSE;
}
$eventManager->trigger('detectVisitor', $this, array('setLang' => $setLang, 'setCurrency' => $setCurrency, 'browserLang' => $browserLang, 'userAgent' => $userAgent, 'referer' => $referer, 'request' => $request, 'clientIp' => $client->getIpAddress(), 'clientProxy' => $client->getUseProxy(), 'setPartnerId' => $setPartnerId, 'sessionManager' => $sessionManager, 'response' => $response, 'responseHeaders' => $responseHeaders, 'requestHeaders' => $requestHeaders, 'serviceLocator' => $sm));
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, array($this, 'onPreDispatch'));
}
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
GlobalAdapterFeature::setStaticAdapter($dbAdapter);
}
示例12: onBootstrap
public function onBootstrap(MvcEvent $e)
{
/**
* @var Adapter $dbAdapter
*/
$event = $e->getApplication();
$eventManager = $event->getEventManager();
$this->bootstrapSession($e);
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, [$this, 'onPreDispatch']);
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, [$this, 'onViewHelper']);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// set static adapter for all module table gateways
$serviceManager = $e->getApplication()->getServiceManager();
$dbAdapter = $serviceManager->get('Zend\\Db\\Adapter\\Adapter');
GlobalAdapterFeature::setStaticAdapter($dbAdapter);
}
示例13: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'setRouteMatch'), -1);
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'setLanguages'), -2);
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'accessControl'), -3);
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'globalLayoutVars'), -4);
$eventManager->attach(MvcEvent::EVENT_BOOTSTRAP, array($this, 'bootstrapSession'), 100);
//use the error template of the currently used module
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'controllerNotFound'), -200);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'actionNotFound'), -201);
$eventManager->getSharedManager()->attach('custom', '403', function (MvcEvent $event) use($eventManager) {
$viewModel = new ViewModel();
$viewModel->setTemplate('error/403');
$appViewModel = $event->getViewModel();
$appViewModel->setTemplate('layout/layout');
$appViewModel->addChild($viewModel, 'content');
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) {
$event->stopPropagation(true);
}, 100);
});
$dbAdapter = $serviceManager->get('dbadapter');
GlobalAdapterFeature::setStaticAdapter($dbAdapter);
AbstractValidator::setDefaultTranslator(new \Zend\Mvc\I18n\Translator($serviceManager->get('translator')));
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$serviceManager->get('ViewHelperManager')->setFactory('langUrl', function () use($e) {
$viewHelper = new View\Helper\Url($e->getRouteMatch());
return $viewHelper;
});
if ($serviceManager->has('text-cache')) {
// This will be used to check if there is already cached page and return it.
// The priority must be low in order to be executed after the routing is done
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'getPageCache'), -1000);
// And this will be used to save a generated cache page.
// The priority must be low in order to be executed after the rendering is done
$eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'savePageCache'), -10000);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'getActionCache'), 2);
$eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'saveActionCache'), 0);
}
}
示例14: onBootstrap
public function onBootstrap(MvcEvent $event)
{
$services = $event->getApplication()->getServiceManager();
$dbAdapter = $services->get('database');
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($dbAdapter);
$eventManager = $event->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'protectPage'), -100);
$sharedEventManager = $event->getApplication()->getEventManager()->getSharedManager();
$sharedEventManager->attach('user', 'log-fail', function ($event) use($services) {
$username = $event->getParam('username');
$log = $services->get('log');
$log->warn('Error logging user [' . $username . ']');
});
$sharedEventManager->attach('user', 'register', function ($event) use($services) {
$user = $event->getParam('user');
$log = $services->get('log');
$log->warn('Registered user [' . $user->getName() . '/' . $user->getId() . ']');
});
$eventManager->attach('render', array($this, 'injectUserAcl'));
}
示例15: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// initialize Global Static Db Adapter
if ($e->getApplication()->getServiceManager()->has('Zend\\Db\\Adapter\\Adapter')) {
$adapter = $e->getApplication()->getServiceManager()->get('Zend\\Db\\Adapter\\Adapter');
GlobalAdapterFeature::setStaticAdapter($adapter);
}
// session
$session = $e->getApplication()->getServiceManager()->get('Application\\SessionManager');
$session->start();
$container = new Container('initialized');
if (!isset($container->init)) {
$session->regenerateId(true);
$container->init = 1;
}
Container::setDefaultManager($session);
$this->bootstrapGlobalMvcEventErrorListener($e);
$this->bootstrapSetLayouts($e);
}