Permalink
Browse files

Merge branch 'master' of https://github.com/zendframework/zf2

  • Loading branch information...
2 parents 1f24eba + 46d786f commit 2f41c1bd7e44b73e6c5ff6cabc13f736dc5f4e6c Jerry Saravia committed Oct 7, 2012
Showing with 376 additions and 71 deletions.
  1. +3 −1 .gitignore
  2. +5 −4 composer.json
  3. +1 −1 library/Zend/Db/Adapter/AdapterServiceFactory.php
  4. +6 −0 library/Zend/Db/Adapter/Driver/Pdo/Connection.php
  5. +8 −0 library/Zend/Form/Element/Date.php
  6. +1 −1 library/Zend/I18n/Translator/TranslatorServiceFactory.php
  7. +41 −1 library/Zend/I18n/View/Helper/CurrencyFormat.php
  8. +1 −1 library/Zend/Mvc/Service/RouterFactory.php
  9. +63 −1 library/Zend/Mvc/View/Console/RouteNotFoundStrategy.php
  10. +7 −0 library/Zend/Mvc/View/Console/ViewManager.php
  11. +1 −1 library/Zend/Navigation/Service/AbstractNavigationFactory.php
  12. +5 −1 library/Zend/ServiceManager/ServiceManager.php
  13. +1 −0 library/Zend/Stdlib/Exception/BadMethodCallException.php
  14. +7 −0 library/Zend/Stdlib/Exception/DomainException.php
  15. +7 −0 library/Zend/Stdlib/Exception/ExceptionInterface.php
  16. +7 −0 library/Zend/Stdlib/Exception/InvalidArgumentException.php
  17. +1 −0 library/Zend/Stdlib/Exception/InvalidCallbackException.php
  18. +2 −1 library/Zend/Stdlib/Exception/LogicException.php
  19. +5 −0 library/Zend/Stdlib/Hydrator/Reflection.php
  20. +4 −0 library/Zend/Stdlib/Message.php
  21. +29 −0 library/Zend/Stdlib/MessageInterface.php
  22. +5 −1 library/Zend/Stdlib/Parameters.php
  23. +52 −4 library/Zend/Stdlib/ParametersInterface.php
  24. +4 −0 library/Zend/Stdlib/Request.php
  25. +4 −0 library/Zend/Stdlib/RequestInterface.php
  26. +4 −0 library/Zend/Stdlib/Response.php
  27. +4 −0 library/Zend/Stdlib/ResponseInterface.php
  28. +4 −8 library/Zend/View/Strategy/FeedStrategy.php
  29. +1 −0 tests/ZendTest/Barcode/Renderer/PdfTest.php
  30. +1 −1 tests/ZendTest/Feed/Reader/ReaderTest.php
  31. +5 −7 tests/ZendTest/Filter/Compress/RarTest.php
  32. +10 −0 tests/ZendTest/Form/Element/DateTest.php
  33. +32 −33 tests/ZendTest/I18n/View/Helper/CurrencyFormatTest.php
  34. +11 −2 tests/ZendTest/ServiceManager/ServiceManagerTest.php
  35. +8 −1 tests/ZendTest/View/Helper/Navigation/SitemapTest.php
  36. +21 −0 tests/ZendTest/View/Strategy/FeedStrategyTest.php
  37. +3 −0 tests/ZendTest/XmlRpc/BigIntegerValueTest.php
  38. +2 −1 tests/run-tests.php
