本文整理汇总了PHP中Icinga\Data\Filter\Filter::fromQueryString方法的典型用法代码示例。如果您正苦于以下问题:PHP Filter::fromQueryString方法的具体用法?PHP Filter::fromQueryString怎么用?PHP Filter::fromQueryString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Icinga\Data\Filter\Filter
的用法示例。
在下文中一共展示了Filter::fromQueryString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterAction
public function filterAction()
{
$flat = array();
$filter = Filter::fromQueryString('vars.bpconfig=*');
Benchmark::measure('ready');
$objs = IcingaHost::loadAll($this->db());
Benchmark::measure('db done');
foreach ($objs as $host) {
$flat[$host->id] = (object) array();
foreach ($host->getProperties() as $k => $v) {
$flat[$host->id]->{$k} = $v;
}
}
Benchmark::measure('objects ready');
$vars = IcingaHostVar::loadAll($this->db());
Benchmark::measure('vars loaded');
foreach ($vars as $var) {
if (!array_key_exists($var->host_id, $flat)) {
continue;
}
// Templates?
$flat[$var->host_id]->{'vars.' . $var->varname} = $var->varvalue;
}
Benchmark::measure('vars done');
foreach ($flat as $host) {
if ($filter->matches($host)) {
echo $host->object_name . "\n";
}
}
return;
Benchmark::measure('all done');
}
示例2: filter
protected function filter()
{
if ($this->filter === null) {
$this->filter = Filter::fromQueryString($this->filter_expression);
}
return $this->filter;
}
示例3: getFilter
public function getFilter()
{
if ($this->filter === null) {
$this->filter = Filter::fromQueryString((string) $this->url()->getParams());
}
return $this->filter;
}
示例4: init
/**
* Fetch all downtimes matching the current filter and add tabs
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace('downtime_id', 'downtime_internal_id', (string) $this->params));
$query = $this->backend->select()->from('downtime', array('id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', 'scheduled_start' => 'downtime_scheduled_start', 'scheduled_end' => 'downtime_scheduled_end', 'end' => 'downtime_end', 'duration' => 'downtime_duration', 'is_flexible' => 'downtime_is_flexible', 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', 'host_state', 'service_state', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query);
$this->downtimes = $query;
$this->getTabs()->add('downtimes', array('icon' => 'plug', 'label' => $this->translate('Downtimes') . sprintf(' (%d)', $query->count()), 'title' => $this->translate('Display detailed information about multiple downtimes.'), 'url' => 'monitoring/downtimes/show'))->activate('downtimes');
}
示例5: init
/**
* Fetch all comments matching the current filter and add tabs
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace('comment_id', 'comment_internal_id', (string) $this->params));
$query = $this->backend->select()->from('comment', array('id' => 'comment_internal_id', 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', 'type' => 'comment_type', 'persistent' => 'comment_is_persistent', 'expiration' => 'comment_expiration', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query);
$this->comments = $query;
$this->getTabs()->add('comments', array('icon' => 'comment', 'label' => $this->translate('Comments') . sprintf(' (%d)', $query->count()), 'title' => $this->translate('Display detailed information about multiple comments.'), 'url' => 'monitoring/comments/show'))->activate('comments');
}
示例6: testAction
public function testAction()
{
$pdb = new PuppetDbApi('v4', 'pe2015.example.com');
// $filter = Filter::fromQueryString('type=Nagios_host&exported=true');
// echo FilterRenderer::forFilter($filter)->toJson();
$facts = $pdb->fetchFacts(Filter::fromQueryString('name=kernel|name=osfamily|name=partitions'));
// certname=pe2015.example.com
}
示例7: getFilterOrExitIfEmpty
/**
* Get the filter from URL parameters or exit immediately if the filter is empty
*
* @return Filter
*/
protected function getFilterOrExitIfEmpty()
{
$filter = Filter::fromQueryString((string) $this->params);
if ($filter->isEmpty()) {
$this->getResponse()->json()->setFailData(array('filter' => 'Filter is required and must not be empty'))->sendResponse();
}
return $filter;
}
示例8: init
public function init()
{
$serviceList = new ServiceList($this->backend);
$this->applyRestriction('monitoring/filter/objects', $serviceList);
$serviceList->addFilter(Filter::fromQueryString((string) $this->params->without(array('service_problem', 'service_handled', 'view'))));
$this->serviceList = $serviceList;
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
$this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u services'), count($this->serviceList)), 'label' => $this->translate('Services') . sprintf(' (%d)', count($this->serviceList)), 'url' => Url::fromRequest(), 'icon' => 'services'))->extend(new DashboardAction())->activate('show');
}
示例9: init
public function init()
{
$hostList = new HostList($this->backend);
$hostList->setFilter(Filter::fromQueryString((string) $this->params));
$this->applyRestriction('monitoring/filter/objects', $hostList);
$this->hostList = $hostList;
$this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'url' => Url::fromRequest(), 'icon' => 'host'))->extend(new DashboardAction())->activate('show');
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
}
示例10: applyRestriction
/**
* Apply a restriction on the given data view
*
* @param string $restriction The name of restriction
* @param Filterable $filterable The filterable to restrict
*
* @return Filterable The filterable
*/
protected static function applyRestriction($restriction, Filterable $filterable)
{
$restrictions = Filter::matchAny();
foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
$restrictions->addFilter(Filter::fromQueryString($filter));
}
$filterable->applyFilter($restrictions);
return $filterable;
}
示例11: init
public function init()
{
$hostList = new HostList($this->backend);
$this->applyRestriction('monitoring/filter/objects', $hostList);
$hostList->addFilter(Filter::fromQueryString((string) $this->params));
$this->hostList = $hostList;
$this->hostList->setColumns(array('host_acknowledged', 'host_active_checks_enabled', 'host_display_name', 'host_event_handler_enabled', 'host_flap_detection_enabled', 'host_handled', 'host_in_downtime', 'host_is_flapping', 'host_last_state_change', 'host_name', 'host_notifications_enabled', 'host_obsessing', 'host_passive_checks_enabled', 'host_problem', 'host_state', 'instance_name'));
$this->view->baseFilter = $this->hostList->getFilter();
$this->getTabs()->add('show', array('label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'url' => Url::fromRequest()))->extend(new DashboardAction())->extend(new MenuAction())->activate('show');
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
}
示例12: applyRestriction
/**
* Apply a restriction on the given data view
*
* @param string $restriction The name of restriction
* @param Filterable $view The filterable to restrict
*
* @return Filterable The filterable
*/
protected function applyRestriction($restriction, Filterable $view)
{
$restrictions = Filter::matchAny();
$restrictions->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', function ($c) {
return preg_match('/^_(?:host|service)_/', $c);
}));
foreach ($this->getRestrictions($restriction) as $filter) {
try {
$restrictions->addFilter(Filter::fromQueryString($filter));
} catch (QueryException $e) {
throw new ConfigurationError($this->translate('Cannot apply restriction %s using the filter %s. You can only use the following columns: %s'), $restriction, $filter, implode(', ', array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', '_(host|service)_<customvar-name>')), $e);
}
}
$view->applyFilter($restrictions);
return $view;
}
示例13: isValid
/**
* {@inheritdoc}
*/
public function isValid($formData)
{
if (!parent::isValid($formData)) {
return false;
}
if (($filterString = $this->getValue('filter')) !== null) {
$filter = Filter::matchAll();
$filter->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'instance_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', function ($c) {
return preg_match('/^_(?:host|service)_/', $c);
}));
try {
$filter->addFilter(Filter::fromQueryString($filterString));
} catch (QueryException $_) {
$this->getElement('filter')->addError(sprintf($this->translate('Invalid filter provided. You can only use the following columns: %s'), implode(', ', array('instance_name', 'host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', '_(host|service)_<customvar-name>'))));
return false;
}
}
return true;
}
示例14: init
/**
* Fetch all downtimes matching the current filter and add tabs
*
* @throws Zend_Controller_Action_Exception
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace('downtime_id', 'downtime_internal_id', (string) $this->params));
$query = $this->backend->select()->from('downtime', array('id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', 'scheduled_start' => 'downtime_scheduled_start', 'scheduled_end' => 'downtime_scheduled_end', 'end' => 'downtime_end', 'duration' => 'downtime_duration', 'is_flexible' => 'downtime_is_flexible', 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', 'host_state', 'service_state', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query);
$this->downtimes = $query->getQuery()->fetchAll();
if (false === $this->downtimes) {
throw new Zend_Controller_Action_Exception($this->translate('Downtime not found'));
}
$this->getTabs()->add('downtimes', array('title' => $this->translate('Display detailed information about multiple downtimes.'), 'icon' => 'plug', 'label' => $this->translate('Downtimes') . sprintf(' (%d)', count($this->downtimes)), 'url' => 'monitoring/downtimes/show'))->activate('downtimes');
foreach ($this->downtimes as $downtime) {
if (isset($downtime->service_description)) {
$downtime->isService = true;
} else {
$downtime->isService = false;
}
if ($downtime->isService) {
$downtime->stateText = Service::getStateText($downtime->service_state);
} else {
$downtime->stateText = Host::getStateText($downtime->host_state);
}
}
}
示例15: getRender
/**
* {@inheritdoc}
*/
public function getRender()
{
if ($this->render === null) {
$filter = $this->getFilter();
$this->render = $filter ? Filter::fromQueryString($filter)->matches($this->getObject()) : true;
}
return $this->render;
}