MonitoringBackend: Enforce that views and queries are of a particular naming scheme

I'm adding this mainly to not to break support with modules which are
utilizing our queries.
This commit is contained in:
Johannes Meyer 2015-06-12 14:46:46 +02:00
parent 4996f569fe
commit b6a7b43dd0

View File

@ -263,21 +263,21 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
/** /**
* View name to class name resolution * View name to class name resolution
* *
* @param string $viewName * @param string $view
* *
* @return string * @return string
* @throws ProgrammingError When the view does not exist *
* @throws ProgrammingError In case the view does not exist
*/ */
protected function buildViewClassName($view) protected function buildViewClassName($view)
{ {
$class = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($view); $class = ucfirst(strtolower($view));
if (!class_exists($class)) { $classPath = '\\Icinga\\Module\\Monitoring\\DataView\\' . $class;
throw new ProgrammingError( if (! class_exists($classPath)) {
'DataView %s does not exist', throw new ProgrammingError('DataView %s does not exist', $class);
ucfirst($view)
);
} }
return $class;
return $classPath;
} }
/** /**
@ -287,6 +287,8 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
* @param array $columns Optional column list * @param array $columns Optional column list
* *
* @return Icinga\Data\QueryInterface * @return Icinga\Data\QueryInterface
*
* @throws ProgrammingError When the query does not exist for this backend
*/ */
public function query($name, $columns = null) public function query($name, $columns = null)
{ {
@ -318,16 +320,15 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
/** /**
* Query name to class name resolution * Query name to class name resolution
* *
* @param string $query * @param string $query
* *
* @return string * @return string
* @throws ProgrammingError When the query does not exist for this backend
*/ */
protected function buildQueryClassName($query) protected function buildQueryClassName($query)
{ {
$parts = preg_split('~\\\~', get_class($this)); $parts = preg_split('~\\\~', get_class($this));
array_pop($parts); array_pop($parts);
array_push($parts, 'Query', ucfirst($query) . 'Query'); array_push($parts, 'Query', ucfirst(strtolower($query)) . 'Query');
return implode('\\', $parts); return implode('\\', $parts);
} }
} }