View
@@ -5,4 +5,6 @@ nbproject
.settings/
tmp/
.DS_Store
-composer.lock
+composer.lock
+.*.sw*
+.*.un~
View
@@ -12,7 +12,8 @@
"php": ">=5.3.3"
},
"require-dev": {
- "doctrine/common": ">=2.1"
+ "doctrine/common": ">=2.1",
+ "phpunit/PHPUnit": "3.7.*"
},
"suggest": {
"doctrine/common": "Doctrine\\Common >=2.1 for annotation features",
@@ -27,9 +28,9 @@
"ZendTest\\": "tests/"
}
},
- "config": {
- "bin-dir": "bin"
- },
+ "bin": [
+ "bin/classmap_generator.php"
+ ],
"replace": {
"zendframework/zend-acl": "self.version",
"zendframework/zend-authentication": "self.version",
@@ -28,7 +28,7 @@ class AdapterServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
- $config = $serviceLocator->get('Configuration');
+ $config = $serviceLocator->get('Config');
return new Adapter($config['db']);
}
}
@@ -213,6 +213,9 @@ public function connect()
case 'hostname':
$hostname = (string) $value;
break;
+ case 'port':
+ $port = (int) $value;
+ break;
case 'database':
case 'dbname':
$database = (string) $value;
@@ -241,6 +244,9 @@ public function connect()
if (isset($hostname)) {
$dsn[] = "host={$hostname}";
}
+ if (isset($port)) {
+ $dsn[] = "port={$port}";
+ }
break;
}
$dsn = $pdoDriver . ':' . implode(';', $dsn);
@@ -33,6 +33,14 @@ class Date extends DateTimeElement
'type' => 'date',
);
+ /**
+ * Date format to use for DateTime values. By default, this is RFC-3339,
+ * full-date (Y-m-d), which is what HTML5 dictates.
+ *
+ * @var string
+ */
+ protected $format = 'Y-m-d';
+
/**
* Retrieves a Date Validator configured for a DateTime Input type
*
@@ -25,7 +25,7 @@ class TranslatorServiceFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Configure the translator
- $config = $serviceLocator->get('Configuration');
+ $config = $serviceLocator->get('Config');
$trConfig = isset($config['translator']) ? $config['translator'] : array();
$translator = Translator::factory($trConfig);
return $translator;
@@ -15,7 +15,7 @@
use Zend\View\Helper\AbstractHelper;
/**
- * View helper for formatting dates.
+ * View helper for formatting currency.
*
* @category Zend
* @package Zend_I18n
@@ -37,6 +37,13 @@ class CurrencyFormat extends AbstractHelper
*/
protected $currencyCode;
+ /**
+ * If set to true, the currency will be returned with two decimals
+ *
+ * @var bool
+ */
+ protected $showDecimals = true;
+
/**
* Formatter instances.
*
@@ -66,6 +73,28 @@ public function getCurrencyCode()
return $this->currencyCode;
}
+ /**
+ * Set if the view helper should show two decimals
+ *
+ * @param bool $showDecimals
+ * @return CurrencyFormat
+ */
+ public function setShouldShowDecimals($showDecimals)
+ {
+ $this->showDecimals = (bool) $showDecimals;
+ return $this;
+ }
+
+ /**
+ * Get if the view helper should show two decimals
+ *
+ * @return bool
+ */
+ public function shouldShowDecimals()
+ {
+ return $this->showDecimals;
+ }
+
/**
* Set locale to use instead of the default.
*
@@ -97,12 +126,14 @@ public function getLocale()
*
* @param float $number
* @param string $currencyCode
+ * @param bool $showDecimals
* @param string $locale
* @return string
*/
public function __invoke(
$number,
$currencyCode = null,
+ $showDecimals = null,
$locale = null
) {
if (null === $locale) {
@@ -111,6 +142,9 @@ public function __invoke(
if (null === $currencyCode) {
$currencyCode = $this->getCurrencyCode();
}
+ if (null !== $showDecimals) {
+ $this->setShouldShowDecimals($showDecimals);
+ }
$formatterId = md5($locale);
@@ -121,6 +155,12 @@ public function __invoke(
);
}
+ if ($this->shouldShowDecimals()) {
+ $this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
+ } else {
+ $this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
+ }
+
return $this->formatters[$formatterId]->formatCurrency(
$number, $currencyCode
);
@@ -37,7 +37,7 @@ class RouterFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
- $config = $serviceLocator->get('Configuration');
+ $config = $serviceLocator->get('Config');
if (
$rName === 'ConsoleRouter' || // force console router
@@ -41,6 +41,13 @@ class RouteNotFoundStrategy implements ListenerAggregateInterface
*/
protected $listeners = array();
+ /**
+ * Whether or not to display the reason for routing failure
+ *
+ * @var bool
+ */
+ protected $displayNotFoundReason = true;
+
/**
* The reason for a not-found condition
*
@@ -74,6 +81,28 @@ public function detach(EventManagerInterface $events)
}
}
+ /**
+ * Set flag indicating whether or not to display the routing failure
+ *
+ * @param bool $displayNotFoundReason
+ * @return RouteNotFoundStrategy
+ */
+ public function setDisplayNotFoundReason($displayNotFoundReason)
+ {
+ $this->displayNotFoundReason = (bool) $displayNotFoundReason;
+ return $this;
+ }
+
+ /**
+ * Do we display the routing failure?
+ *
+ * @return bool
+ */
+ public function displayNotFoundReason()
+ {
+ return $this->displayNotFoundReason;
+ }
+
/**
* Detect if an error is a route not found condition
*
@@ -162,10 +191,11 @@ public function handleRouteNotFoundError(MvcEvent $e)
// Get application usage information
$usage = $this->getConsoleUsage($console, $scriptName, $mm, $router);
- // Inject the text into view model
+ // Inject the text into view
$result = $banner ? rtrim($banner, "\r\n") : '';
$result .= $usage ? "\n\n" . trim($usage, "\r\n") : '';
$result .= "\n"; // to ensure we output a final newline
+ $result .= $this->reportNotFoundReason($e);
$model->setResult($result);
// Inject the result into MvcEvent
@@ -412,4 +442,36 @@ protected function renderTable($data, $cols, $consoleWidth)
return $table->render();
}
+
+ /**
+ * Report the 404 reason and/or exceptions
+ *
+ * @param \Zend\Event\EventInterface $e
+ * @return string
+ */
+ protected function reportNotFoundReason($e)
+ {
+ if (!$this->displayNotFoundReason()) {
+ return '';
+ }
+ $exception = $e->getParam('exception', false);
+ if (!$exception && !$this->reason) {
+ return '';
+ }
+
+ $reason = (isset($this->reason) && !empty($this->reason)) ? $this->reason : 'unknown';
+ $reasons = array(
+ Application::ERROR_CONTROLLER_NOT_FOUND => 'Could not match to a controller',
+ Application::ERROR_CONTROLLER_INVALID => 'Invalid controller specified',
+ Application::ERROR_ROUTER_NO_MATCH => 'Invalid arguments or no arguments provided',
+ 'unknown' => 'Unknown',
+ );
+ $report = sprintf("\nReason for failure: %s\n", $reasons[$reason]);
+
+ while ($exception instanceof \Exception) {
+ $report .= sprintf("Exception: %s\nTrace:\n%s\n", $exception->getMessage(), $exception->getTraceAsString());
+ $exception = $exception->getPrevious();
+ }
+ return $report;
+ }
}
@@ -146,6 +146,13 @@ public function getRouteNotFoundStrategy()
$this->routeNotFoundStrategy = new RouteNotFoundStrategy();
+ $displayNotFoundReason = true;
+
+ if (array_key_exists('display_not_found_reason', $this->config)) {
+ $displayNotFoundReason = $this->config['display_not_found_reason'];
+ }
+ $this->routeNotFoundStrategy->setDisplayNotFoundReason($displayNotFoundReason);
+
$this->services->setService('RouteNotFoundStrategy', $this->routeNotFoundStrategy);
$this->services->setAlias('Zend\Mvc\View\RouteNotFoundStrategy', 'RouteNotFoundStrategy');
$this->services->setAlias('Zend\Mvc\View\Console\RouteNotFoundStrategy', 'RouteNotFoundStrategy');
@@ -56,7 +56,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
protected function getPages(ServiceLocatorInterface $serviceLocator)
{
if (null === $this->pages) {
- $configuration = $serviceLocator->get('Configuration');
+ $configuration = $serviceLocator->get('Config');
if (!isset($configuration['navigation'])) {
throw new Exception\InvalidArgumentException('Could not find navigation configuration key');
@@ -385,7 +385,11 @@ public function setShared($name, $isShared)
{
$cName = $this->canonicalizeName($name);
- if (!isset($this->invokableClasses[$cName]) && !isset($this->factories[$cName])) {
+ if (
+ !isset($this->invokableClasses[$cName])
+ && !isset($this->factories[$cName])
+ && !$this->canCreateFromAbstractFactory($cName, $name)
+ ) {
throw new Exception\ServiceNotFoundException(sprintf(
'%s: A service by the name "%s" was not found and could not be marked as shared',
__METHOD__,
@@ -15,6 +15,7 @@
*
* @category Zend
* @package Zend_Stdlib
+ * @subpackage Exception
*/
class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
{
@@ -10,6 +10,13 @@
namespace Zend\Stdlib\Exception;
+/**
+ * Domain exception
+ *
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage Exception
+ */
class DomainException extends \DomainException implements ExceptionInterface
{
}
@@ -10,6 +10,13 @@
namespace Zend\Stdlib\Exception;
+/**
+ * Exception marker interface
+ *
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage Exception
+ */
interface ExceptionInterface
{
}
@@ -10,6 +10,13 @@
namespace Zend\Stdlib\Exception;
+/**
+ * Invalid Argument Exception
+ *
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage Exception
+ */
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
@@ -15,6 +15,7 @@
*
* @category Zend
* @package Zend_Stdlib
+ * @subpackage Exception
*/
class InvalidCallbackException extends DomainException implements ExceptionInterface
{
@@ -11,10 +11,11 @@
namespace Zend\Stdlib\Exception;
/**
- * logic exception
+ * Logic exception
*
* @category Zend
* @package Zend_Stdlib
+ * @subpackage Exception
*/
class LogicException extends \LogicException implements ExceptionInterface
{
@@ -13,6 +13,11 @@
use ReflectionClass;
use Zend\Stdlib\Exception;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage Hydrator
+ */
class Reflection extends AbstractHydrator
{
/**
Oops, something went wrong.

0 comments on commit 2f41c1b

Please sign in to comment.