Skip to content

Commit

Permalink
Merge branch 'milestones/exceptions' of git://git.zendframework.com/z…
Browse files Browse the repository at this point in the history
…f into barcode-exceptions
  • Loading branch information
mikaelkael committed Sep 12, 2010
2 parents fddc10e + b18df98 commit d49b049
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 95 deletions.
9 changes: 6 additions & 3 deletions library/Zend/Authentication/Adapter/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ protected function _setDbAdapter(AbstractDBAdapter $zendDb = null)
if(null === $this->_zendDb) {
$this->_zendDb = AbstractTable::getDefaultAdapter();
if (null === $this->_zendDb) {
throw new Exception('No database adapter present');
throw new RuntimeException(
'Null was provided for the adapter but there is no default'
. ' adatper registered with Zend\Db\Table to utilize.'
);
}
}

Expand Down Expand Up @@ -409,7 +412,7 @@ protected function _authenticateSetup()
}

if (null !== $exception) {
throw new Exception($exception);
throw new RuntimeException($exception);
}

$this->_authenticateResultInfo = array(
Expand Down Expand Up @@ -476,7 +479,7 @@ protected function _authenticateQuerySelect(DBSelect $dbSelect)
unset($origDbFetchMode);
}
} catch (\Exception $e) {
throw new Exception('The supplied parameters to Zend\\Authentication\\Adapter\\DbTable failed to '
throw new RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to '
. 'produce a valid sql statement, please check table and column names '
. 'for validity.', 0, $e);
}
Expand Down
6 changes: 3 additions & 3 deletions library/Zend/Authentication/Adapter/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ public function setPassword($password)
/**
* Defined by Zend_Auth_Adapter_Interface
*
* @throws Zend\Authentication\Adapter\Exception
* @throws Zend\Authentication\Adapter\RuntimeException
* @return Zend\Authentication\Result
*/
public function authenticate()
{
$optionsRequired = array('filename', 'realm', 'username', 'password');
foreach ($optionsRequired as $optionRequired) {
if (null === $this->{"_$optionRequired"}) {
throw new Exception("Option '$optionRequired' must be set before authentication");
throw new RuntimeException("Option '$optionRequired' must be set before authentication");
}
}

if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
throw new Exception("Cannot open '$this->_filename' for reading");
throw new UnexpectedValueException("Cannot open '$this->_filename' for reading");
}

