Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Upgraded to Typhoon ~0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Feb 7, 2013
1 parent 3c25a30 commit 70f15f9
Show file tree
Hide file tree
Showing 22 changed files with 2,534 additions and 3,321 deletions.
12 changes: 6 additions & 6 deletions lib-typhoon/Icecave/Collections/TypeCheck/AbstractValidator.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
namespace Icecave\Collections\TypeCheck;


abstract class AbstractValidator
{
public function __construct()
{
($this->reflector = (new \ReflectionObject($this)));
$this->reflector = new \ReflectionObject($this);
}

public function __call($name, array $arguments)
{
($validatorMethodName = \sprintf('validate%s', \ucfirst(\ltrim($name, '_'))));
if ((!$this->reflector->hasMethod($validatorMethodName)))
{
throw (new \BadMethodCallException(\sprintf('Call to undefined method %s::%s().', __CLASS__, $name)));
$validatorMethodName = \sprintf('validate%s', \ucfirst(\ltrim($name, '_')));
if (!$this->reflector->hasMethod($validatorMethodName)) {
throw new \BadMethodCallException(\sprintf('Call to undefined method %s::%s().', __CLASS__, $name));
}
return $this->reflector->getMethod($validatorMethodName)->invokeArgs($this, $arguments);
}

private $reflector;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace Icecave\Collections\TypeCheck;


class DummyValidator extends AbstractValidator
{
public function __call($name, array $arguments)
{
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
namespace Icecave\Collections\TypeCheck\Exception;


final class MissingArgumentException extends UnexpectedInputException
{
public function __construct($parameterName, $index, $expectedType, \Exception $previous = null)
{
($this->parameterName = $parameterName);
($this->index = $index);
($this->expectedType = $expectedType);
$this->parameterName = $parameterName;
$this->index = $index;
$this->expectedType = $expectedType;
parent::__construct(
\sprintf(
'Missing argument for parameter \'%s\' at index %d. Expected \'%s\'.',
Expand All @@ -19,18 +18,22 @@ public function __construct($parameterName, $index, $expectedType, \Exception $p
$previous
);
}

public function parameterName()
{
return $this->parameterName;
}

public function index()
{
return $this->index;
}

public function expectedType()
{
return $this->expectedType;
}

private $parameterName;
private $index;
private $expectedType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
<?php
namespace Icecave\Collections\TypeCheck\Exception;


final class UnexpectedArgumentException extends UnexpectedInputException
{
public function __construct($index, $value, \Exception $previous = null, \Icecave\Collections\TypeCheck\TypeInspector $typeInspector = null)
{
if ((null === $typeInspector))
{
($typeInspector = (new \Icecave\Collections\TypeCheck\TypeInspector()));
if (null === $typeInspector) {
$typeInspector = new \Icecave\Collections\TypeCheck\TypeInspector();
}
($this->index = $index);
($this->value = $value);
($this->typeInspector = $typeInspector);
($this->unexpectedType = $typeInspector->type($this->value));
$this->index = $index;
$this->value = $value;
$this->typeInspector = $typeInspector;
$this->unexpectedType = $typeInspector->type($this->value);
parent::__construct(\sprintf('Unexpected argument of type \'%s\' at index %d.', $this->unexpectedType, $index), $previous);
}

public function index()
{
return $this->index;
}

public function value()
{
return $this->value;
}

public function typeInspector()
{
return $this->typeInspector;
}

public function unexpectedType()
{
return $this->unexpectedType;
}

private $index;
private $value;
private $typeInspector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
namespace Icecave\Collections\TypeCheck\Exception;


final class UnexpectedArgumentValueException extends UnexpectedInputException
{
public function __construct($parameterName, $index, $value, $expectedType, \Exception $previous = null, \Icecave\Collections\TypeCheck\TypeInspector $typeInspector = null)
{
if ((null === $typeInspector))
{
($typeInspector = (new \Icecave\Collections\TypeCheck\TypeInspector()));
if (null === $typeInspector) {
$typeInspector = new \Icecave\Collections\TypeCheck\TypeInspector();
}
($this->parameterName = $parameterName);
($this->index = $index);
($this->value = $value);
($this->expectedType = $expectedType);
($this->typeInspector = $typeInspector);
($this->unexpectedType = $typeInspector->type($this->value));
$this->parameterName = $parameterName;
$this->index = $index;
$this->value = $value;
$this->expectedType = $expectedType;
$this->typeInspector = $typeInspector;
$this->unexpectedType = $typeInspector->type($this->value);
parent::__construct(
\sprintf(
'Unexpected argument of type \'%s\' for parameter \'%s\' at index %d. Expected \'%s\'.',
Expand All @@ -27,30 +25,37 @@ public function __construct($parameterName, $index, $value, $expectedType, \Exce
$previous
);
}

public function parameterName()
{
return $this->parameterName;
}

public function index()
{
return $this->index;
}

public function value()
{
return $this->value;
}

public function expectedType()
{
return $this->expectedType;
}

public function typeInspector()
{
return $this->typeInspector;
}

public function unexpectedType()
{
return $this->unexpectedType;
}

private $parameterName;
private $index;
private $value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Icecave\Collections\TypeCheck\Exception;


abstract class UnexpectedInputException extends \InvalidArgumentException
{
public function __construct($message, \Exception $previous = null)
{
parent::__construct($message, 0, $previous);
}

}
45 changes: 23 additions & 22 deletions lib-typhoon/Icecave/Collections/TypeCheck/TypeCheck.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
<?php
namespace Icecave\Collections\TypeCheck;


abstract class TypeCheck
{
public static function get($className, array $arguments = null)
{
if (static::$dummyMode)
{
return (new DummyValidator());
if (static::$dummyMode) {
return new DummyValidator();
}
if ((!\array_key_exists($className, static::$instances)))
{
if (!\array_key_exists($className, static::$instances)) {
static::install($className, static::createValidator($className));
}
($validator = static::$instances[$className]);
if ((null !== $arguments))
{
$validator = static::$instances[$className];
if (null !== $arguments) {
$validator->validateConstruct($arguments);
}
return $validator;
}

public static function install($className, $validator)
{
(static::$instances[$className] = $validator);
static::$instances[$className] = $validator;
}

public static function setRuntimeGeneration($runtimeGeneration)
{
(static::$runtimeGeneration = $runtimeGeneration);
static::$runtimeGeneration = $runtimeGeneration;
}

public static function runtimeGeneration()
{
return static::$runtimeGeneration;
}

protected static function createValidator($className)
{
($validatorClassName = ('Icecave\\Collections\\TypeCheck\\Validator\\' . $className . 'TypeCheck'));
if ((static::runtimeGeneration() && (!\class_exists($validatorClassName))))
{
(static::$dummyMode = true);
$validatorClassName = '\\Icecave\\Collections\\TypeCheck\\Validator\\' . $className . 'TypeCheck';
if (static::runtimeGeneration() && !\class_exists($validatorClassName)) {
static::$dummyMode = true;
static::defineValidator($className);
(static::$dummyMode = false);
static::$dummyMode = false;
}
return (new $validatorClassName);
return new $validatorClassName;
}

protected static function defineValidator($className, \Eloquent\Typhoon\Generator\ValidatorClassGenerator $classGenerator = null)
{
if ((null === $classGenerator))
{
($classGenerator = (new \Eloquent\Typhoon\Generator\ValidatorClassGenerator));
if (null === $classGenerator) {
$classGenerator = new \Eloquent\Typhoon\Generator\ValidatorClassGenerator;
}
eval(('?>' . $classGenerator->generateFromClass(static::configuration(), (new \ReflectionClass($className)))));
eval('?>' . $classGenerator->generateFromClass(static::configuration(), new \ReflectionClass($className)));
}

protected static function configuration()
{
return (new \Eloquent\Typhoon\Configuration\RuntimeConfiguration('Icecave\\Collections\\TypeCheck', false));
return new \Eloquent\Typhoon\Configuration\RuntimeConfiguration(\Eloquent\Cosmos\ClassName::fromString('\\Icecave\\Collections\\TypeCheck'), false);
}

private static $instances = array();
private static $dummyMode = false;
private static $runtimeGeneration = false;
Expand Down
Loading

0 comments on commit 70f15f9

Please sign in to comment.