本文整理汇总了PHP中JFactory::document方法的典型用法代码示例。如果您正苦于以下问题:PHP JFactory::document方法的具体用法?PHP JFactory::document怎么用?PHP JFactory::document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFactory
的用法示例。
在下文中一共展示了JFactory::document方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doExecute
/**
* Method to run the Web application routines.
*
* @return void
*/
protected function doExecute()
{
$this->loadDocument();
$document = $this->getDocument();
// Register the template to the config
$this->set('theme', 'template');
$this->set('themeParams', new JRegistry());
// Inject the document object into the factory
JFactory::$document = $document;
switch ($document->getType()) {
case 'html':
// Set metadata
$document->setTitle('Joomla! Guestbook');
break;
default:
break;
}
// Execute the task.
try {
$controller = $this->fetchController($this->input->getCmd('task', 'display'));
$contents = $controller->execute();
} catch (RuntimeException $e) {
echo $e->getMessage();
$this->close($e->getCode());
}
$document->setBuffer($contents, 'component');
}
示例2: testCalendar
/**
* Tests JHtml::calendar() method with and without 'readonly' attribute.
*/
public function testCalendar()
{
// Create a world for the test
jimport('joomla.session.session');
jimport('joomla.application.application');
jimport('joomla.document.document');
$cfg = new JObject();
JFactory::$session = $this->getMock('JSession', array('_start'));
JFactory::$application = $this->getMock('ApplicationMock');
JFactory::$config = $cfg;
JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic'));
$cfg->live_site = 'http://example.com';
$cfg->offset = 'Europe/Kiev';
$_SERVER['HTTP_USER_AGENT'] = 'Test Browser';
// two sets of test data
$test_data = array('date' => '2010-05-28 00:00:00', 'friendly_date' => 'Friday, 28 May 2010', 'name' => 'cal1_name', 'id' => 'cal1_id', 'format' => '%Y-%m-%d', 'attribs' => array());
$test_data_ro = array_merge($test_data, array('attribs' => array('readonly' => 'readonly')));
foreach (array($test_data, $test_data_ro) as $data) {
// Reset the document
JFactory::$document = JDocument::getInstance('html', array('unique_key' => serialize($data)));
$input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']);
$this->assertEquals((string) $xml->input['title'], $data['friendly_date'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`');
$this->assertEquals((string) $xml->input['name'], $data['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`');
$this->assertEquals((string) $xml->input['id'], $data['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`');
$head_data = JFactory::getDocument()->getHeadData();
if (!isset($data['attribs']['readonly']) || !$data['attribs']['readonly'] === 'readonly') {
$this->assertArrayHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded');
$this->assertArrayHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded');
}
}
}
示例3: register
/**
* Register the API server.
*
* @throws \Exception
* @return boolean
*/
public function register()
{
$uri = \JURI::getInstance();
if (!$this->isApi()) {
return false;
}
$app = \JFactory::getApplication();
$input = $app->input;
// Restore Joomla handler and using our Json handler.
JsonResponse::registerErrorHandler();
// Authentication
if (!$this->isUserOperation($uri) && $this->option['authorise']) {
if (!Authentication::authenticate($input->get('session_key'))) {
throw new \Exception(\JText::_('JERROR_ALERTNOAUTHOR'), 403);
}
}
// Set Format to JSON
$input->set('format', 'json');
// Store JDocumentJson to Factory
\JFactory::$document = \JDocument::getInstance('json');
$router = $app::getRouter();
// Attach a hook to Router
$router->attachParseRule(array($this, 'parseRule'));
return true;
}
示例4: dispatch
/**
* Dispatch the application
*
* @param string $component The component which is being rendered.
*
* @return void
*
* @since 3.2
*/
public function dispatch($component = null)
{
if ($component === null) {
$component = JAdministratorHelper::findOption();
}
// Load the document to the API
$this->loadDocument();
// Set up the params
$document = JFactory::getDocument();
// Register the document object with JFactory
JFactory::$document = $document;
switch ($document->getType()) {
case 'html':
$document->setMetaData('keywords', $this->get('MetaKeys'));
// Get the template
$template = $this->getTemplate(true);
// Store the template and its params to the config
$this->set('theme', $template->template);
$this->set('themeParams', $template->params);
break;
default:
break;
}
$document->setTitle($this->get('sitename') . ' - ' . JText::_('JADMINISTRATION'));
$document->setDescription($this->get('MetaDesc'));
$document->setGenerator('Joomla! - Open Source Content Management');
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
// Trigger the onAfterDispatch event.
JPluginHelper::importPlugin('system');
$this->triggerEvent('onAfterDispatch');
}
示例5: setUp
/**
* Sets up the fixture.
*
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp()
{
JFactory::$application = $this->getMockApplication();
JFactory::$document = $this->getMockDocument();
$this->_instance = new JDocumentRendererMessage(JFactory::getDocument());
parent::setUp();
}
示例6: setUp
/**
* Sets up the fixture.
*
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
$this->saveFactoryState();
JFactory::$application = $this->getMockCmsApp();
JFactory::$document = $this->getMockDocument();
JFactory::$session = $this->getMockSession();
$this->instance = new JDocumentRendererMessage(JFactory::getDocument());
}
示例7: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
$this->saveFactoryState();
JFactory::$application = $this->getMockApplication();
JFactory::$document = $this->getMockDocument();
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SCRIPT_NAME'] = '';
}
示例8: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
// Ensure the loaded states are reset
JHtmlJqueryInspector::resetLoaded();
$this->saveFactoryState();
JFactory::$application = $this->getMockApplication();
JFactory::$document = $this->getMockDocument();
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SCRIPT_NAME'] = '';
}
示例9: setUp
/**
* Setup for testing.
*
* @return void
*
* @since 11.3
*/
public function setUp()
{
parent::setUp();
$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
// Get a new JApplicationWebInspector instance.
$this->inspector = new JApplicationWebInspector();
// We are only coupled to Document and Language in JFactory.
$this->saveFactoryState();
JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
}
示例10: restoreFactoryState
/**
* Sets the Factory pointers
*
* @return void
*/
protected function restoreFactoryState()
{
\JFactory::$application = $this->savedFactoryState['application'];
\JFactory::$config = $this->savedFactoryState['config'];
\JFactory::$dates = $this->savedFactoryState['dates'];
\JFactory::$session = $this->savedFactoryState['session'];
\JFactory::$language = $this->savedFactoryState['language'];
\JFactory::$document = $this->savedFactoryState['document'];
\JFactory::$acl = $this->savedFactoryState['acl'];
\JFactory::$database = $this->savedFactoryState['database'];
\JFactory::$mailer = $this->savedFactoryState['mailer'];
}
示例11: setUp
/**
* Setup for testing.
*
* @return void
*
* @since 3.6
*/
public function setUp()
{
parent::setUp();
$this->saveFactoryState();
JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
JFactory::$session = $this->getMockSession();
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
$_SERVER['SCRIPT_NAME'] = '/index.php';
}
示例12: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
parent::setUp();
$this->saveFactoryState();
JFactory::$application = $this->getMockCmsApp();
JFactory::$config = $this->getMockConfig();
JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
JFactory::$session = $this->getMockSession();
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SCRIPT_NAME'] = '';
}
示例13: setUp
/**
* Prepares the environment before running a test.
*
* @return void
*
* @since 1.0
*/
protected function setUp()
{
parent::setUp();
$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
$_SERVER['SCRIPT_NAME'] = '/index.php';
// Get a new JApplicationWebInspector instance.
$this->_instance = new WebServiceApplicationWebInspector();
// We are only coupled to Document and Language in JFactory.
$this->saveFactoryState();
JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
}
示例14: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
// Ensure the loaded states are reset
JHtmlBehaviorInspector::resetLoaded();
parent::setUp();
$this->saveFactoryState();
JFactory::$application = $this->getMockCmsApp();
JFactory::$document = $this->getMockDocument();
JFactory::$session = $this->getMockSession();
// We generate a random template name so that we don't collide or hit anything
JFactory::$application->expects($this->any())->method('getTemplate')->willReturn('mytemplate' . mt_rand(1, 10000));
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SCRIPT_NAME'] = '';
}
示例15: testCalendar
/**
* Tests JHtml::calendar() method with and without 'readonly' attribute.
*/
public function testCalendar()
{
// Create a world for the test
jimport('joomla.session.session');
jimport('joomla.application.application');
jimport('joomla.document.document');
$cfg = new JObject();
JFactory::$session = $this->getMock('JSession', array('_start'));
JFactory::$application = $this->getMock('ApplicationMock');
JFactory::$config = $cfg;
JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic'));
$cfg->live_site = 'http://example.com';
$cfg->offset = 'Europe/Kiev';
$_SERVER['HTTP_USER_AGENT'] = 'Test Browser';
// two sets of test data
$test_data = array('date' => '2010-05-28', 'friendly_date' => 'Friday, 28 May 2010', 'name' => 'cal1_name', 'id' => 'cal1_id', 'format' => '%Y-%m-%d', 'attribs' => array());
$test_data_ro = array_merge($test_data, array('attribs' => array('readonly' => 'readonly')));
foreach (array($test_data, $test_data_ro) as $data) {
// Reset the document
JFactory::$document = JDocument::getInstance('html', array('unique_key' => serialize($data)));
$input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']);
$this->assertThat(strlen($input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The calendar method should return something without error.');
$xml = new simpleXMLElement('<calendar>' . $input . '</calendar>');
$this->assertEquals((string) $xml->input['type'], 'text', 'Line:' . __LINE__ . ' The calendar input should have `type == "text"`');
$this->assertEquals((string) $xml->input['title'], $data['friendly_date'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`');
$this->assertEquals((string) $xml->input['name'], $data['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`');
$this->assertEquals((string) $xml->input['id'], $data['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`');
$this->assertEquals((string) $xml->input['value'], $data['date'], 'Line:' . __LINE__ . ' The calendar input should have `value == "' . $data['date'] . '"`');
$head_data = JFactory::getDocument()->getHeadData();
if (isset($data['attribs']['readonly']) && $data['attribs']['readonly'] === 'readonly') {
$this->assertEquals((string) $xml->input['readonly'], $data['attribs']['readonly'], 'Line:' . __LINE__ . ' The readonly calendar input should have `readonly == "' . $data['attribs']['readonly'] . '"`');
$this->assertFalse(isset($xml->img), 'Line:' . __LINE__ . ' The readonly calendar input shouldn\'t have a calendar image');
$this->assertArrayNotHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" shouldn\'t be loaded');
$this->assertArrayNotHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" shouldn\'t be loaded');
$this->assertArrayNotHasKey('text/javascript', $head_data['script'], 'Line:' . __LINE__ . ' Inline JS for the calendar shouldn\'t be loaded');
} else {
$this->assertFalse(isset($xml->input['readonly']), 'Line:' . __LINE__ . ' The calendar input shouldn\'t have readonly attribute');
$this->assertTrue(isset($xml->img), 'Line:' . __LINE__ . ' The calendar input should have a calendar image');
$this->assertEquals((string) $xml->img['id'], $data['id'] . '_img', 'Line:' . __LINE__ . ' The calendar image should have `id == "' . $data['id'] . '_img' . '"`');
$this->assertEquals((string) $xml->img['class'], 'calendar', 'Line:' . __LINE__ . ' The calendar image should have `class == "calendar"`');
$this->assertFileExists(JPATH_ROOT . $xml->img['src'], 'Line:' . __LINE__ . ' The calendar image source should point to an existent file');
$this->assertArrayHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded');
$this->assertArrayHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded');
$this->assertContains('DHTML Date/Time Selector', $head_data['script']['text/javascript'], 'Line:' . __LINE__ . ' Inline JS for the calendar should be loaded');
}
}
}