本文整理汇总了PHP中Windwalker\DI\Container::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::getInstance方法的具体用法?PHP Container::getInstance怎么用?PHP Container::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windwalker\DI\Container
的用法示例。
在下文中一共展示了Container::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContainer
/**
* Get the DI container.
*
* @return Container
*
* @since 1.0
*
* @throws \UnexpectedValueException May be thrown if the container has not been set.
*/
public function getContainer()
{
if (!$this->container) {
$this->container = Container::getInstance($this->getName());
}
return $this->container;
}
示例2: render
/**
* Render the profiler log data, and echo it..
*
* @param string $namespace The JProfiler instance ID. Default is the core profiler "Application".
* @param boolean $asString Return as string.
*
* @return string
*/
public static function render($namespace = 'Windwalker', $asString = false)
{
$app = Container::getInstance()->get('app');
if ($namespace == 'core' || !$namespace) {
$namespace = 'Application';
}
$buffer = 'No Profiler data.';
if (isset(self::$profiler[$namespace])) {
$_PROFILER = self::$profiler[$namespace];
$buffer = $_PROFILER->getBuffer();
$buffer = implode("\n<br />\n", $buffer);
} else {
$buffer = $app->getUserState('windwalker.system.profiler.' . $namespace);
$buffer = $buffer ? implode("\n<br />\n", $buffer) : '';
}
$buffer = $buffer ? $buffer : 'No Profiler data.';
// Get last page logs
$state_buffer = \JArrayHelper::getValue(self::$stateBuffer, $namespace);
if ($state_buffer) {
$state_buffer = implode("\n<br />\n", $state_buffer);
$buffer = $state_buffer . "\n<br />---------<br />\n" . $buffer;
}
// Render
$buffer = "<pre><h3>WindWalker Debug [namespace: {$namespace}]: </h3>" . $buffer . '</pre>';
$app->setUserState('windwalker.system.profiler.' . $namespace, '');
if ($asString) {
return $buffer;
}
echo $buffer;
return '';
}
示例3: refreshIncludePaths
/**
* Refresh the list of include paths
*
* @return void
*/
protected function refreshIncludePaths()
{
$app = Container::getInstance()->get('app');
// Reset includePaths
$this->includePaths = array();
// (1 - lower priority) Frontend base layouts
$this->addIncludePaths(JPATH_ROOT . '/layouts');
// (2) Windwalker layouts.
$this->addIncludePaths(WINDWALKER . '/resource/layouts');
// (3) Standard Joomla! template override
$this->addIncludePaths(JPATH_THEMES . '/' . $app->getTemplate() . '/html/layouts');
// Component layouts & overrides if exist
$component = $this->options->get('component', null);
if (!empty($component)) {
// (4) Component path
if ($this->options->get('client') == 0) {
$this->addIncludePaths(JPATH_SITE . '/components/' . $component . '/layouts');
} else {
$this->addIncludePaths(JPATH_ADMINISTRATOR . '/components/' . $component . '/layouts');
}
// (5) Component template overrides path
$this->addIncludePath(JPATH_THEMES . '/' . $app->getTemplate() . '/html/layouts/' . $component);
}
// (6 - highest priority) Received a custom high priority path ?
if (!is_null($this->basePath)) {
$this->addIncludePath(rtrim($this->basePath, DIRECTORY_SEPARATOR));
}
}
示例4: setup
/**
* Method to attach a JForm object to the field.
* Catch upload files when form setup.
*
* @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
parent::setup($element, $value, $group);
$container = \Windwalker\DI\Container::getInstance();
$input = $container->get('input');
$delete = isset($_REQUEST['jform']['profile'][$this->element['name'] . '_delete']) ? $_REQUEST['jform']['profile'][$this->element['name'] . '_delete'] : 0;
if ($delete == 1) {
$this->value = '';
} else {
// Upload Image
// ===============================================
if (isset($_FILES['jform']['name']['profile'])) {
foreach ($_FILES['jform']['name']['profile'] as $key => $var) {
if (!$var) {
continue;
}
// Get Field Attr
$width = $this->element['save_width'] ? $this->element['save_width'] : 800;
$height = $this->element['save_height'] ? $this->element['save_height'] : 800;
// Build File name
$src = $_FILES['jform']['tmp_name']['profile'][$key];
$var = explode('.', $var);
$date = DateHelper::getDate();
$name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var);
$url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name;
// A Event for extend.
$container->get('event.dispatcher')->trigger('onCCKEngineUploadImage', array(&$url, &$this, &$this->element));
$dest = JPATH_ROOT . '/' . $url;
// Upload First
JFile::upload($src, $dest);
// Resize image
$img = new JImage();
$img->loadFile(JPATH_ROOT . '/' . $url);
$img = $img->resize($width, $height);
switch (array_pop($var)) {
case 'gif':
$type = IMAGETYPE_GIF;
break;
case 'png':
$type = IMAGETYPE_PNG;
break;
default:
$type = IMAGETYPE_JPEG;
break;
}
// Save
$img->toFile($dest, $type, array('quality' => 85));
// Set in Value
$this->value = $url;
// Clean cache
$thumb = $this->getThumbPath();
if (is_file(JPATH_ROOT . '/' . $thumb)) {
\JFile::delete(JPATH_ROOT . '/' . $thumb);
}
}
}
}
return true;
}
示例5: quickadd
/**
* Add an quick add button & modal
*
* @return string The quickadd button.
*/
public function quickadd()
{
// Prepare Element
$readonly = $this->getElement('readonly', false);
$disabled = $this->getElement('disabled', false);
if ($readonly || $disabled) {
return '';
}
$container = Container::getInstance();
$input = $container->get('input');
$quickadd = $this->getElement('quickadd', false);
$table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
$key_field = $this->getElement('key_field', 'id');
$value_field = $this->getElement('value_field', 'title');
$formpath = WINDWALKER_SOURCE . "/Form/Forms/quickadd/category.xml";
$quickadd_handler = $this->getElement('quickadd_handler', $input->get('option'));
$title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
$qid = $this->id . '_quickadd';
if (!$quickadd) {
return '';
}
// Prepare Script & Styles
/** @var Windwalker\Helper\AssetHelper $asset */
$asset = Container::getInstance($quickadd_handler)->get('helper.asset');
$asset->addJs('js/quickadd.js');
// Set AKQuickAddOption
$config['task'] = $this->view_item . '.ajax.legacyquickadd';
$config['quickadd_handler'] = $quickadd_handler;
$config['cat_extension'] = (string) $this->element['extension'];
$config['extension'] = 'com_' . $this->component;
$config['component'] = $this->component;
$config['table'] = $table_name;
$config['model_name'] = 'category';
$config['key_field'] = $key_field;
$config['value_field'] = $value_field;
$config['joomla3'] = JVERSION >= 3;
$config = HtmlHelper::getJSObject($config);
$script = <<<QA
window.addEvent('domready', function(){
var AKQuickAddOption = {$config} ;
AKQuickAdd.init('{$qid}', AKQuickAddOption);
});
QA;
$asset->internalJS($script);
// Load Language & Form
LanguageHelper::loadLanguage('com_' . $this->component, null);
$formpath = str_replace(JPATH_ROOT, '', $formpath);
$content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
// Prepare HTML
$html = '';
$button_title = $title;
$modal_title = $button_title;
$button_class = 'btn btn-small btn-success delicious green light fltlft quickadd_button';
$footer = "<button class=\"btn delicious\" type=\"button\" onclick=\"\$\$('#{$qid} input', '#{$qid} select').set('value', '');AKQuickAdd.closeModal('{$qid}');\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
$footer .= "<button class=\"btn btn-primary delicious blue\" type=\"submit\" onclick=\"AKQuickAdd.submit('{$qid}', event);\">" . JText::_('JSUBMIT') . "</button>";
$html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
$html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
return $html;
}
示例6: getDate
/**
* Return the {@link JDate} object
*
* @param mixed $time The initial time for the JDate object
* @param mixed $tzOffset The timezone offset.
*
* @return \JDate object
*/
public static function getDate($time = 'now', $tzOffset = null)
{
if (!$tzOffset) {
$config = Container::getInstance()->get('joomla.config');
$tzOffset = $config->get('offset');
}
return \JFactory::getDate($time, $tzOffset);
}
示例7: restoreApplication
/**
* Restore original Application instance
*
* @return void
*/
public static function restoreApplication()
{
$container = Container::getInstance();
$className = get_class(static::$originalApplication);
$container->alias('app', $className);
$container->share($className, static::$originalApplication);
\JFactory::$application = static::$originalApplication;
}
示例8: publishingPeriod
/**
* Get a query string to filter the publishing items now.
*
* Will return: '( publish_up < 'xxxx-xx-xx' OR publish_up = '0000-00-00' )
* AND ( publish_down > 'xxxx-xx-xx' OR publish_down = '0000-00-00' )'
*
* @param string $prefix Prefix to columns name, eg: 'a.' will use `a`.`publish_up`.
*
* @return string Query string.
*/
public static function publishingPeriod($prefix = '')
{
$db = Container::getInstance()->get('db');
$nowDate = $date = DateHelper::getDate()->toSQL();
$nullDate = $db->getNullDate();
$date_where = " ( {$prefix}publish_up < '{$nowDate}' OR {$prefix}publish_up = '{$nullDate}') AND " . " ( {$prefix}publish_down > '{$nowDate}' OR {$prefix}publish_down = '{$nullDate}') ";
return $date_where;
}
示例9: getInput
/**
* Method to get the user field input markup.
*
* @return string The field input markup.
*/
protected function getInput()
{
$html = array();
$groups = $this->getGroups();
$excluded = $this->getExcluded();
$link = 'index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id . (isset($groups) ? '&groups=' . base64_encode(json_encode($groups)) : '') . (isset($excluded) ? '&excluded=' . base64_encode(json_encode($excluded)) : '');
// Initialize some field attributes.
$attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
// Initialize JavaScript field attributes.
$onchange = (string) $this->element['onchange'];
// Load the modal behavior script.
WindwalkerScript::modal('.hasUserModal');
JQueryScript::ui(array('effect'));
// Build the script.
$js = <<<JS
function jSelectUser_{$this->id}(id, title) {
\tvar input = jQuery('#{$this->id}_id');
\tvar oldId = input.val();
\tif (oldId != id) {
\t\tinput.val(id);
\t\tjQuery('#{$this->id}_name').val(title).removeClass('invalid').delay(300).effect('highlight');
\t}
\t{$onchange};
\tWindwalker.Modal.hide();
};
JS;
// Add the script to the document head.
$asset = Container::getInstance()->get('helper.asset');
$asset->internalJS($js);
// Load the current username if available.
$table = JTable::getInstance('user');
if ($this->value) {
$table->load($this->value);
} elseif (strtoupper($this->value) == 'CURRENT') {
// 'CURRENT' is not a reasonable value to be placed in the html
$this->value = JFactory::getUser()->id;
$table->load($this->value);
} else {
$table->name = JText::_('JLIB_FORM_SELECT_USER');
}
// Create a dummy text field with the user name.
$html[] = '<div class="input-append">';
$html[] = ' <input type="text" id="' . $this->id . '_name" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"' . ' readonly' . $attr . ' />';
// Create the user select button.
if (!XmlHelper::getBool($this->element, 'readonly', false)) {
$html[] = ' <a class="btn btn-primary hasUserModal modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
$html[] = '<i class="icon-user"></i></a>';
}
$html[] = '</div>';
// Create the real field, hidden, that stored the user id.
$html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $this->value . '" />';
return implode("\n", $html);
}
示例10: __construct
/**
* Object constructor to set table and key fields. In most cases this will
* be overridden by child classes to explicitly set the table and key fields
* for a particular database table.
*
* @param string $table Name of the table to model.
* @param mixed $key Name of the primary key field in the table or array of field names that compose the primary key.
* @param \JDatabaseDriver $db JDatabaseDriver object.
*/
public function __construct($table, $key = 'id', $db = null)
{
$db = $db ?: Container::getInstance()->get('db');
parent::__construct($table, $key, $db);
// Prepare Relation handler
$this->_relation = new Relation($this, $this->getPrefix());
RelationObserver::createObserver($this);
$this->configure();
$this->_observers->update('onAfterConstruction', array());
}
示例11: executeSql
/**
* executeSql
*
* @param string $sql
*
* @return void
*/
protected function executeSql($sql)
{
$db = Container::getInstance()->get('db');
$queries = $db->splitSql($sql);
foreach ($queries as $query) {
if (!trim($query)) {
continue;
}
$db->setQuery($query)->execute();
}
}
示例12: __construct
/**
* constructor.
*
* @param Command $command
* @param Container $container
* @param IOInterface $io
*/
public function __construct(Command $command, Container $container = null, IOInterface $io = null)
{
$this->command = $command;
$container = $container ?: Container::getInstance();
$this->container = $container;
$container->registerServiceProvider(new GeneratorBundleProvider($command));
$io = $io ?: $container->get('io');
$io->setCommand($command);
parent::__construct($container, $io);
$container->registerServiceProvider(new OperatorProvider($command));
}
示例13: detach
/**
* Detach a listener.
*
* @param \JEvent|string|array $listener The listener name to detach.
* @param \JEventDispatcher $dispatcher The EventDispatcher.
*
* @return boolean True if the observer object was detached.
*/
protected static function detach($listener, $dispatcher = null)
{
$dispatcher = $dispatcher ?: Container::getInstance()->get('event.dispatcher');
if (is_string($listener) && class_exists($listener)) {
if (empty(static::$listener[$listener])) {
static::$listener[$listener] = $listener = new $listener($dispatcher);
} else {
$listener = static::$listener[$listener];
}
}
return $dispatcher->detach($listener);
}
示例14: init
/**
* init
*
* @param \JDocument $template JDcoument object.
* @param \JRegistry $params Template params.
*
* @return Template
*/
public function init(\JDocument $template, \JRegistry $params)
{
include_once static::windwalkerPath();
static::$template = $template;
static::$params = $params;
static::$asset = Container::getInstance('tpl_' . static::$name)->get('helper.asset');
// Reset AssetHelper
static::$asset->resetPaths();
static::$asset->setDoc($template);
static::registerStylesheet($template);
static::registerScript($template);
return $this;
}
示例15: testGetInstance
/**
* testGetInstance
*
* @covers \Windwalker\DI\Container::getInstance()
*/
public function testGetInstance()
{
$backup = Container::getInstance();
$stub = new StubContainer(Container::getInstance());
$this->assertInstanceOf('Joomla\\DI\\Container', $stub::getInstance());
$this->assertInstanceOf('Joomla\\DI\\Container', $stub::getInstance('foo'));
// Test parent
$this->assertSame(StubContainer::getInstance(), StubContainer::getInstance('stub')->getParent());
// Put backup instance back
$ref = new \ReflectionProperty('Windwalker\\DI\\Container', 'instance');
$ref->setAccessible(true);
$ref->setValue($backup);
}