本文整理匯總了PHP中Zend\Stdlib\ErrorHandler::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP ErrorHandler::addError方法的具體用法?PHP ErrorHandler::addError怎麽用?PHP ErrorHandler::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Stdlib\ErrorHandler
的用法示例。
在下文中一共展示了ErrorHandler::addError方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testAddError
public function testAddError()
{
ErrorHandler::start();
ErrorHandler::addError(1, 'test-msg1', 'test-file1', 100);
ErrorHandler::addError(2, 'test-msg2', 'test-file2', 200);
$err = ErrorHandler::stop();
$this->assertInstanceOf('ErrorException', $err);
$this->assertEquals('test-file2', $err->getFile());
$this->assertEquals('test-msg2', $err->getMessage());
$this->assertEquals(200, $err->getLine());
$this->assertEquals(0, $err->getCode());
$this->assertEquals(2, $err->getSeverity());
$previous = $err->getPrevious();
$this->assertInstanceOf('ErrorException', $previous);
$this->assertEquals('test-file1', $previous->getFile());
$this->assertEquals('test-msg1', $previous->getMessage());
$this->assertEquals(100, $previous->getLine());
$this->assertEquals(0, $previous->getCode());
$this->assertEquals(1, $previous->getSeverity());
}
示例2: clearByPrefix
/**
* Remove items matching given prefix
*
* @param string $prefix
* @throws Exception\RuntimeException
* @return bool
*/
public function clearByPrefix($prefix)
{
$prefix = (string) $prefix;
if ($prefix === '') {
throw new Exception\InvalidArgumentException('No prefix given');
}
$options = $this->getOptions();
$namespace = $options->getNamespace();
$nsPrefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
$flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
$path = $options->getCacheDir() . str_repeat(DIRECTORY_SEPARATOR . $nsPrefix . '*', $options->getDirLevel()) . DIRECTORY_SEPARATOR . $nsPrefix . $prefix . '*.*';
$glob = new GlobIterator($path, $flags);
ErrorHandler::start();
foreach ($glob as $pathname) {
// remove the file by ignoring errors if the file doesn't exist afterwards
// to fix a possible race condition if onother process removed the faile already.
ErrorHandler::start();
unlink($pathname);
$err = ErrorHandler::stop();
if ($err && file_exists($pathname)) {
ErrorHandler::addError($err->getSeverity(), $err->getMessage(), $err->getFile(), $err->getLine());
}
}
$err = ErrorHandler::stop();
if ($err) {
$result = false;
return $this->triggerException(__FUNCTION__, new ArrayObject(), $result, new Exception\RuntimeException("Failed to remove files of '{$path}'", 0, $err));
}
return true;
}