当前位置: 首页>>代码示例>>PHP>>正文


PHP Stdlib\ErrorHandler类代码示例

本文整理汇总了PHP中Zend\Stdlib\ErrorHandler的典型用法代码示例。如果您正苦于以下问题:PHP ErrorHandler类的具体用法?PHP ErrorHandler怎么用?PHP ErrorHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ErrorHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter

 /**
  * Returns the result of filtering $value
  *
  * @param mixed $value
  * @return mixed
  */
 public function filter($value)
 {
     $unfilteredValue = $value;
     if (is_float($value) && !is_nan($value) && !is_infinite($value)) {
         ErrorHandler::start();
         $formatter = $this->getFormatter();
         $currencyCode = $this->setupCurrencyCode();
         $result = $formatter->formatCurrency($value, $currencyCode);
         ErrorHandler::stop();
         // FIXME: verify that this, given the initial IF condition, never happens
         // if ($result === false) {
         // return $unfilteredValue;
         // }
         // Retrieve the precision internally used by the formatter (i.e., depends from locale and currency code)
         $precision = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
         // $result is considered valid if the currency's fraction digits can accomodate the $value decimal precision
         // i.e. EUR (fraction digits = 2) must NOT allow double(1.23432423432)
         $isFloatScalePrecise = $this->isFloatScalePrecise($value, $precision, $this->formatter->getAttribute(\NumberFormatter::ROUNDING_MODE));
         if ($this->getScaleCorrectness() && !$isFloatScalePrecise) {
             return $unfilteredValue;
         }
         return $result;
     }
     return $unfilteredValue;
 }
开发者ID:leodido,项目名称:moneylaundry,代码行数:31,代码来源:Currency.php

示例2: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $cacheDir = $this->config['directory'];
     if (!is_writable($cacheDir)) {
         throw new \RuntimeException("Unable to write to the {$cacheDir} directory");
     }
     $output->writeln('<info>Clearing the cache</info>');
     $dirIterator = new \RecursiveDirectoryIterator($cacheDir, \FilesystemIterator::SKIP_DOTS);
     /** @var \DirectoryIterator[] $items */
     $items = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($items as $item) {
         if (substr($item->getFileName(), 0, 1) == '.') {
             continue;
         }
         if ($item->isFile()) {
             ErrorHandler::start();
             unlink($item->getPathName());
             ErrorHandler::stop(true);
             if (file_exists($item->getPathname())) {
                 throw new \RuntimeException('Could not delete file ' . $item->getPathname());
             }
         } else {
             ErrorHandler::start();
             rmdir($item->getPathName());
             ErrorHandler::stop(true);
             if (file_exists($item->getPathname())) {
                 throw new \RuntimeException('Could not delete directory ' . $item->getPathname());
             }
         }
     }
     $output->writeln('Successfully deleted all cache files');
 }
开发者ID:radnan,项目名称:rdn-console,代码行数:32,代码来源:CacheClear.php

示例3: onRun

 public function onRun(RunEvent $e)
 {
     /* @var $test \ZFTool\Diagnostics\Test\TestInterface */
     $test = $e->getTarget();
     try {
         ErrorHandler::start($this->getCatchErrorSeverity());
         $result = $test->run();
         ErrorHandler::stop(true);
     } catch (ErrorException $e) {
         return new Failure('PHP ' . static::getSeverityDescription($e->getSeverity()) . ': ' . $e->getMessage(), $e);
     } catch (\Exception $e) {
         ErrorHandler::stop(false);
         return new Failure('Uncaught ' . get_class($e) . ': ' . $e->getMessage(), $e);
     }
     // Check if we've received a Result object
     if (is_object($result)) {
         if (!$result instanceof ResultInterface) {
             return new Failure('Test returned unknown object ' . get_class($result), $result);
         }
         return $result;
         // Interpret boolean as a failure or success
     } elseif (is_bool($result)) {
         if ($result) {
             return new Success();
         } else {
             return new Failure();
         }
         // Convert scalars to a warning
     } elseif (is_scalar($result)) {
         return new Warning('Test returned unexpected ' . gettype($result), $result);
         // Otherwise interpret as failure
     } else {
         return new Failure('Test returned unknown result of type ' . gettype($result), $result);
     }
 }
