php Zend-Stdlib-ErrorHandler类(方法)实例源码

下面列出了php Zend-Stdlib-ErrorHandler 类(方法)源码代码实例,从而了解它的用法。

作者:leodid    项目:moneylaundr   
/**
  * 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;
 }

作者:radna    项目:rdn-consol   
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');
 }

作者:ralfegger    项目:zftoo   
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);
     }
 }

作者:alexb-u    项目:ZendServerSD   
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.';
     }
 }

作者:Andyyang198    项目:p   
/**
  * 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;
 }

作者:ramo    项目:zf   
/**
     * 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');
            }
        }
    }

作者:Baf    项目:Zend-For   
/**
  * 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();
 }

作者:proop    项目:link-app-cor   
/**
  * @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);
 }

作者:ninahuanc    项目:zf   
public function tearDown()
 {
     // be sure the error handler has been stopped
     if (ErrorHandler::started()) {
         ErrorHandler::stop();
         $this->fail('ErrorHandler not stopped');
     }
 }

作者:marcyni    项目:vendor   
/**
  * 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();
     }
 }

作者:rezi    项目:ZfcDatagri   
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);
 }

作者:thomascantonne    项目:tc-errorhandle   
public function checkForErrors(MvcEvent $e)
 {
     try {
         ErrorHandler::stop(true);
         $this->startMonitoringErrors($e);
     } catch (ErrorException $exception) {
         $this->outputFatalError($exception, $e);
     }
     return;
 }

作者:jguittar    项目:AssetManage   
/**
  * {@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;
 }

作者:radna    项目:rdn-uploa   
/**
  * @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})");
     }
 }

作者:pnaq5    项目:zf2dem   
/**
  * @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);
 }

作者:avbruge    项目:uace-larave   
/**
  * Object constructor
  *
  * @throws \ZendSearch\Lucene\Exception\RuntimeException
  */
 public function __construct()
 {
     ErrorHandler::start(E_WARNING);
     $result = preg_match('/\\pL/u', 'a');
     ErrorHandler::stop();
     if ($result != 1) {
         // PCRE unicode support is turned off
         throw new RuntimeException('Utf8 analyzer needs PCRE unicode support to be enabled.');
     }
 }

作者:KBO-Techo-De    项目:MagazinePro-zf2   
/**
  * Constructor
  *
  * Attempts to read from php://input to get raw POST request; if an error
  * occurs in doing so, or if the XML is invalid, the request is declared a
  * fault.
  *
  */
 public function __construct()
 {
     ErrorHandler::start();
     $xml = file_get_contents('php://input');
     ErrorHandler::stop();
     if (!$xml) {
         $this->fault = new Fault(630);
         return;
     }
     $this->xml = $xml;
     $this->loadXml($xml);
 }

作者:proop    项目:link-app-cor   
/**
  * @param string $configLocation
  * @param string $sqliteDbFile
  * @return EventStoreSetUpWasUndone
  */
 public static function undoEventStoreSetUp($configLocation, $sqliteDbFile)
 {
     ErrorHandler::start();
     if (file_exists($configLocation . DIRECTORY_SEPARATOR . self::$configFileName)) {
         unlink($configLocation . DIRECTORY_SEPARATOR . self::$configFileName);
     }
     if (file_exists($sqliteDbFile)) {
         unlink($sqliteDbFile);
     }
     ErrorHandler::stop();
     return EventStoreSetUpWasUndone::in($configLocation . DIRECTORY_SEPARATOR . self::$configFileName);
 }

作者:leonardovn8    项目:zf2_basic201   
/**
  * Deserialize igbinary string to PHP value
  *
  * @param  string $serialized
  * @return mixed
  * @throws Exception\RuntimeException on igbinary error
  */
 public function unserialize($serialized)
 {
     if ($serialized === static::$serializedNull) {
         return null;
     }
     ErrorHandler::start();
     $ret = igbinary_unserialize($serialized);
     $err = ErrorHandler::stop();
     if ($ret === null) {
         throw new Exception\RuntimeException('Unserialization failed', 0, $err);
     }
     return $ret;
 }

作者:gstearmi    项目:EshopVegeTabl   
/**
  * Override moveUploadedFile
  *
  * If the request is not HTTP, or not a PUT or PATCH request, delegates to
  * the parent functionality.
  *
  * Otherwise, does a `rename()` operation, and returns the status of the
  * operation.
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @return bool
  * @throws FilterRuntimeException in the event of a warning
  */
 protected function moveUploadedFile($sourceFile, $targetFile)
 {
     if (null === $this->request || !method_exists($this->request, 'isPut') || !$this->request->isPut() && !$this->request->isPatch()) {
         return parent::moveUploadedFile($sourceFile, $targetFile);
     }
     ErrorHandler::start();
     $result = rename($sourceFile, $targetFile);
     $warningException = ErrorHandler::stop();
     if (false === $result || null !== $warningException) {
         throw new FilterRuntimeException(sprintf('File "%s" could not be renamed. An error occurred while processing the file.', $sourceFile), 0, $warningException);
     }
     return $result;
 }


问题


面经


文章

微信
公众号

扫码关注公众号