本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::get方法的具体用法?PHP ServiceManager::get怎么用?PHP ServiceManager::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: email
/**
* @return $this
*/
protected function email()
{
$uniqueObjectValidator = new UniqueObject(['object_repository' => $this->sm->get('Doctrine\\ORM\\EntityManager')->getRepository('User\\Entity\\User'), 'fields' => ['email'], 'object_manager' => $this->sm->get('Doctrine\\ORM\\EntityManager'), 'use_context' => true]);
$uniqueObjectValidator->setMessage('Email is already taken', UniqueObject::ERROR_OBJECT_NOT_UNIQUE);
$this->add(array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'EmailAddress'), $uniqueObjectValidator), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
return $this;
}
示例2: check
/**
* Check var/generation read and write access
*
* @return bool
*/
public function check()
{
$initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
$filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
$directoryList = new DirectoryList(BP, $filesystemDirPaths);
$generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
$driverPool = new DriverPool();
$fileWriteFactory = new WriteFactory($driverPool);
/** @var \Magento\Framework\Filesystem\DriverInterface $driver */
$driver = $driverPool->getDriver(DriverPool::FILE);
$directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
if ($directoryWrite->isExist()) {
if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
try {
$probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
$fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
$driver->deleteFile($probeFilePath);
} catch (\Exception $e) {
return false;
}
} else {
return false;
}
} else {
try {
$directoryWrite->create();
} catch (\Exception $e) {
return false;
}
}
return true;
}
示例3: setUp
/**
* {@inheritDoc}
*/
public function setUp()
{
$this->serviceManager = Bootstrap::getServiceManager();
$this->doa = new Doa();
$this->doa->setId(1);
$program = new Program();
$program->setId(1);
$program->setProgram('Program');
$this->doa->setProgram($program);
$organisation = new Organisation();
$organisation->setId(1);
$organisation->setOrganisation("Organisation");
$this->doa->setOrganisation($organisation);
$this->authorizeService = $this->serviceManager->get('BjyAuthorize\\Service\\Authorize');
if (!$this->authorizeService->getAcl()->hasResource($this->doa)) {
$this->authorizeService->getAcl()->addResource($this->doa);
$this->authorizeService->getAcl()->allow([], $this->doa, []);
}
/**
* Add the resource on the fly
*/
if (!$this->authorizeService->getAcl()->hasResource(new Doa())) {
$this->authorizeService->getAcl()->addResource(new Doa());
}
$this->authorizeService->getAcl()->allow([], new Doa(), []);
$this->doaLink = $this->serviceManager->get('viewhelpermanager')->get('programDoaLink');
/**
* Bootstrap the application to have the other information available
*/
$application = $this->serviceManager->get('application');
$application->bootstrap();
}
示例4: email
/**
* @return $this
*/
protected function email()
{
$recordExistsValidator = new UniqueObject(array('object_repository' => $this->sm->get('Doctrine\\ORM\\EntityManager')->getRepository('Test\\Entity\\Test'), 'object_manager' => $this->sm->get('Doctrine\\ORM\\EntityManager'), 'fields' => 'email', 'use_context' => true));
$recordExistsValidator->setMessage('This email already in use', UniqueObject::ERROR_OBJECT_NOT_UNIQUE);
$this->add(array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'EmailAddress'), $recordExistsValidator), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
return $this;
}
示例5: setUp
/**
* Setup
*/
protected function setUp()
{
// get service manager
$this->serviceLocator = AclBootstrap::getServiceLocator();
// get acl model
$this->aclModelBase = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Acl\\Model\\AclBase');
}
示例6: generateCertificate
/**
* Generates certificate of exellence and
* triggers an event when the file is generated
* @param \User\Model\Entity\User $user
* @param string $examName
*/
public function generateCertificate($user, $examName)
{
$config = $this->services->get('config');
$pdf = PdfDocument::load($config['pdf']['exam_certificate']);
// get the first page
$page = $pdf->pages[0];
// Extract the AdineKirnberg-Script font included in the PDF sample
$font = $page->extractFont('AdineKirnberg-Script');
$page->setFont($font, 80);
// and write the name of the user with it
$page->drawText($user->getName(), 200, 280);
// after that use Time Bold to write the name of the exam
$font = PdfFont::fontWithName(PdfFont::FONT_TIMES_BOLD);
$page->setFont($font, 40);
$page->drawText($examName, 200, 120);
// We use the png image from the public/images folder
$imageFile = 'public/images/zf2-logo.png';
// get the right size to do some calculations
$size = getimagesize($imageFile);
// load the image
$image = \ZendPdf\Image::imageWithPath($imageFile);
$x = 580;
$y = 440;
// and finally draw the image
$page->drawImage($image, $x, $y, $x + $size[0], $y + $size[1]);
return $pdf;
}
示例7: setUp
/**
* Setup
*/
protected function setUp()
{
// get service manager
$this->serviceLocator = ApplicationBootstrap::getServiceLocator();
// get base model instance
$this->model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationBase');
}
示例8: setUp
public function setUp()
{
Bootstrap::setUpAclDatabase();
$em = Bootstrap::getServiceManager()->get('doctrine.entitymanager.orm_default');
/* @var $em \Doctrine\ORM\EntityManager */
$this->serviceManager = Bootstrap::getServiceManager();
$this->acl = $this->serviceManager->get('jaztec_acl_service')->getAcl();
$resource1 = new \JaztecAcl\Entity\Acl\Resource('resource01');
$resource2 = new \JaztecAcl\Entity\Acl\Resource('resource02', $resource1);
$resource3 = new \JaztecAcl\Entity\Acl\Resource('resource03', $resource2);
$resource4 = new \JaztecAcl\Entity\Acl\Resource('resource04');
$resource5 = new \JaztecAcl\Entity\Acl\Resource('resource05', $resource4);
$privilege1 = new \JaztecAcl\Entity\Acl\Privilege();
$privilege1->setResource($resource5);
$privilege1->setRole($em->getRepository('JaztecAcl\\Entity\\Acl\\Role')->findOneBy(['name' => 'guest']));
$privilege1->setType('allow');
$em->persist($privilege1);
$em->persist($resource1);
$em->persist($resource2);
$em->persist($resource3);
$em->persist($resource4);
$em->persist($resource5);
$em->flush();
// Clear the ACL.
$this->acl->removeResourceAll();
$this->acl->removeRoleAll();
$this->acl->setupAcl();
}
示例9: testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfaceServicePresentWithMinimumBootstrap
public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfaceServicePresentWithMinimumBootstrap()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('This test will only run if ext/intl is present');
}
//minimum bootstrap
$applicationConfig = array('module_listener_options' => array(), 'modules' => array());
$serviceLocator = new ServiceManager(new ServiceManagerConfig());
$serviceLocator->setService('ApplicationConfig', $applicationConfig);
$serviceLocator->get('ModuleManager')->loadModules();
$serviceLocator->get('Application')->bootstrap();
//enable to re-write Config
$ref = new \ReflectionObject($serviceLocator);
$prop = $ref->getProperty('allowOverride');
$prop->setAccessible(true);
$prop->setValue($serviceLocator, true);
$config = array('di' => array(), 'translator' => array('locale' => 'en_US'));
$serviceLocator->setService('Config', $config);
//#5959
//get any plugins with AbstractPluginManagerFactory
$routePluginManagerFactory = new RoutePluginManagerFactory();
$routePluginManager = $routePluginManagerFactory->createService($serviceLocator);
$translator = $this->factory->createService($serviceLocator);
$this->assertInstanceOf('Zend\\Mvc\\I18n\\Translator', $translator);
$this->assertInstanceOf('Zend\\I18n\\Translator\\Translator', $translator->getTranslator());
}
示例10: init
public static function init()
{
// Define application environment (production|staging|testing|development)
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APP_ENV') ? getenv('APP_ENV') : 'testing');
// Load the user-defined test configuration file, if it exists; otherwise, load
if (is_readable(__DIR__ . '/TestConfig.php')) {
$testConfig = (include __DIR__ . '/TestConfig.php');
} else {
$testConfig = (include __DIR__ . '/TestConfig.php.dist');
}
$zf2ModulePaths = array();
if (isset($testConfig['module_listener_options']['module_paths'])) {
$modulePaths = $testConfig['module_listener_options']['module_paths'];
foreach ($modulePaths as $modulePath) {
if ($path = static::findParentPath($modulePath)) {
$zf2ModulePaths[] = $path;
}
}
}
$zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
$zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
static::initAutoloader();
// use ModuleManager to load this module and it's dependencies
$baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
$config = ArrayUtils::merge($baseConfig, $testConfig);
$serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();
static::$application = $serviceManager->get('Application');
}
示例11: testAskingTwiceTheSameQueueReturnsTheSameInstance
public function testAskingTwiceTheSameQueueReturnsTheSameInstance()
{
$queuePluginManager = $this->serviceManager->get('SlmQueue\\Queue\\QueuePluginManager');
$firstInstance = $queuePluginManager->get('basic-queue');
$secondInstance = $queuePluginManager->get('basic-queue');
$this->assertSame($firstInstance, $secondInstance);
}
示例12: create
/**
* @param ServiceLocatorInterface $serviceLocator
* @return FormInterface
*/
public function create()
{
$formElementManager = $this->serviceManager->get('FormElementManager');
$form = new Form();
$form->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Previous'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Next'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Valid'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Cancel'));
return $form;
}
示例13: indexAction
public function indexAction()
{
$requestUri = $this->getEvent()->getRouteMatch()->getParam('asset');
$response = $this->serviceLocator->get('AssetsManager')->dispatch($requestUri);
$this->getEvent()->setResponse($response);
return $response;
}
示例14: setUp
protected function setUp()
{
$this->serviceManager = Bootstrap::getServiceManager();
$this->fileSystem = vfsStream::setup('public', null, array('img' => array('test.jpg' => file_get_contents(__DIR__ . '/../../_files/test.jpg')), 'processed' => array()));
$this->imagine = $this->serviceManager->get('TckImageResizerImagine');
$this->imageProcessing = new ImageProcessing($this->imagine);
}
示例15: setUp
/**
* {@inheritDoc}
*/
public function setUp()
{
$this->serviceManager = Bootstrap::getServiceManager();
$this->call = new Call();
$this->call->setId(1);
$this->call->setCall('This is the call');
$program = new Program();
$program->setProgram('This is the program');
$this->call->setProgram($program);
$this->authorizeService = $this->serviceManager->get('BjyAuthorize\\Service\\Authorize');
if (!$this->authorizeService->getAcl()->hasResource($this->call)) {
$this->authorizeService->getAcl()->addResource($this->call);
$this->authorizeService->getAcl()->allow([], $this->call, []);
}
/**
* Add the resource on the fly
*/
if (!$this->authorizeService->getAcl()->hasResource(new Call())) {
$this->authorizeService->getAcl()->addResource(new Call());
}
$this->authorizeService->getAcl()->allow([], new Call(), []);
$this->callLink = $this->serviceManager->get('viewhelpermanager')->get('calllink');
/**
* Bootstrap the application to have the other information available
*/
$application = $this->serviceManager->get('application');
$application->bootstrap();
}