當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::getService方法代碼示例

本文整理匯總了PHP中Library\Application::getService方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::getService方法的具體用法?PHP Application::getService怎麽用?PHP Application::getService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Library\Application的用法示例。


在下文中一共展示了Application::getService方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testRouter

 /**
  * Test route matches against various URIs
  */
 public function testRouter()
 {
     $router = \Library\Application::getService('HttpRouter');
     $request = new \Zend\Http\Request();
     $matchDefaultDefault = array('controller' => 'client', 'action' => 'index');
     $matchControllerDefault = array('controller' => 'controllername', 'action' => 'index');
     $matchControllerAction = array('controller' => 'controllername', 'action' => 'actionname');
     $request->setUri('/');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/controllername');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/controllername/');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname/');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname/invalid');
     $this->assertNull($router->match($request));
     $request->setUri('/console');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/console/');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername/');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname/');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname/invalid');
     $this->assertNull($router->match($request));
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:37,代碼來源:RouterTest.php

示例2: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     // GroupInfo initialization depends on Config table
     $config = \Library\Application::getService('Database\\Table\\Config');
     $config->setSchema();
     parent::setUpBeforeClass();
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:7,代碼來源:GroupInfoTest.php

示例3: testHelperInterface

 /**
  * Test if the helper is properly registered with the service manager
  */
 public function testHelperInterface()
 {
     // Test if the helper is registered with the application's service manager
     $this->assertTrue(\Library\Application::getService('ViewHelperManager')->has($this->_getHelperName()));
     // Get helper instance through service manager and test for required interface
     $this->assertInstanceOf('Zend\\View\\Helper\\HelperInterface', $this->_getHelper());
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:10,代碼來源:AbstractTest.php

示例4: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     // These tables must exist before the view can be created
     \Library\Application::getService('Database\\Table\\ClientsAndGroups')->setSchema();
     \Library\Application::getService('Database\\Table\\ClientSystemInfo')->setSchema();
     parent::setUpBeforeClass();
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:7,代碼來源:ClientsTest.php

示例5: testNoTranslatorForEnglishLocale

 public function testNoTranslatorForEnglishLocale()
 {
     // Preserve state
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     }
     // Repeat application initialization with english locale
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_UK';
     \Library\Application::init('Library', false);
     // Invoke translator with untranslatable string - must not trigger notice
     $translator = \Library\Application::getService('MvcTranslator')->getTranslator();
     $message = $translator->translate('this_string_is_not_translated');
     // Reset application state ASAP.
     if (isset($language)) {
         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $language;
     } else {
         unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
     }
     \Library\Application::init('Library', false);
     $this->assertEquals('this_string_is_not_translated', $message);
     // No translations should be loaded
     $reflectionObject = new \ReflectionObject($translator);
     $reflectionProperty = $reflectionObject->getProperty('files');
     $reflectionProperty->setAccessible(true);
     $this->assertSame(array(), $reflectionProperty->getValue($translator));
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:26,代碼來源:TranslatorTest.php

示例6: testFind

 /**
  * @dataProvider findProvider
  */
 public function testFind($criteria, $order, $direction, $clearBlacklist, $expectedOrder, $expectedResult)
 {
     if ($clearBlacklist) {
         \Library\Application::getService('Database\\Table\\DuplicateMacAddresses')->delete(true);
         \Library\Application::getService('Database\\Table\\DuplicateSerials')->delete(true);
         \Library\Application::getService('Database\\Table\\DuplicateAssetTags')->delete(true);
     }
     $ordercolumns = array('Id' => 'clients.id', 'Name' => 'clients.name', 'NetworkInterface.MacAddress' => 'networkinterface_macaddr');
     $sql = new \Zend\Db\Sql\Sql(\Library\Application::getService('Db'), 'clients');
     $select = $sql->select()->columns(array('id', 'name', 'lastcome', 'ssn', 'assettag'))->order(array($ordercolumns[$order] => $direction));
     $clientManager = $this->getMockBuilder('Model\\Client\\ClientManager')->disableOriginalConstructor()->getMock();
     $clientManager->method('getClients')->with(array('Id', 'Name', 'LastContactDate', 'Serial', 'AssetTag'), $order, $direction, null, null, null, null, false, false, false)->willReturn($select);
     $clients = $this->getMockBuilder('Database\\Table\\Clients')->disableOriginalConstructor()->setMethods(array('getSql', 'selectWith'))->getMock();
     $clients->method('getSql')->willReturn($sql);
     $clients->method('selectWith')->with($this->callback(function ($select) use($expectedOrder) {
         return $select->getRawState($select::ORDER) == $expectedOrder;
     }))->willReturnCallback(function ($select) use($sql) {
         // Build simple result set to bypass hydrator
         $resultSet = new \Zend\Db\ResultSet\ResultSet();
         $resultSet->initialize($sql->prepareStatementForSqlObject($select)->execute());
         return $resultSet;
     });
     $duplicates = $this->_getModel(array('Database\\Table\\Clients' => $clients, 'Model\\Client\\ClientManager' => $clientManager));
     $resultSet = $duplicates->find($criteria, $order, $direction);
     $this->assertInstanceOf('Zend\\Db\\ResultSet\\AbstractResultSet', $resultSet);
     $this->assertEquals($expectedResult, $resultSet->toArray());
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:30,代碼來源:DuplicatesManagerTest.php

示例7: testLoggerService

 /**
  * Test service
  */
 public function testLoggerService()
 {
     $logger = \Library\Application::getService('Library\\Logger');
     $this->assertInstanceOf('\\Zend\\Log\\Logger', $logger);
     // Log a message. The NULL writer should be attached so that no
     // exception should be thrown.
     $logger->debug('test');
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:11,代碼來源:LoggerServiceFactoryTest.php

示例8: getConnection

 public function getConnection()
 {
     if (!$this->_db) {
         $pdo = \Library\Application::getService('Db')->getDriver()->getConnection()->getResource();
         $this->_db = $this->createDefaultDBConnection($pdo, ':memory:');
     }
     return $this->_db;
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:8,代碼來源:AbstractTableTest.php

示例9: _createView

 /**
  * Create a new view renderer
  *
  * @return \Zend\View\Renderer\PhpRenderer
  */
 protected function _createView()
 {
     // Clone helper plugin manager to prevent state changes leaking into other tests
     $plugins = clone \Library\Application::getService('ViewHelperManager');
     $view = new \Zend\View\Renderer\PhpRenderer();
     $view->setHelperPluginManager($plugins);
     return $view;
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:13,代碼來源:AbstractFormTest.php

示例10: testService

 public function testService()
 {
     $serviceManager = \Library\Application::getService('serviceManager');
     // Service must not be shared so that a different result is returned
     // each time.
     $now1 = $serviceManager->get('Library\\Now');
     sleep(1);
     $now2 = $serviceManager->get('Library\\Now');
     $this->assertGreaterThan($now1->getTimestamp(), $now2->getTimestamp());
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:10,代碼來源:NowTest.php

示例11: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // Add columns to CustomFields table
     static::$_customFields = \Library\Application::getService('Database\\Nada')->getTable('accountinfo');
     static::$_customFields->addColumn('col_text', \Nada::DATATYPE_VARCHAR, 255);
     static::$_customFields->addColumn('col_clob', \Nada::DATATYPE_CLOB);
     static::$_customFields->addColumn('col_integer', \Nada::DATATYPE_INTEGER, 32);
     static::$_customFields->addColumn('col_float', \Nada::DATATYPE_FLOAT);
     static::$_customFields->addColumn('col_date', \Nada::DATATYPE_DATE);
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:11,代碼來源:ClientManagerTest.php

示例12: testDeleteItems

 public function testDeleteItems()
 {
     $model = $this->_getModel();
     $model->deleteItems(1);
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection());
     foreach (static::$_tables as $table) {
         if ($table == 'ClientsAndGroups' or $table == 'DuplicateMacAddresses' or $table == 'SoftwareDefinitions') {
             continue;
         }
         $table = \Library\Application::getService("Database\\Table\\{$table}")->table;
         $dataSet->addTable($table, "SELECT hardware_id FROM {$table}");
     }
     $this->assertDataSetsEqual($this->_loadDataSet('DeleteItems'), $dataSet);
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:14,代碼來源:ItemManagerTest.php

示例13: testFormElementHelperIntegration

    public function testFormElementHelperIntegration()
    {
        $element = new \Zend\Form\Element\Select('test');
        $element->setAttribute('type', 'select_untranslated')->setValueOptions(array('Yes<b>', 'No'));
        $expected = <<<EOT
<select name="test"><option value="0">Yes&lt;b&gt;</option>
<option value="1">No</option></select>
EOT;
        $plugins = clone \Library\Application::getService('ViewHelperManager');
        $view = new \Zend\View\Renderer\PhpRenderer();
        $view->setHelperPluginManager($plugins);
        $helper = $plugins->get('formElement');
        $helper->setView($view);
        $this->assertEquals($expected, $helper($element));
    }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:15,代碼來源:FormSelectUntranslatedTest.php

示例14: testInvokeWithConsoleForm

 public function testInvokeWithConsoleForm()
 {
     $plugin = $this->_getPlugin(false);
     // Set up \Console\Form\Form using default renderer
     $form = $this->getMock('Console\\Form\\Form');
     $form->expects($this->once())->method('render')->will($this->returnValue('\\Console\\Form\\Form default renderer'));
     // Evaluate plugin return value
     $viewModel = $plugin($form);
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $viewModel);
     $this->assertEquals('plugin/PrintForm.php', $viewModel->getTemplate());
     $this->assertEquals($form, $viewModel->form);
     // Invoke template and test output
     $renderer = \Library\Application::getService('ViewRenderer');
     $output = $renderer->render($viewModel);
     $this->assertEquals('\\Console\\Form\\Form default renderer', $output);
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:16,代碼來源:PrintFormTest.php

示例15: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     static::$_nada = \Library\Application::getService('Database\\Nada');
     // Add columns to CustomFields table, matching config from fixture
     $customFields = \Library\Application::getService('Database\\Table\\CustomFields');
     $customFields->setSchema();
     $fields = static::$_nada->getTable('accountinfo');
     $fields->addColumn('fields_3', \Nada::DATATYPE_VARCHAR, 255);
     $fields->addColumn('fields_4', \Nada::DATATYPE_INTEGER, 32);
     $fields->addColumn('fields_5', \Nada::DATATYPE_FLOAT);
     $fields->addColumn('fields_6', \Nada::DATATYPE_CLOB);
     $fields->addColumn('fields_7', \Nada::DATATYPE_DATE);
     $fields->addColumn('fields_8', \Nada::DATATYPE_VARCHAR, 255);
     $fields->addColumn('fields_9', \Nada::DATATYPE_VARCHAR, 255);
 }
開發者ID:patrickpreuss,項目名稱:Braintacle,代碼行數:16,代碼來源:CustomFieldConfigTest.php


注:本文中的Library\Application::getService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。