Skip to content
Browse files

Standardize the code

  • Loading branch information...
1 parent 2d35d2c commit 64fc2a0c9d660205bb9fe3d7271f5e00914d71ba @rande rande committed Apr 2, 2012
Showing with 185 additions and 12 deletions.
  1. +10 −0 .travis.yml
  2. +8 −0 Check/Check.php
  3. +27 −6 Check/CheckChain.php
  4. +7 −0 Check/CheckInterface.php
  5. +12 −1 Check/Runner.php
  6. +22 −1 Helper/PathHelper.php
  7. +21 −0 LICENSE
  8. +0 −2 LiipMonitorBundle.php
  9. +19 −2 Result/CheckResult.php
  10. +26 −0 composer.json
  11. +33 −0 phpunit.xml.dist
View
10 .travis.yml
@@ -0,0 +1,10 @@
+language: php
+php:
+ - 5.3
+ - 5.4
+
+env:
+ - SYMFONY_VERSION=v2.0.12
+ - SYMFONY_VERSION=origin/2.0
+
+before_script: php Tests/tests/vendors.php
View
8 Check/Check.php
@@ -6,11 +6,19 @@
abstract class Check implements CheckInterface
{
+ /**
+ * {@inheritdoc}
+ */
public function getName()
{
return get_called_class();
}
+ /**
+ * @param $message
+ * @param $status
+ * @return \Liip\MonitorBundle\Result\CheckResult
+ */
protected function buildResult($message, $status)
{
return new CheckResult($this->getName(), $message, $status);
View
33 Check/CheckChain.php
@@ -4,30 +4,51 @@
use Liip\MonitorBundle\Check\CheckInterface;
-class CheckChain
+final class CheckChain
{
- protected $checks;
+ protected $checks = array();
- public function __construct()
+ /**
+ * @param array $checks
+ */
+ public function __construct(array $checks = array())
{
- $this->checks = array();
+ foreach ($checks as $serviceId => $check) {
+ $this->addCheck($serviceId, $check);
+ }
}
- public function addCheck($service_id, CheckInterface $check)
+ /**
+ * @param $serviceId
+ * @param CheckInterface $check
+ * @return void
+ */
+ public function addCheck($serviceId, CheckInterface $check)
{
- $this->checks[$service_id] = $check;
+ $this->checks[$serviceId] = $check;
}
+ /**
+ * @return array
+ */
public function getChecks()
{
return $this->checks;
}
+ /**
+ * @return array
+ */
public function getAvailableChecks()
{
return array_keys($this->checks);
}
+ /**
+ * @throws \InvalidArgumentException
+ * @param $id
+ * @return \Liip\MonitorBundle\Check\CheckInterface
+ */
public function getCheckById($id)
{
if (!isset($this->checks[$id])) {
View
7 Check/CheckInterface.php
@@ -4,6 +4,13 @@
interface CheckInterface
{
+ /**
+ * @return \Liip\MonitorBundle\Result\CheckResult
+ */
function check();
+
+ /**
+ * @return string
+ */
function getName();
}
View
13 Check/Runner.php
@@ -8,16 +8,27 @@ class Runner extends ContainerAware
{
protected $chain;
- public function __construct($chain)
+ /**
+ * @param $chain
+ */
+ public function __construct(CheckChain $chain)
{
$this->chain = $chain;
}
+ /**
+ * @param $checkId
+ * @return
+ */
public function runCheckById($checkId)
{
return $this->runCheck($this->chain->getCheckById($checkId));
}
+ /**
+ * @param $checkService
+ * @return
+ */
public function runCheck($checkService)
{
return $checkService->check();
View
23 Helper/PathHelper.php
@@ -2,23 +2,33 @@
namespace Liip\MonitorBundle\Helper;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+
class PathHelper
{
protected $assetsHelper;
protected $routerHelper;
- public function __construct($container)
+ /**
+ * @param \Symfony\Component\DependencyInjection\ContainerAwareInterface $container
+ */
+ public function __construct(ContainerAwareInterface $container)
{
$this->assetsHelper = $container->get('templating.helper.assets');
$this->routerHelper = $container->get('templating.helper.router');
}
+ /**
+ * @param $routes
+ * @return array
+ */
public function generateRoutes($routes)
{
$ret = array();
foreach ($routes as $route => $params) {
$ret[] = sprintf('api.%s = "%s";', $route, $this->routerHelper->generate($route, $params));
}
+
return $ret;
}
@@ -28,24 +38,35 @@ public function getRoutesJs($routes)
$script .= "var api = {};\n";
$script .= implode("\n", $this->generateRoutes($routes));
$script .= '</script>';
+
return $script;
}
+ /**
+ * @param $paths
+ * @return string
+ */
public function getScriptTags($paths)
{
$ret = '';
foreach ($paths as $path) {
$ret .= sprintf('<script type="text/javascript" charset="utf-8" src="%s"></script>%s', $this->assetsHelper->getUrl($path), "\n");
}
+
return $ret;
}
+ /**
+ * @param $paths
+ * @return string
+ */
public function getStyleTags($paths)
{
$ret = '';
foreach ($paths as $path) {
$ret .= sprintf('<link rel="stylesheet" href="%s" type="text/css">%s', $this->assetsHelper->getUrl($path), "\n");
}
+
return $ret;
}
}
View
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2012 alvaro.videla@liip.ch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
2 LiipMonitorBundle.php
@@ -10,8 +10,6 @@ class LiipMonitorBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
- parent::build($container);
-
$container->addCompilerPass(new HealthCheckTagCompilerPass());
}
}
View
21 Result/CheckResult.php
@@ -11,34 +11,51 @@ class CheckResult
protected $message;
protected $status;
+ /**
+ * @param $checkName
+ * @param $message
+ * @param $status
+ */
public function __construct($checkName, $message, $status)
{
$this->checkName = $checkName;
$this->message = $message;
$this->status = $status;
}
+ /**
+ * @return string
+ */
public function getCheckName()
{
return $this->checkName;
}
+ /**
+ * @return string
+ */
public function getMessage()
{
return $this->message;
}
+ /**
+ * @return integer
+ */
public function getStatus()
{
return $this->status;
}
+ /**
+ * @return array
+ */
public function toArray()
{
return array(
'checkName' => $this->checkName,
- 'message' => $this->message,
- 'status' => $this->status
+ 'message' => $this->message,
+ 'status' => $this->status
);
}
}
View
26 composer.json
@@ -0,0 +1,26 @@
+{
+ "name": "liip/monitor-bundle",
+ "type": "symfony-bundle",
+ "description": "Liip Monitor Bundle",
+ "keywords": ["liip", "Monitor"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Alvaro Videla",
+ "email": "alvaro.videla@liip.ch"
+ },
+ {
+ "name": "Thomas Rabaix",
+ "email": "thomas.rabaix@sonata-project.org",
+ "homepage": "http://sonata-project.org"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.2",
+ "symfony/framework-bundle": "2.0.*"
+ },
+ "autoload": {
+ "psr-0": { "Liip\\MonitorBundle": "" }
+ },
+ "target-dir": "Sonata/MonitorBundle"
+}
View
33 phpunit.xml.dist
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ verbose="true"
+ bootstrap="Tests/tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="MonitorBundle Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./Tests/</directory>
+ <directory>./DataFixtures/</directory>
+ <directory>./Resources/</directory>
+ <directory>./DependencyInjection/</directory>
+ <directory>./Twig/</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>

0 comments on commit 64fc2a0

Please sign in to comment.
Something went wrong with that request. Please try again.