Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into acceptHandling
Browse files Browse the repository at this point in the history
Conflicts:
	library/Zend/Http/Header/AbstractAccept.php
	library/Zend/Http/Header/AcceptEncoding.php
	library/Zend/Http/Header/AcceptLanguage.php
	tests/Zend/Http/Header/AcceptCharsetTest.php
	tests/Zend/Http/Header/AcceptEncodingTest.php
	tests/Zend/Http/Header/AcceptLanguageTest.php
	tests/Zend/Http/Header/AcceptTest.php
  • Loading branch information
Freeaqingme committed Jul 14, 2012
6 parents 3e833ad + 4d4dd8b + c655082 + dbb18b2 + 97a9134 + 80367df commit 98d5255
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 88 deletions.
8 changes: 6 additions & 2 deletions src/Filter/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Log\Filter;

use Zend\Log\Exception;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand All @@ -35,7 +36,10 @@ class Regex implements FilterInterface
*/
public function __construct($regex)
{
if (@preg_match($regex, '') === false) {
ErrorHandler::start(E_WARNING);
$result = preg_match($regex, '');
ErrorHandler::stop();
if ($result === false) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid regular expression "%s"',
$regex
Expand All @@ -54,7 +58,7 @@ public function filter(array $event)
{
$message = $event['message'];
if (is_array($event['message'])) {
$message = var_export($message, TRUE);
$message = var_export($message, TRUE);
}
return preg_match($this->regex, $message) > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(ZendValidator $validator)
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean
* @return boolean
*/
public function filter(array $event)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Formatter/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
class ErrorHandler implements FormatterInterface
{
const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%) %message% (errno %extra[errno]%) in %extra[file]% on line %extra[line]%';

/**
* Format
*
* @var string
*
* @var string
*/
protected $format;

/**
* Class constructor
*
Expand Down
4 changes: 2 additions & 2 deletions src/Formatter/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function format($event)

/**
* Get the type of a function
*
*
* @param string $type
* @return string
* @return string
*/
protected function getType($type)
{
Expand Down
42 changes: 21 additions & 21 deletions src/Writer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Db extends AbstractWriter

/**
* Table name
*
* @var string
*
* @var string
*/
protected $tableName;

Expand All @@ -44,17 +44,17 @@ class Db extends AbstractWriter

/**
* Field separator for sub-elements
*
* @var string
*
* @var string
*/
protected $separator = '_';

/**
* Constructor
*
* We used the Adapter instead of Zend\Db for a performance reason.
*
* @param Adapter $db
*
* @param Adapter $db
* @param string $tableName
* @param array $columnMap
* @param string $separator
Expand All @@ -66,11 +66,11 @@ public function __construct(Adapter $db, $tableName, array $columnMap = null, $s
if ($db === null) {
throw new Exception\InvalidArgumentException('You must pass a valid Zend\Db\Adapter\Adapter');
}

$this->db = $db;
$this->tableName = $tableName;
$this->columnMap = $columnMap;

if (!empty($separator)) {
$this->separator = $separator;
}
Expand Down Expand Up @@ -120,34 +120,34 @@ protected function doWrite(array $event)

$statement = $this->db->query($this->prepareInsert($this->db, $this->tableName, $dataToInsert));
$statement->execute($dataToInsert);

}

/**
* Prepare the INSERT SQL statement
*
*
* @param Adapter $db
* @param string $tableName
* @param array $fields
* @return string
* @return string
*/
protected function prepareInsert(Adapter $db, $tableName, array $fields)
{
protected function prepareInsert(Adapter $db, $tableName, array $fields)
{
$sql = 'INSERT INTO ' . $db->platform->quoteIdentifier($tableName) . ' (' .
implode(",",array_map(array($db->platform, 'quoteIdentifier'), $fields)) . ') VALUES (' .
implode(",",array_map(array($db->driver, 'formatParameterName'), $fields)) . ')';

return $sql;
}

/**
* Map event into column using the $columnMap array
*
*
* @param array $event
* @param array $columnMap
* @return array
* @return array
*/
protected function mapEventIntoColumn(array $event, array $columnMap = null)
protected function mapEventIntoColumn(array $event, array $columnMap = null)
{
if (empty($event)) {
return array();
Expand All @@ -163,18 +163,18 @@ protected function mapEventIntoColumn(array $event, array $columnMap = null)
}
} elseif (isset($columnMap[$name])) {
$data[$columnMap[$name]] = $value;
}
}
}
return $data;
}

/**
* Transform event into column for the db table
*
*
* @param array $event
* @return array
* @return array
*/
protected function eventIntoColumn(array $event)
protected function eventIntoColumn(array $event)
{
if (empty($event)) {
return array();
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* completion, so any log entries accumulated are sent in a single email.
* The email is sent using a Zend\Mail\Transport\TransportInterface object
* (Sendmail is default).
*
*
* @category Zend
* @package Zend_Log
* @subpackage Writer
Expand Down Expand Up @@ -72,7 +72,7 @@ class Mail extends AbstractWriter

/**
* Constructor
*
*
* @param MailMessage $mail
* @param Transport\TransportInterface $transport Optional
* @return Mail
Expand Down
84 changes: 84 additions & 0 deletions src/Writer/MongoDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace Zend\Log\Writer;

use Mongo;
use Zend\Log\Exception\InvalidArgumentException;
use Zend\Log\Exception\RuntimeException;
use Zend\Log\Formatter\FormatterInterface;

/**
* MongoDB log writer.
*
* @category Zend
* @package Zend_Log
* @subpackage Writer
*/
class MongoDB extends AbstractWriter
{
/**
* MongoCollection instance
*
* @var MongoCollection
*/
protected $mongoCollection;

/**
* Options used for MongoCollection::save()
*
* @var array
*/
protected $saveOptions;

/**
* Constructor
*
* @param Mongo $mongo
* @param string $database
* @param string $collection
* @param array $saveOptions
* @return Zend\Log\Writer\MongoDB
*/
public function __construct(Mongo $mongo, $database, $collection, array $saveOptions = array())
{
$this->mongoCollection = $mongo->selectCollection($database, $collection);
$this->saveOptions = $saveOptions;
}

/**
* This writer does not support formatting.
*
* @param Zend\Log\Formatter\FormatterInterface $formatter
* @return void
* @throws Zend\Log\Exception\InvalidArgumentException
*/
public function setFormatter(FormatterInterface $formatter)
{
throw new InvalidArgumentException(get_class() . ' does not support formatting');
}

/**
* Write a message to the log.
*
* @param array $event Event data
* @return void
* @throws Zend\Log\Exception\RuntimeException
*/
protected function doWrite(array $event)
{
if (null === $this->mongoCollection) {
throw new RuntimeException('MongoCollection must be defined');
}

$this->mongoCollection->save($event, $this->saveOptions);
}
}
6 changes: 5 additions & 1 deletion src/Writer/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Log\Exception;
use Zend\Log\Formatter\Simple as SimpleFormatter;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -87,7 +88,10 @@ protected function doWrite(array $event)
{
$line = $this->formatter->format($event);

if (false === @fwrite($this->stream, $line)) {
ErrorHandler::start(E_WARNING);
$result = fwrite($this->stream, $line);
ErrorHandler::stop();
if (false === $result) {
throw new Exception\RuntimeException("Unable to write to stream");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function setFacility($facility)

if (!in_array($facility, $this->validFacilities)) {
throw new Exception\InvalidArgumentException(
'Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values'
'Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values'
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/WriterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class WriterPluginManager extends AbstractPluginManager
{
/**
* Default set of writers
*
*
* @var array
*/
protected $invokableClasses = array(
Expand All @@ -39,8 +39,8 @@ class WriterPluginManager extends AbstractPluginManager
* Validate the plugin
*
* Checks that the writer loaded is an instance of Writer\WriterInterface.
*
* @param mixed $plugin
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
Expand Down
4 changes: 2 additions & 2 deletions test/Filter/ChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace ZendTest\Log\Filter;

use \Zend\Log\Logger;
use \Zend\Log\Writer;
use Zend\Log\Logger;
use Zend\Log\Writer;

/**
* @category Zend
Expand Down
4 changes: 2 additions & 2 deletions test/Filter/PriorityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace ZendTest\Log\Filter;

use \Zend\Log\Logger;
use \Zend\Log\Filter\Priority;
use Zend\Log\Logger;
use Zend\Log\Filter\Priority;

/**
* @category Zend
Expand Down
4 changes: 2 additions & 2 deletions test/Filter/SuppressFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace ZendTest\Log\Filter;

use \Zend\Log\Filter\SuppressFilter;
use \Zend\Log\Logger;
use Zend\Log\Filter\SuppressFilter;
use Zend\Log\Logger;

/**
* @category Zend
Expand Down
2 changes: 1 addition & 1 deletion test/Filter/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testValidatorFilter()
$this->assertFalse($filter->filter(array('message' => 'test123')));
$this->assertFalse($filter->filter(array('message' => '(%$')));
}

public function testValidatorChain()
{
$validatorChain = new ValidatorChain();
Expand Down
Loading

0 comments on commit 98d5255

Please sign in to comment.