This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream/master' into module-class-map-cache
- Loading branch information
47 parents
309136e
+
fe78a35
+
f6430c3
+
6041a1e
+
86b9031
+
674bd75
+
67a1bfb
+
4d4dd8b
+
c655082
+
dbb18b2
+
97a9134
+
80367df
+
98d5255
+
7946c9f
+
ea67c13
+
44df0b2
+
38e090d
+
7af74e7
+
8b311b1
+
e2c2b94
+
51601cb
+
dcc1eaf
+
6f4b805
+
a30a64f
+
ee7347d
+
8b04bfe
+
b487f00
+
ecdfdf6
+
d8cde75
+
b7a33bb
+
65ecb58
+
571d938
+
625a786
+
6fe4efc
+
f94838d
+
76607e3
+
492076c
+
17b56b8
+
c5509fe
+
e0fa433
+
7d74e99
+
f1dd38a
+
7be533f
+
6a618c2
+
3a454e3
+
f66ca80
+
f1bebf2
commit 91ed9d0
Showing
20 changed files
with
570 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?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\Formatter; | ||
|
||
use DateTime; | ||
use Traversable; | ||
use Zend\Log\Exception; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Log | ||
* @subpackage Formatter | ||
*/ | ||
class Base implements FormatterInterface | ||
{ | ||
/** | ||
* Format specifier for DateTime objects in event data (default: ISO 8601) | ||
* | ||
* @see http://php.net/manual/en/function.date.php | ||
* @var string | ||
*/ | ||
protected $dateTimeFormat = self::DEFAULT_DATETIME_FORMAT; | ||
|
||
/** | ||
* Class constructor | ||
* | ||
* @see http://php.net/manual/en/function.date.php | ||
* @param null|string $dateTimeFormat Format for DateTime objects | ||
*/ | ||
public function __construct($dateTimeFormat = null) | ||
{ | ||
if (null !== $dateTimeFormat) { | ||
$this->dateTimeFormat = $dateTimeFormat; | ||
} | ||
} | ||
|
||
/** | ||
* Formats data to be written by the writer. | ||
* | ||
* @param array $event event data | ||
* @return array | ||
*/ | ||
public function format($event) | ||
{ | ||
foreach ($event as $key => $value) { | ||
// Keep extra as an array | ||
if ('extra' === $key) { | ||
$event[$key] = self::format($value); | ||
} else { | ||
$event[$key] = $this->normalize($value); | ||
} | ||
} | ||
|
||
return $event; | ||
} | ||
|
||
/** | ||
* Normalize all non-scalar data types (except null) in a string value | ||
* | ||
* @param mixed $value | ||
* @return mixed | ||
*/ | ||
protected function normalize($value) | ||
{ | ||
if (is_scalar($value) || null === $value) { | ||
return $value; | ||
} | ||
|
||
if ($value instanceof DateTime) { | ||
$value = $value->format($this->getDateTimeFormat()); | ||
} elseif (is_array($value) || $value instanceof Traversable) { | ||
if ($value instanceof Traversable) { | ||
$value = iterator_to_array($value); | ||
} | ||
foreach ($value as $key => $subvalue) { | ||
$value[$key] = $this->normalize($subvalue); | ||
} | ||
$value = json_encode($value); | ||
} elseif (is_object($value) && !method_exists($value,'__toString')) { | ||
$value = sprintf('object(%s) %s', get_class($value), json_encode($value)); | ||
} elseif (is_resource($value)) { | ||
$value = sprintf('resource(%s)', get_resource_type($value)); | ||
} elseif (!is_object($value)) { | ||
$value = gettype($value); | ||
} | ||
|
||
return (string) $value; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getDateTimeFormat() | ||
{ | ||
return $this->dateTimeFormat; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setDateTimeFormat($dateTimeFormat) | ||
{ | ||
$this->dateTimeFormat = (string) $dateTimeFormat; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?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\Formatter; | ||
|
||
use DateTime; | ||
use Zend\Log\Exception; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Log | ||
* @subpackage Formatter | ||
*/ | ||
class Db implements FormatterInterface | ||
{ | ||
/** | ||
* Format specifier for DateTime objects in event data (default: ISO 8601) | ||
* | ||
* @see http://php.net/manual/en/function.date.php | ||
* @var string | ||
*/ | ||
protected $dateTimeFormat = self::DEFAULT_DATETIME_FORMAT; | ||
|
||
/** | ||
* Class constructor | ||
* | ||
* @see http://php.net/manual/en/function.date.php | ||
* @param null|string $dateTimeFormat Format specifier for DateTime objects in event data | ||
*/ | ||
public function __construct($dateTimeFormat = null) | ||
{ | ||
if (null !== $dateTimeFormat) { | ||
$this->setDateTimeFormat($dateTimeFormat); | ||
} | ||
} | ||
|
||
/** | ||
* Formats data to be written by the writer. | ||
* | ||
* @param array $event event data | ||
* @return array | ||
*/ | ||
public function format($event) | ||
{ | ||
$format = $this->getDateTimeFormat(); | ||
array_walk_recursive($event, function (&$value) use ($format) { | ||
if ($value instanceof DateTime) { | ||
$value = $value->format($format); | ||
} | ||
}); | ||
|
||
return $event; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getDateTimeFormat() | ||
{ | ||
return $this->dateTimeFormat; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setDateTimeFormat($dateTimeFormat) | ||
{ | ||
$this->dateTimeFormat = (string) $dateTimeFormat; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.