开发者ID:ralfeggert,项目名称:zftool,代码行数:35,代码来源:RunListener.php

示例4: pharAction

 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:29,代码来源:UpdateController.php

示例5: load

 /**
  * Load a CSV file content
  *
  * {@inheritdoc}
  * @return TextDomain|false
  */
 public function load($locale, $filename)
 {
     //$filename .= $this->fileExtension;
     $messages = array();
     ErrorHandler::start();
     $file = fopen($filename, 'rb');
     $error = ErrorHandler::stop();
     if (false === $file) {
         return false;
     }
     while (($data = fgetcsv($file, $this->options['length'], $this->options['delimiter'], $this->options['enclosure'])) !== false) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             $singular = array_shift($data);
             $messages[$singular] = $data;
         }
     }
     $textDomain = new TextDomain($messages);
     return $textDomain;
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:33,代码来源:Csv.php

示例6: connect

    /**
     * Open connection to IMAP server
     *
     * @param  string      $host  hostname or IP address of IMAP server
     * @param  int|null    $port  of IMAP server, default is 143 (993 for ssl)
     * @param  string|bool $ssl   use 'SSL', 'TLS' or false
     * @throws Exception\RuntimeException
     * @return string welcome message
     */
    public function connect($host, $port = null, $ssl = false)
    {
        if ($ssl == 'SSL') {
            $host = 'ssl://' . $host;
        }

        if ($port === null) {
            $port = $ssl === 'SSL' ? 993 : 143;
        }

        ErrorHandler::start();
        $this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
        $error = ErrorHandler::stop();
        if (!$this->socket) {
            throw new Exception\RuntimeException(sprintf(
                'cannot connect to host%s',
                ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '')
            ), 0, $error);
        }

        if (!$this->_assumedNextLine('* OK')) {
            throw new Exception\RuntimeException('host doesn\'t allow connection');
        }

        if ($ssl === 'TLS') {
            $result = $this->requestAndResponse('STARTTLS');
            $result = $result && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
            if (!$result) {
                throw new Exception\RuntimeException('cannot enable TLS');
            }
        }
    }
开发者ID:ramol,项目名称:zf2,代码行数:41,代码来源:Imap.php

示例7: __construct

 /**
  * Constructor
  *
  * @param  string|resource|array|Traversable $streamOrUrl Stream or URL to open as a stream
  * @param  string|null $mode Mode, only applicable if a URL is given
  * @param  null|string $logSeparator Log separator string
  * @return Stream
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function __construct($streamOrUrl, $mode = null, $logSeparator = null)
 {
     if ($streamOrUrl instanceof Traversable) {
         $streamOrUrl = iterator_to_array($streamOrUrl);
     }
     if (is_array($streamOrUrl)) {
         $mode = isset($streamOrUrl['mode']) ? $streamOrUrl['mode'] : null;
         $logSeparator = isset($streamOrUrl['log_separator']) ? $streamOrUrl['log_separator'] : null;
         $streamOrUrl = isset($streamOrUrl['stream']) ? $streamOrUrl['stream'] : null;
     }
     // Setting the default mode
     if (null === $mode) {
         $mode = 'a';
     }
     if (is_resource($streamOrUrl)) {
         if ('stream' != get_resource_type($streamOrUrl)) {
             throw new Exception\InvalidArgumentException(sprintf('Resource is not a stream; received "%s', get_resource_type($streamOrUrl)));
         }
         if ('a' != $mode) {
             throw new Exception\InvalidArgumentException(sprintf('Mode must be "a" on existing streams; received "%s"', $mode));
         }
         $this->stream = $streamOrUrl;
     } else {
         ErrorHandler::start();
         $this->stream = fopen($streamOrUrl, $mode, false);
         $error = ErrorHandler::stop();
         if (!$this->stream) {
             throw new Exception\RuntimeException(sprintf('"%s" cannot be opened with mode "%s"', $streamOrUrl, $mode), 0, $error);
         }
     }
     if (null !== $logSeparator) {
         $this->setLogSeparator($logSeparator);
     }
     $this->formatter = new SimpleFormatter();
 }
开发者ID:Baft,项目名称:Zend-Form,代码行数:45,代码来源:Stream.php

示例8: initializeFromDist

 /**
  * @param string $fileName
  * @return \Application\SharedKernel\SqliteDbFile
  */
 public static function initializeFromDist($fileName)
 {
     $dist = new self($fileName . '.dist');
     ErrorHandler::start();
     copy($dist->toString(), $fileName);
     ErrorHandler::stop(true);
     return new self($fileName);
 }
