【发布时间】:2015-08-03 05:48:08
【问题描述】:
我正在尝试在我自己的命名空间中使用来自另一个命名空间的一些文件,但是它无法识别来自 Defuse\Crypto 命名空间的异常。
我检查了所有文件,所有文件都完美地存储在我的目录中。我也可以毫无例外地包含自动加载器。
如何在同一个文件中干净地使用两个命名空间?
这是我的代码:
namespace Defuse\Crypto;
$path = '/my/path/to/DefuseCrypto/autoloader';
require_once $path;
use \Defuse\Crypto\Crypto;
use \Defuse\Crypto\Exception as Ex;
namespace myNamespace;
class myClass
{
static function encrypt_key($key)
{
try
{
$ciphertext = Crypto::encrypt($key, $privateKey);
return $ciphertext;
}
catch (Ex\CryptoTestFailedException $ex)
{
return false;
}
catch (Ex\CannotPerformOperationException $ex)
{
return false;
}
}
static function decrypt_key($key)
{
try
{
$decryptedKey = Crypto::decrypt($key, $privateKey);
return $decryptedKey;
}
catch (Ex\InvalidCiphertextException $ex)
{
return false;
}
catch (Ex\CryptoTestFailedException $ex)
{
return false;
}
catch (Ex\CannotPerformOperationException $ex)
{
return false;
}
}
}
【问题讨论】:
标签: php namespaces