本文整理汇总了PHP中Library\Application类的典型用法代码示例。如果您正苦于以下问题:PHP Application类的具体用法?PHP Application怎么用?PHP Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: EndLog
public static function EndLog(\Library\Application $app, $type)
{
$logs = Logger::GetLogs($app->user());
$log = $logs[$type][$app->HttpRequest()->requestID()];
$log->setLog_end(Logger::GetTime());
$log->setLog_execution_time(($log->log_end - $log->log_start()) * 1000);
$log->setLog_start(gmdate("Y-m-d H:i:s", $log->log_start()));
$log->setLog_end(gmdate("Y-m-d H:i:s", $log->log_end()));
Logger::AddLogToDatabase($app, $log);
Logger::StoreLogs($app->user(), $logs);
}
示例2: 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));
}
示例3: testRouter
/**
* Test route matches against various URIs
*/
public function testRouter()
{
$application = \Library\Application::init('Console', true);
$router = $application->getServiceManager()->get('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));
}
示例4: setUpBeforeClass
public static function setUpBeforeClass()
{
// This table must exist before the view can be created
\Library\Application::getService('Database\\Table\\ClientsAndGroups')->setSchema();
\Library\Application::getService('Database\\Table\\WindowsProductKeys')->setSchema();
parent::setUpBeforeClass();
}
示例5: testMessageTranslated
public function testMessageTranslated()
{
$validator = new LogLevel();
$validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator'));
$validator->isValid('Error');
$this->assertEquals(array(LogLevel::LOG_LEVEL => "'Error' ist kein gültiger Loglevel"), $validator->getMessages());
}
示例6: setUpBeforeClass
public static function setUpBeforeClass()
{
// GroupInfo initialization depends on Config table
$config = \Library\Application::getService('Database\\Table\\Config');
$config->setSchema();
parent::setUpBeforeClass();
}
示例7: _createView
/**
* Create a new view renderer
*
* @return \Zend\View\Renderer\PhpRenderer
*/
protected function _createView()
{
$application = \Library\Application::init('Console', true);
$view = new \Zend\View\Renderer\PhpRenderer();
$view->setHelperPluginManager($application->getServiceManager()->get('ViewHelperManager'));
return $view;
}
示例8: 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());
}
示例9: 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());
}
示例10: setPackageData
/**
* Set attributes from given package
*
* Attributes are populated with values from the given package and
* hardcoded defaults.
*
* @param array $data Package data
*/
public function setPackageData($data)
{
$node = $this->createElement('DOWNLOAD');
$node->setAttribute('ID', $data['Id']);
$node->setAttribute('PRI', $data['Priority']);
$node->setAttribute('ACT', strtoupper($data['DeployAction']));
$node->setAttribute('DIGEST', $data['Hash']);
$node->setAttribute('PROTO', 'HTTP');
$node->setAttribute('FRAGS', $data['NumFragments']);
$node->setAttribute('DIGEST_ALGO', 'SHA1');
$node->setAttribute('DIGEST_ENCODE', 'Hexa');
$node->setAttribute('PATH', $data['DeployAction'] == 'store' ? $data['ActionParam'] : '');
$node->setAttribute('NAME', $data['DeployAction'] == 'launch' ? $data['ActionParam'] : '');
$node->setAttribute('COMMAND', $data['DeployAction'] == 'execute' ? $data['ActionParam'] : '');
$node->setAttribute('NOTIFY_USER', $data['Warn'] ? '1' : '0');
$node->setAttribute('NOTIFY_TEXT', $this->_escapeMessage($data['WarnMessage']));
$node->setAttribute('NOTIFY_COUNTDOWN', $data['WarnCountdown']);
$node->setAttribute('NOTIFY_CAN_ABORT', $data['WarnAllowAbort'] ? '1' : '0');
$node->setAttribute('NOTIFY_CAN_DELAY', $data['WarnAllowDelay'] ? '1' : '0');
$node->setAttribute('NEED_DONE_ACTION', $data['PostInstMessage'] ? '1' : '0');
$node->setAttribute('NEED_DONE_ACTION_TEXT', $this->_escapeMessage($data['PostInstMessage']));
$node->setAttribute('GARDEFOU', 'rien');
if ($this->hasChildNodes()) {
$this->replaceChild($node, $this->firstChild);
} else {
$this->appendChild($node);
}
if (!\Library\Application::isProduction()) {
$this->forceValid();
}
}
示例11: testMissingTranslationDoesNotTriggerNoticeWhenDisabled
/**
* @dataProvider missingTranslationProvider
*/
public function testMissingTranslationDoesNotTriggerNoticeWhenDisabled($locale)
{
\Locale::setDefault($locale);
$application = \Library\Application::init('Library', true, array('Library\\UserConfig' => array('debug' => array('report missing translations' => false))));
$translator = $application->getServiceManager()->get('MvcTranslator');
$this->assertEquals('this_string_is_not_translated', $translator->translate('this_string_is_not_translated'));
}
示例12: testMessageTranslated
public function testMessageTranslated()
{
$validator = new ProductKey();
$validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator'));
$validator->isValid('invalid');
$this->assertEquals(array(ProductKey::PRODUCT_KEY => "'invalid' ist kein gültiger Lizenzschlüssel"), $validator->getMessages());
}
示例13: getConnection
public function getConnection()
{
if (!$this->_db) {
$pdo = \Library\Application::getService('Db')->getDriver()->getConnection()->getResource();
$this->_db = $this->createDefaultDBConnection($pdo, ':memory:');
}
return $this->_db;
}
示例14: _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;
}
示例15: 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');
}