Skip to content

Commit

Permalink
refactor exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Dec 29, 2014
1 parent b4d452b commit cd2a48a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 146 deletions.
2 changes: 1 addition & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
echo PHP_EOL."*** Single lookup with no results ***".PHP_EOL;
try {
$user = $sm->find('Doctrine\Tests\Models\Comments\User', 'unknownid');
} catch (Doctrine\Search\Exception\NoResultException $exception) {
} catch (\Doctrine\Search\NoResultException $exception) {
print_r($exception->getMessage());
echo PHP_EOL;
}
Expand Down
24 changes: 0 additions & 24 deletions lib/Doctrine/Search/Exception/DoctrineSearchException.php

This file was deleted.

This file was deleted.

This file was deleted.

34 changes: 0 additions & 34 deletions lib/Doctrine/Search/Exception/NoResultException.php

This file was deleted.

35 changes: 0 additions & 35 deletions lib/Doctrine/Search/Exception/UnexpectedTypeException.php

This file was deleted.

91 changes: 91 additions & 0 deletions lib/Doctrine/Search/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Doctrine\Search;



interface Exception
{

}



class DefaultSerializerNotProvidedException extends \LogicException implements Exception
{

}



class DoctrineSearchException extends \RuntimeException implements Exception
{

}



class NotImplementedException extends \LogicException implements Exception
{

}


class InvalidMetadataException extends \LogicException implements Exception
{

}


class InvalidArgumentException extends \InvalidArgumentException implements Exception
{

}



class InvalidStateException extends \RuntimeException implements Exception
{

}



class UnexpectedValueException extends \UnexpectedValueException implements Exception
{

}



/**
* Exception thrown when an search query unexpectedly does not return any results.
*
* @author robo
* @since 2.0
*/
class NoResultException extends \RuntimeException implements Exception
{

public function __construct($message = NULL)
{
parent::__construct($message ?: 'No result was found for query although at least one row was expected.');
}
}



class UnexpectedTypeException extends \LogicException implements Exception
{

public function __construct($value, $expected)
{
parent::__construct(
sprintf(
'Expected argument of type "%s", "%s" given',
$expected,
(is_object($value) ? get_class($value) : gettype($value))
)
);
}
}

0 comments on commit cd2a48a

Please sign in to comment.