开发者ID:prooph,项目名称:link-app-core,代码行数:12,代码来源:SqliteDbFile.php

示例9: tearDown

 public function tearDown()
 {
     // be sure the error handler has been stopped
     if (ErrorHandler::started()) {
         ErrorHandler::stop();
         $this->fail('ErrorHandler not stopped');
     }
 }
开发者ID:ninahuanca,项目名称:zf2,代码行数:8,代码来源:CommonAdapterTest.php

示例10: __destruct

 /**
  * Object destructor.
  *
  * Closes the file if it had been successfully opened.
  */
 public function __destruct()
 {
     if (is_resource($this->_fileResource)) {
         ErrorHandler::start(E_WARNING);
         fclose($this->_fileResource);
         ErrorHandler::stop();
     }
 }
开发者ID:marcyniu,项目名称:vendors,代码行数:13,代码来源:File.php

示例11: testSetByValueException

 public function testSetByValueException()
 {
     /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
     $style = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\Style\\AbstractStyle');
     ErrorHandler::start(E_USER_DEPRECATED);
     $style->setByValue($this->column, 'test');
     $err = ErrorHandler::stop();
     $this->assertInstanceOf('ErrorException', $err);
 }
开发者ID:rezix,项目名称:ZfcDatagrid,代码行数:9,代码来源:AbstractStyleTest.php

示例12: checkForErrors

 public function checkForErrors(MvcEvent $e)
 {
     try {
         ErrorHandler::stop(true);
         $this->startMonitoringErrors($e);
     } catch (ErrorException $exception) {
         $this->outputFatalError($exception, $e);
     }
     return;
 }
开发者ID:thomascantonnet,项目名称:tc-errorhandler,代码行数:10,代码来源:Module.php

示例13: remove

 /**
  * {@inheritDoc}
  */
 public function remove($key)
 {
     ErrorHandler::start(\E_WARNING);
     $success = unlink($this->cachedFile());
     ErrorHandler::stop();
     if (false === $success) {
         throw new RuntimeException(sprintf('Could not remove key "%s"', $this->cachedFile()));
     }
     return $success;
 }
开发者ID:jguittard,项目名称:AssetManager,代码行数:13,代码来源:FilePathCache.php

示例14: download

 /**
  * @inheritdoc
  * @throws \RuntimeException
  */
 public function download($id, FileInterface $output)
 {
     $source = new GFile($id, $this->filesystem);
     ErrorHandler::start();
     $flag = file_put_contents($output->getPath(), $source->getContent());
     ErrorHandler::stop(true);
     if ($flag === false) {
         throw new \RuntimeException("Could not download file ({$id})");
     }
 }
开发者ID:radnan,项目名称:rdn-upload,代码行数:14,代码来源:Gaufrette.php

示例15: testGetConstantsReturnsConstantNames

 /**
  * @todo Remove error handling once we remove deprecation warning from getConstants method
  */
 public function testGetConstantsReturnsConstantNames()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\FooClass');
     ErrorHandler::start(E_USER_DEPRECATED);
     $constants = $class->getConstants();
     $error = ErrorHandler::stop();
     $this->assertInstanceOf('ErrorException', $error);
     $this->assertContains('FOO', $constants);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:13,代码来源:ClassScannerTest.php


注:本文中的Zend\Stdlib\ErrorHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。