$id = "$this->_username:$this->_realm";
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Adapter/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Authentication\Exception
interface Exception extends \Zend\Authentication\Exception
{}
41 changes: 22 additions & 19 deletions library/Zend/Authentication/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ class Http implements AuthenticationAdapter
* 'use_opaque' => <bool> Whether to send the opaque value in the header
* 'alogrithm' => <string> See $_supportedAlgos. Default: MD5
* 'proxy_auth' => <bool> Whether to do authentication as a Proxy
* @throws Zend\Authentication\Exception
* @throws Zend\Authentication\Adapter\InvalidArgumentException
* @return void
*/
public function __construct(array $config)
{
if (!extension_loaded('hash')) {
throw new Exception(__CLASS__ . ' requires the \'hash\' extension');
throw new InvalidArgumentException(__CLASS__ . ' requires the \'hash\' extension to be availabe in PHP');
}

$this->_request = null;
Expand All @@ -182,13 +182,13 @@ public function __construct(array $config)


if (empty($config['accept_schemes'])) {
throw new Exception('Config key \'accept_schemes\' is required');
throw new InvalidArgumentException('Config key \'accept_schemes\' is required');
}

$schemes = explode(' ', $config['accept_schemes']);
$this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes);
if (empty($this->_acceptSchemes)) {
throw new Exception('No supported schemes given in \'accept_schemes\'. Valid values: '
throw new InvalidArgumentException('No supported schemes given in \'accept_schemes\'. Valid values: '
. implode(', ', $this->_supportedSchemes));
}

Expand All @@ -198,7 +198,7 @@ public function __construct(array $config)
!ctype_print($config['realm']) ||
strpos($config['realm'], ':') !== false ||
strpos($config['realm'], '"') !== false) {
throw new Exception('Config key \'realm\' is required, and must contain only printable '
throw new InvalidArgumentException('Config key \'realm\' is required, and must contain only printable '
. 'characters, excluding quotation marks and colons');
} else {
$this->_realm = $config['realm'];
Expand All @@ -208,15 +208,15 @@ public function __construct(array $config)
if (empty($config['digest_domains']) ||
!ctype_print($config['digest_domains']) ||
strpos($config['digest_domains'], '"') !== false) {
throw new Exception('Config key \'digest_domains\' is required, and must contain '
throw new InvalidArgumentException('Config key \'digest_domains\' is required, and must contain '
. 'only printable characters, excluding quotation marks');
} else {
$this->_domains = $config['digest_domains'];
}

if (empty($config['nonce_timeout']) ||
!is_numeric($config['nonce_timeout'])) {
throw new Exception('Config key \'nonce_timeout\' is required, and must be an '
throw new InvalidArgumentException('Config key \'nonce_timeout\' is required, and must be an '
. 'integer');
} else {
$this->_nonceTimeout = (int) $config['nonce_timeout'];
Expand Down Expand Up @@ -339,14 +339,14 @@ public function getResponse()
/**
* Authenticate
*
* @throws Zend\Authentication\Exception
* @throws Zend\Authentication\Adapter\RuntimeException
* @return Zend\Authentication\Result
*/
public function authenticate()
{
if (empty($this->_request) ||
empty($this->_response)) {
throw new Exception('Request and Response objects must be set before calling '
throw new RuntimeException('Request and Response objects must be set before calling '
. 'authenticate()');
}

Expand Down Expand Up @@ -389,7 +389,7 @@ public function authenticate()
$result = $this->_digestAuth($authHeader);
break;
default:
throw new Exception('Unsupported authentication scheme');
throw new RuntimeException('Unsupported authentication scheme: ' . $clientScheme);
}

return $result;
Expand Down Expand Up @@ -466,24 +466,25 @@ protected function _digestHeader()
* Basic Authentication
*
* @param string $header Client's Authorization header
* @throws Zend\Authentication\Exception
* @throws Zend\Authentication\UnexpectedValueException
* @return Zend\Authentication\Result
*/
protected function _basicAuth($header)
{
if (empty($header)) {
throw new Exception('The value of the client Authorization header is required');
throw new RuntimeException('The value of the client Authorization header is required');
}
if (empty($this->_basicResolver)) {
throw new Exception('A basicResolver object must be set before doing Basic '
. 'authentication');
throw new RuntimeException(
'A basicResolver object must be set before doing Basic '
. 'authentication');
}

// Decode the Authorization header
$auth = substr($header, strlen('Basic '));
$auth = base64_decode($auth);
if (!$auth) {
throw new Exception('Unable to base64_decode Authorization header value');
throw new RuntimeException('Unable to base64_decode Authorization header value');
}

// See ZF-1253. Validate the credentials the same way the digest
Expand Down Expand Up @@ -511,16 +512,18 @@ protected function _basicAuth($header)
* Digest Authentication
*
* @param string $header Client's Authorization header
* @throws Zend\Authentication\Exception
* @throws Zend\Authentication\Adapter\UnexpectedValueException
* @throws Zend\Authentication\Adapter\MissingDependencyException
* @throws Zend\Authentication\Adapter\UnsupportedRequestException
* @return Zend\Authentication\Result Valid auth result only on successful auth
*/
protected function _digestAuth($header)
{
if (empty($header)) {
throw new Exception('The value of the client Authorization header is required');
throw new RuntimeException('The value of the client Authorization header is required');
}
if (empty($this->_digestResolver)) {
throw new Exception('A digestResolver object must be set before doing Digest authentication');
throw new RuntimeException('A digestResolver object must be set before doing Digest authentication');
}

$data = $this->_parseDigestAuth($header);
Expand Down Expand Up @@ -575,7 +578,7 @@ protected function _digestAuth($header)
// Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body),
// but this isn't supported yet, so fall through to default case
default:
throw new Exception('Client requested an unsupported qop option');
throw new RuntimeException('Client requested an unsupported qop option');
}
// Using hash() should make parameterizing the hash algorithm
// easier
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Adapter/Http/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Authentication\Exception
interface Exception extends \Zend\Authentication\Adapter\Exception
{}
12 changes: 6 additions & 6 deletions library/Zend/Authentication/Adapter/Http/FileResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct($path = '')
public function setFile($path)
{
if (empty($path) || !is_readable($path)) {
throw new Exception('Path not readable: ' . $path);
throw new InvalidArgumentException('Path not readable: ' . $path);
}
$this->_file = $path;

Expand Down Expand Up @@ -109,22 +109,22 @@ public function getFile()
public function resolve($username, $realm)
{
if (empty($username)) {
throw new Exception('Username is required');
throw new InvalidArgumentException('Username is required');
} else if (!ctype_print($username) || strpos($username, ':') !== false) {
throw new Exception('Username must consist only of printable characters, '
throw new InvalidArgumentException('Username must consist only of printable characters, '
. 'excluding the colon');
}
if (empty($realm)) {
throw new Exception('Realm is required');
throw new InvalidArgumentException('Realm is required');
} else if (!ctype_print($realm) || strpos($realm, ':') !== false) {
throw new Exception('Realm must consist only of printable characters, '
throw new InvalidArgumentException('Realm must consist only of printable characters, '
. 'excluding the colon.');
}

// Open file, read through looking for matching credentials
$fp = @fopen($this->_file, 'r');
if (!$fp) {
throw new Exception('Unable to open password file: ' . $this->_file);
throw new RuntimeException('Unable to open password file: ' . $this->_file);
}

// No real validation is done on the contents of the password file. The
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\Authentication\Adapter\Http;

class InvalidArgumentException
extends \InvalidArgumentException
implements Exception
{
}
9 changes: 9 additions & 0 deletions library/Zend/Authentication/Adapter/Http/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\Authentication\Adapter\Http;

class RuntimeException
extends \RuntimeException
implements Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\Authentication\Adapter;

class InvalidArgumentException
extends \InvalidArgumentException
implements Exception
{
}
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Adapter/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function authenticate()
foreach ($this->_options as $name => $options) {

if (!is_array($options)) {
throw new Exception('Adapter options array not an array');
throw new InvalidArgumentException('Adapter options array not an array');
}
$adapterOptions = $this->_prepareOptions($ldap, $options);
$dname = '';
Expand Down
10 changes: 10 additions & 0 deletions library/Zend/Authentication/Adapter/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Zend\Authentication\Adapter;

class RuntimeException
extends \RuntimeException
implements Exception
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\Authentication\Adapter;

class UnexpectedValueException
extends \UnexpectedValueException
implements Exception
{
}
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Exception
interface Exception
{}
37 changes: 0 additions & 37 deletions library/Zend/Authentication/Storage/Exception.php

This file was deleted.

Loading

0 comments on commit d49b049

Please sign in to comment.