simplified logging of data
This commit is contained in:
parent
7df8138ba7
commit
752445118f
7 changed files with 3 additions and 281 deletions
|
@ -48,18 +48,9 @@ class DataController extends Controller {
|
|||
|
||||
/**
|
||||
* Log new readings with logger interfaces
|
||||
*
|
||||
* @todo authentification/indentification
|
||||
* @todo reimplement
|
||||
*/
|
||||
public function add() {
|
||||
$class = 'Volkszaehler\Logger\\' . ucfirst($this->view->request->getParameter('logger')) . 'Logger';
|
||||
if (!(Util\ClassLoader::classExists($class)) || !is_subclass_of($class, '\Volkszaehler\Logger\Logger')) {
|
||||
throw new \Exception('Unkown logger: ' . $class);
|
||||
}
|
||||
$logger = new $class($this->view->request, $this->em);
|
||||
|
||||
$logger->log();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
||||
* @package default
|
||||
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Volkszaehler\Logger;
|
||||
|
||||
/**
|
||||
* Logger for the Flukso.net API
|
||||
*
|
||||
* @package default
|
||||
* @link http://www.flukso.net
|
||||
* @link http://github.com/icarus75/flukso
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @todo to be implemented
|
||||
*/
|
||||
class FluksoLogger extends Logger {
|
||||
/**
|
||||
* @return array of Model\Data
|
||||
*/
|
||||
public function getData();
|
||||
|
||||
public function getVersion();
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
||||
* @package default
|
||||
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Volkszaehler\Logger;
|
||||
|
||||
use Volkszaehler\View\HTTP;
|
||||
use Doctrine\ORM;
|
||||
use Volkszaehler\Model;
|
||||
|
||||
/**
|
||||
* Interface for parsing diffrent logging APIs (google, flukso etc..)
|
||||
*
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @package default
|
||||
* @todo to be implemented
|
||||
*/
|
||||
interface LoggerInterface {
|
||||
public function __construct(HTTP\Request $request, ORM\EntityManager $em);
|
||||
|
||||
/**
|
||||
* @return array of Model\Data
|
||||
*/
|
||||
public function getData();
|
||||
|
||||
public function getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @package default
|
||||
* @todo to be implemented
|
||||
*/
|
||||
abstract class Logger implements LoggerInterface {
|
||||
protected $request;
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTTP\Request $request
|
||||
* @param ORM\EntityManager $em
|
||||
*/
|
||||
public function __construct(HTTP\Request $request, ORM\EntityManager $em) {
|
||||
$this->request = $request;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function log() {
|
||||
$data = $this->getData();
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data = array($data);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
||||
* @package default
|
||||
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Volkszaehler\Logger;
|
||||
|
||||
use Volkszaehler\Model;
|
||||
use Doctrine\ORM;
|
||||
|
||||
/**
|
||||
* Logger for the the original volkszaehler.org prototype based on ethersex's watchasync
|
||||
*
|
||||
* @package default
|
||||
* @link http://github.com/ethersex/ethersex/blob/master/services/watchasync
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @todo to be implemented
|
||||
*/
|
||||
class PrototypeLogger extends Logger {
|
||||
/**
|
||||
* @return array of Model\Data
|
||||
*/
|
||||
public function getData() {
|
||||
$uuid = $this->request->getParameter('uuid');
|
||||
$port = $this->request->getParameter('port');
|
||||
|
||||
$channel = $this->em->getRepository('Volkszaehler\Model\Channel')->findOneBy(array(
|
||||
'description' => $uuid,
|
||||
'name' => $port
|
||||
));
|
||||
|
||||
if ($channel) {
|
||||
if (!($time = $this->request->getParameter('time'))) {
|
||||
$time = (int) (microtime(TRUE) * 1000);
|
||||
}
|
||||
return new Model\Data($channel, 1, $time);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the prototyp protocol doesn't have a version
|
||||
*/
|
||||
public function getVersion() {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Just some documentation
|
||||
*
|
||||
* /httplog/httplog.php?port=<port>&uuid=<uuid>&time=<unixtimestamp>
|
||||
*
|
||||
* <port> = <prefix:PC><no#>
|
||||
* <unixstimestamp> = timestamp in ms since 1970
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package default
|
||||
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
||||
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Volkszaehler\Logger;
|
||||
|
||||
use Volkszaehler\Model;
|
||||
|
||||
use Doctrine\ORM;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @package default
|
||||
*
|
||||
*/
|
||||
class VzLogger extends Logger {
|
||||
/**
|
||||
* @return array of Model\Data
|
||||
*/
|
||||
public function getData() {
|
||||
$ucid = $this->view->request->getParameter('ucid');
|
||||
$channel = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findOneBy(array('uuid' => $ucid));
|
||||
|
||||
$value = (float) $this->view->request->getParameter('value');
|
||||
$ts = (int) $this->view->request->getParameter('timestamp');
|
||||
if ($ts == 0) {
|
||||
$ts = microtime(TRUE) * 1000;
|
||||
}
|
||||
|
||||
$data = new Model\Data($channel, $value, $ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the version
|
||||
*/
|
||||
public function getVersion() {
|
||||
return $this->request->getParameter('version');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -65,7 +65,7 @@ abstract class Entity {
|
|||
|
||||
/**
|
||||
* @OneToMany(targetEntity="Property", mappedBy="entity", cascade={"remove", "persist"})
|
||||
* @OrderBy({"`key`" = "ASC"})
|
||||
* @OrderBy({"key" = "ASC"})
|
||||
*/
|
||||
protected $properties = NULL;
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class Property {
|
|||
*/
|
||||
public function checkRemove() {
|
||||
if (in_array($this->key, $this->entity->getDefinition()->getRequiredProperties())) {
|
||||
throw new \Exception('"' . $this->key . '" is a required property for the "' . $this->entity->getType() . '" entity');
|
||||
throw new \Exception($this->key . ' is a required property for the entity: ' . $this->entity->getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class Property {
|
|||
*/
|
||||
public function checkPersist() {
|
||||
if (!in_array($this->key, $this->entity->getDefinition()->getValidProperties())) {
|
||||
throw new \Exception('"' . $this->key . '" is not a valid property for the "' . $this->entity->getType() . '" entity');
|
||||
throw new \Exception($this->key . ' is not a valid property for the entity: ' . $this->entity->getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue