Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated for latest master

  • Loading branch information...
commit 7e985d7655741a9051b9c45f551d45955e43f9eb 2 parents 25b521a + de807ff
@bakura10 bakura10 authored
Showing with 1,293 additions and 709 deletions.
  1. +40 −0 README.md
  2. +2 −2 composer.json
  3. +7 −26 library/Zend/Db/Adapter/Adapter.php
  4. +11 −1 library/Zend/Db/Adapter/Driver/Mysqli/Result.php
  5. +10 −2 library/Zend/Db/Adapter/Driver/Pdo/Result.php
  6. +6 −2 library/Zend/Db/Adapter/Driver/Pgsql/Result.php
  7. +1 −1  library/Zend/Db/Adapter/Driver/Pgsql/Statement.php
  8. +1 −0  library/Zend/Db/Adapter/Driver/ResultInterface.php
  9. +8 −0 library/Zend/Db/Adapter/Driver/Sqlsrv/Result.php
  10. +67 −7 library/Zend/Db/ResultSet/AbstractResultSet.php
  11. +3 −0  library/Zend/Db/RowGateway/AbstractRowGateway.php
  12. +10 −1 library/Zend/Db/Sql/Select.php
  13. +44 −9 library/Zend/Form/Element/Csrf.php
  14. +69 −3 library/Zend/Form/Element/MultiCheckbox.php
  15. +1 −1  library/Zend/Form/Element/Radio.php
  16. +76 −11 library/Zend/Form/Element/Select.php
  17. +16 −10 library/Zend/Form/Factory.php
  18. +4 −0 library/Zend/Form/Form.php
  19. +4 −5 library/Zend/Form/View/Helper/FormElement.php
  20. +21 −18 library/Zend/Form/View/Helper/FormMultiCheckbox.php
  21. +36 −0 library/Zend/Form/View/Helper/FormReset.php
  22. +41 −6 library/Zend/Form/View/Helper/FormRow.php
  23. +13 −9 library/Zend/Form/View/Helper/FormSelect.php
  24. +36 −0 library/Zend/Form/View/Helper/FormSubmit.php
  25. +10 −0 library/Zend/Http/PhpEnvironment/Request.php
  26. +4 −4 library/Zend/I18n/Translator/Loader/{LoaderInterface.php → FileLoaderInterface.php}
  27. +5 −5 library/Zend/I18n/Translator/Loader/Gettext.php
  28. +5 −5 library/Zend/I18n/Translator/Loader/PhpArray.php
  29. +30 −0 library/Zend/I18n/Translator/Loader/RemoteLoaderInterface.php
  30. +9 −8 library/Zend/I18n/Translator/LoaderPluginManager.php
  31. +91 −15 library/Zend/I18n/Translator/Translator.php
  32. +4 −6 library/Zend/Log/Writer/Syslog.php
  33. +6 −2 library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
  34. +0 −67 library/Zend/Paginator/AdapterPluginManager.php
  35. +1 −87 library/Zend/Paginator/Paginator.php
  36. +11 −0 library/Zend/Stdlib/Hydrator/ClassMethods.php
  37. +7 −4 library/Zend/Validator/Csrf.php
  38. +7 −21 tests/ZendTest/Db/Adapter/AdapterTest.php
  39. +23 −0 tests/ZendTest/Db/ResultSet/ResultSetTest.php
  40. +35 −0 tests/ZendTest/Db/RowGateway/AbstractRowGatewayTest.php
  41. +13 −1 tests/ZendTest/Db/Sql/SelectTest.php
  42. +17 −0 tests/ZendTest/Form/Element/CsrfTest.php
  43. +23 −10 tests/ZendTest/Form/Element/SelectTest.php
  44. +12 −0 tests/ZendTest/Form/FactoryTest.php
  45. +2 −2 tests/ZendTest/Form/FormTest.php
  46. +12 −2 tests/ZendTest/Form/View/Helper/FormElementTest.php
  47. +14 −14 tests/ZendTest/Form/View/Helper/FormMultiCheckboxTest.php
  48. +8 −8 tests/ZendTest/Form/View/Helper/FormRadioTest.php
  49. +21 −0 tests/ZendTest/Form/View/Helper/FormResetTest.php
  50. +14 −1 tests/ZendTest/Form/View/Helper/FormRowTest.php
  51. +13 −13 tests/ZendTest/Form/View/Helper/FormSelectTest.php
  52. +20 −0 tests/ZendTest/Form/View/Helper/FormSubmitTest.php
  53. +31 −1 tests/ZendTest/Http/PhpEnvironment/RequestTest.php
  54. +6 −7 tests/ZendTest/I18n/Translator/Loader/GettextTest.php
  55. +5 −6 tests/ZendTest/I18n/Translator/Loader/PhpArrayTest.php
  56. +2 −2 tests/ZendTest/I18n/Translator/TestAsset/Loader.php
  57. +1 −1  tests/ZendTest/I18n/Validator/FloatTest.php
  58. +19 −0 tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
  59. +8 −8 tests/ZendTest/Paginator/Adapter/ArrayTest.php
  60. +12 −11 tests/ZendTest/Paginator/Adapter/IteratorTest.php
  61. +11 −11 tests/ZendTest/Paginator/Adapter/NullTest.php
  62. +23 −114 tests/ZendTest/Paginator/PaginatorTest.php
  63. +21 −18 tests/ZendTest/Paginator/ScrollingStyle/AllTest.php
  64. +38 −35 tests/ZendTest/Paginator/ScrollingStyle/ElasticTest.php
  65. +34 −31 tests/ZendTest/Paginator/ScrollingStyle/JumpingTest.php
  66. +28 −25 tests/ZendTest/Paginator/ScrollingStyle/SlidingTest.php
  67. +0 −22 tests/ZendTest/Paginator/TestAsset/AdapterPluginManager.php
  68. +0 −19 tests/ZendTest/Paginator/TestAsset/TestTable.php
  69. +36 −2 tests/ZendTest/Stdlib/HydratorTest.php
  70. +26 −0 tests/ZendTest/Stdlib/TestAsset/ClassMethodsCamelCase.php
  71. +26 −0 tests/ZendTest/Stdlib/TestAsset/ClassMethodsUnderscore.php
  72. +17 −3 tests/ZendTest/Validator/CsrfTest.php
  73. +1 −1  tests/ZendTest/Validator/TestAsset/ArrayTranslator.php
  74. +3 −2 tests/ZendTest/View/Helper/PaginationControlTest.php
  75. +1 −1  tests/ZendTest/View/Helper/TestAsset/ArrayTranslator.php
View
40 README.md
@@ -15,6 +15,36 @@ XX August 2012
### UPDATES IN RC6
+- Zend\Db
+ - ResultInterface adds isBuffered() method for checking if the resultset is
+ buffered or not. Allows for more fine grained control of result set
+ buffering, including using the database engine's native buffering.
+- Zend\Form
+ - You can now omit error messages on elements when rendering via formRow(), by
+ passing a boolean false as the third argument of the helper.
+ - You can now use concrete hydrator instances with the factory.
+ - You may now set the CSRF validator class and/or options to use on the Csrf
+ element
+ - The Select, Radio, and MultiCheckbox elements and view helpers were
+ refactored to move value options into properties, instead of attributes.
+ This makes them more consistent with other elements, and simplifies the
+ interfaces.
+ - Forms now lazy-load an input filter if none has been specified; this should
+ simplify usage for many, and remove the "no input filter attached"
+ exception.
+ - All form helpers for buttons (button, submit, reset) now allow translation.
+- Zend\Http
+ - Some browser/web server combingations set SERVER_NAME to the IPv6 address,
+ and enclose it in brackets. The PhpEnvironment\Request object now correctly
+ detects such situations.
+- Zend\I18n\Translator
+ - Loader\LoaderInterface was splitted into Loader\FileLoaderInterface and
+ Loader\RemoteLoaderInterface. The latter one will be used in ZF 2.1 for
+ a database loader.
+ - Translator::addTranslationPattern() and the option "translation_patterns"
+ were renamed to Translator::addTranslationFilePattern and
+ "translation_file_patterns".
+ - A new method Translator::addRemoteTranslations() was added.
- Zend\Mvc
- Application no longer defines the "application" identifier for its composed
EventManager instance. If you had listeners listening on that context,
@@ -22,6 +52,16 @@ XX August 2012
http://zend-framework-community.634137.n4.nabble.com/Change-to-Zend-Mvc-Application-s-event-identifiers-tp4656517.html
+ - The PRG plugin now allows passing no arguments; if you do so, the currently
+ matched route will be used for the redirect.
+- Zend\Paginator
+ - Removes the factory() and related methods. This was done to be more
+ consistent with other components, and also because the utility was not
+ terribly useful; in most cases, developers needed to configure the adapter
+ up-front anyways.
+- Zend\Stdlib
+ - ClassMethods Hydrator now supports boolean getters prefixed with "is"
+
More than XX pull requests for a variety of features and bugfixes were handled
since RC5, as well as around XX documentation changes!
View
4 composer.json
@@ -23,8 +23,8 @@
},
"autoload": {
"psr-0": {
- "Zend": "library/",
- "ZendTest": "tests/"
+ "Zend\\": "library/",
+ "ZendTest\\": "tests/"
}
},
"config": {
View
33 library/Zend/Db/Adapter/Adapter.php
@@ -51,16 +51,11 @@ class Adapter
protected $platform = null;
/**
- * @var \Zend\Db\ResultSet\ResultSet
+ * @var ResultSet\ResultSetInterface
*/
protected $queryResultSetPrototype = null;
/**
- * @var string
- */
- protected $queryMode = self::QUERY_MODE_PREPARE;
-
- /**
* @var Driver\StatementInterface
*/
protected $lastPreparedStatement = null;
@@ -106,33 +101,19 @@ public function getDriver()
}
/**
- * @param string $queryMode
- * @return Adapter
- * @throws \InvalidArgumentException
+ * @return Platform\PlatformInterface
*/
- public function setQueryMode($queryMode)
- {
- if (!in_array($queryMode, array(self::QUERY_MODE_EXECUTE, self::QUERY_MODE_PREPARE))) {
- throw new Exception\InvalidArgumentException(
- sprintf('Query Mode must be one of "%s" or "%s"', self::QUERY_MODE_EXECUTE, self::QUERY_MODE_PREPARE)
- );
- }
-
- $this->queryMode = $queryMode;
- return $this;
- }
-
- public function getQueryMode()
+ public function getPlatform()
{
- return $this->queryMode;
+ return $this->platform;
}
/**
- * @return Platform\PlatformInterface
+ * @return ResultSet\ResultSetInterface
*/
- public function getPlatform()
+ public function getQueryResultSetPrototype()
{
- return $this->platform;
+ return $this->queryResultSetPrototype;
}
public function getCurrentSchema()
View
12 library/Zend/Db/Adapter/Driver/Mysqli/Result.php
@@ -113,6 +113,14 @@ public function buffer()
}
/**
+ * @return bool|null
+ */
+ public function isBuffered()
+ {
+ return $this->isBuffered;
+ }
+
+ /**
* Return the resource
* @return mixed
*/
@@ -192,7 +200,9 @@ protected function loadDataFromMysqliStatement()
}
if (($r = $this->resource->fetch()) === null) {
- $this->resource->close();
+ if (!$this->isBuffered) {
+ $this->resource->close();
+ }
return false;
} elseif ($r === false) {
throw new Exception\RuntimeException($this->resource->error);
View
12 library/Zend/Db/Adapter/Driver/Pdo/Result.php
@@ -53,7 +53,7 @@ class Result implements Iterator, ResultInterface
* Track current item in recordset
* @var mixed
*/
- protected $currentData;
+ protected $currentData = null;
/**
* Current position of scrollable statement
@@ -96,6 +96,14 @@ public function buffer()
}
/**
+ * @return bool|null
+ */
+ public function isBuffered()
+ {
+ return false;
+ }
+
+ /**
* Get resource
*
* @return mixed
@@ -164,7 +172,7 @@ public function rewind()
*/
public function valid()
{
- return ($this->currentData != false);
+ return ($this->currentData !== false);
}
/**
View
8 library/Zend/Db/Adapter/Driver/Pgsql/Result.php
@@ -34,7 +34,6 @@ class Result implements ResultInterface
public function initialize($resource, $generatedValue)
{
if (!is_resource($resource) || get_resource_type($resource) != 'pgsql result') {
- var_dump($resource); debug_print_backtrace();
throw new \Exception('Resource not of the correct type.');
}
@@ -73,7 +72,12 @@ public function rewind()
public function buffer()
{
- // @todo
+ return null;
+ }
+
+ public function isBuffered()
+ {
+ return false;
}
public function isQueryResult()
View
2  library/Zend/Db/Adapter/Driver/Pgsql/Statement.php
@@ -180,7 +180,7 @@ public function execute($parameters = null)
}
/** END Standard ParameterContainer Merging Block */
- $resultResource = pg_execute($this->pgsql, $this->statementName, $parameters);
+ $resultResource = pg_execute($this->pgsql, $this->statementName, (array) $parameters);
if ($resultResource === false) {
throw new Exception\InvalidQueryException(pg_last_error());
View
1  library/Zend/Db/Adapter/Driver/ResultInterface.php
@@ -18,6 +18,7 @@
interface ResultInterface extends \Countable, \Iterator
{
public function buffer();
+ public function isBuffered();
public function isQueryResult();
public function getAffectedRows();
public function getGeneratedValue();
View
8 library/Zend/Db/Adapter/Driver/Sqlsrv/Result.php
@@ -70,6 +70,14 @@ public function buffer()
}
/**
+ * @return bool
+ */
+ public function isBuffered()
+ {
+ return false;
+ }
+
+ /**
* Get resource
*
* @return resource
View
74 library/Zend/Db/ResultSet/AbstractResultSet.php
@@ -24,13 +24,24 @@
*/
abstract class AbstractResultSet implements Iterator, ResultSetInterface
{
+
+ /**
+ * if -1, datasource is already buffered
+ * if -2, implicitly disabling buffering in ResultSet
+ * if false, explicitly disabled
+ * if null, default state - nothing, but can buffer until iteration started
+ * if array, already buffering
+ * @var mixed
+ */
+ protected $buffer = null;
+
/**
* @var null|int
*/
protected $count = null;
/**
- * @var Iterator|IteratorAggregate
+ * @var Iterator|IteratorAggregate|ResultInterface
*/
protected $dataSource = null;
@@ -39,6 +50,7 @@
*/
protected $fieldCount = null;
+ protected $position = null;
/**
* Set the data source for the result set
@@ -53,6 +65,9 @@ public function initialize($dataSource)
$this->count = $dataSource->count();
$this->fieldCount = $dataSource->getFieldCount();
$this->dataSource = $dataSource;
+ if ($dataSource->isBuffered()) {
+ $this->buffer = -1;
+ }
return $this;
}
@@ -63,6 +78,7 @@ public function initialize($dataSource)
$this->count = count($dataSource);
$this->fieldCount = count($first);
$this->dataSource = new ArrayIterator($dataSource);
+ $this->buffer = -1; // array's are a natural buffer
} elseif ($dataSource instanceof IteratorAggregate) {
$this->dataSource = $dataSource->getIterator();
} elseif ($dataSource instanceof Iterator) {
@@ -78,6 +94,23 @@ public function initialize($dataSource)
return $this;
}
+ public function buffer()
+ {
+ if ($this->buffer === -2) {
+ throw new Exception\RuntimeException('Buffering must be enabled before iteration is started');
+ } elseif ($this->buffer === null) {
+ $this->buffer = array();
+ }
+ }
+
+ public function isBuffered()
+ {
+ if ($this->buffer === -1 || is_array($this->buffer)) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Get the data source used to create the result set
*
@@ -128,7 +161,11 @@ public function getFieldCount()
*/
public function next()
{
+ if ($this->buffer === null) {
+ $this->buffer = -2; // implicitly disable buffering from here on
+ }
$this->dataSource->next();
+ $this->position++;
}
/**
@@ -138,7 +175,7 @@ public function next()
*/
public function key()
{
- return $this->dataSource->key();
+ return $this->position;
}
/**
@@ -148,7 +185,16 @@ public function key()
*/
public function current()
{
- return $this->dataSource->current();
+ if ($this->buffer === null) {
+ $this->buffer = -2; // implicitly disable buffering from here on
+ } elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {
+ return $this->buffer[$this->position];
+ }
+ $data = $this->dataSource->current();
+ if (is_array($this->buffer)) {
+ $this->buffer[$this->position] = $data;
+ }
+ return $data;
}
/**
@@ -158,7 +204,16 @@ public function current()
*/
public function valid()
{
- return $this->dataSource->valid();
+ if (is_array($this->buffer) && isset($this->buffer[$this->position])) {
+ return true;
+ }
+ if ($this->dataSource instanceof Iterator) {
+ return $this->dataSource->valid();
+ } else {
+ $key = key($this->dataSource);
+ return ($key !== null);
+ }
+
}
/**
@@ -168,8 +223,14 @@ public function valid()
*/
public function rewind()
{
- $this->dataSource->rewind();
- // return void
+ if (!is_array($this->buffer)) {
+ if ($this->dataSource instanceof Iterator) {
+ $this->dataSource->rewind();
+ } else {
+ reset($this->dataSource);
+ }
+ }
+ $this->position = 0;
}
/**
@@ -195,7 +256,6 @@ public function count()
public function toArray()
{
$return = array();
- // @todo determine if its necessary to cast rows, shouldn't they all be arrays? speed counts.
foreach ($this as $row) {
if (is_array($row)) {
$return[] = $row;
View
3  library/Zend/Db/RowGateway/AbstractRowGateway.php
@@ -164,6 +164,9 @@ public function save()
$result = $statement->execute();
if (($primaryKeyValue = $result->getGeneratedValue()) && count($this->primaryKeyColumn) == 1) {
$this->primaryKeyData = array($this->primaryKeyColumn[0] => $primaryKeyValue);
+ } else {
+ // make primary key data available so that $where can be complete
+ $this->processPrimaryKeyData();
}
$rowsAffected = $result->getAffectedRows();
unset($statement, $result); // cleanup
View
11 library/Zend/Db/Sql/Select.php
@@ -72,7 +72,7 @@ class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface
self::HAVING => 'HAVING %1$s',
self::ORDER => array(
'ORDER BY %1$s' => array(
- array(2 => '%1$s %2$s', 'combinedby' => ', ')
+ array(1 => '%1$s', 2 => '%1$s %2$s', 'combinedby' => ', ')
)
),
self::LIMIT => 'LIMIT %1$s',
@@ -676,6 +676,15 @@ protected function processOrder(PlatformInterface $platform, Adapter $adapter =
}
$orders = array();
foreach ($this->order as $k => $v) {
+ if ($v instanceof Expression) {
+ /** @var $orderParts \Zend\Db\Adapter\StatementContainer */
+ $orderParts = $this->processExpression($v, $platform, $adapter);
+ if ($parameterContainer) {
+ $parameterContainer->merge($orderParts->getParameterContainer());
+ }
+ $orders[] = array($orderParts->getSql());
+ continue;
+ }
if (is_int($k)) {
if (strpos($v, ' ') !== false) {
list($k, $v) = preg_split('# #', $v, 2);
View
53 library/Zend/Form/Element/Csrf.php
@@ -33,21 +33,56 @@ class Csrf extends Element implements InputProviderInterface, ElementPrepareAwar
);
/**
+ * @var array
+ */
+ protected $csrfValidatorOptions = array();
+
+ /**
* @var CsrfValidator
*/
- protected $validator;
+ protected $csrfValidator;
+
+ /**
+ * @return array
+ */
+ public function getCsrfValidatorOptions()
+ {
+ return $this->csrfValidatorOptions;
+ }
+
+ /**
+ * @param array $options
+ * @return Csrf
+ */
+ public function setCsrfValidatorOptions(array $options)
+ {
+ $this->csrfValidatorOptions = $options;
+ return $this;
+ }
/**
* Get CSRF validator
*
* @return CsrfValidator
*/
- protected function getValidator()
+ public function getCsrfValidator()
{
- if (null === $this->validator) {
- $this->validator = new CsrfValidator(array('name' => $this->getName()));
+ if (null === $this->csrfValidator) {
+ $csrfOptions = $this->getCsrfValidatorOptions();
+ $csrfOptions = array_merge($csrfOptions, array('name' => $this->getName()));
+ $this->csrfValidator = new CsrfValidator($csrfOptions);
}
- return $this->validator;
+ return $this->csrfValidator;
+ }
+
+ /**
+ * @param \Zend\Validator\Csrf $validator
+ * @return Csrf
+ */
+ public function setCsrfValidator(CsrfValidator $validator)
+ {
+ $this->csrfValidator = $validator;
+ return $this;
}
/**
@@ -59,7 +94,7 @@ protected function getValidator()
*/
public function getValue()
{
- $validator = $this->getValidator();
+ $validator = $this->getCsrfValidator();
return $validator->getHash();
}
@@ -73,7 +108,7 @@ public function getValue()
public function getAttributes()
{
$attributes = parent::getAttributes();
- $validator = $this->getValidator();
+ $validator = $this->getCsrfValidator();
$attributes['value'] = $validator->getHash();
return $attributes;
}
@@ -94,7 +129,7 @@ public function getInputSpecification()
array('name' => 'Zend\Filter\StringTrim'),
),
'validators' => array(
- $this->getValidator(),
+ $this->getCsrfValidator(),
),
);
}
@@ -104,6 +139,6 @@ public function getInputSpecification()
*/
public function prepareElement(Form $form)
{
- $this->getValidator()->getHash(true);
+ $this->getCsrfValidator()->getHash(true);
}
}
View
72 library/Zend/Form/Element/MultiCheckbox.php
@@ -32,6 +32,72 @@ class MultiCheckbox extends Checkbox
protected $uncheckedValue = '';
/**
+ * @var array
+ */
+ protected $valueOptions = array();
+
+ /**
+ * @return array
+ */
+ public function getValueOptions()
+ {
+ return $this->valueOptions;
+ }
+
+ /**
+ * @param array $options
+ * @return MultiCheckbox
+ */
+ public function setValueOptions(array $options)
+ {
+ $this->valueOptions = $options;
+ return $this;
+ }
+
+ /**
+ * Set options for an element. Accepted options are:
+ * - label: label to associate with the element
+ * - label_attributes: attributes to use when the label is rendered
+ * - value_options: list of values and labels for the select options
+ *
+ * @param array|\Traversable $options
+ * @return MultiCheckbox|ElementInterface
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setOptions($options)
+ {
+ parent::setOptions($options);
+
+ if (isset($this->options['value_options'])) {
+ $this->setValueOptions($this->options['value_options']);
+ }
+ // Alias for 'value_options'
+ if (isset($this->options['options'])) {
+ $this->setValueOptions($this->options['options']);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Set a single element attribute
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return MultiCheckbox|ElementInterface
+ */
+ public function setAttribute($key, $value)
+ {
+ // Do not include the options in the list of attributes
+ // TODO: Deprecate this
+ if ($key === 'options') {
+ $this->setValueOptions($value);
+ return $this;
+ }
+ return parent::setAttribute($key, $value);
+ }
+
+ /**
* Get validator
*
* @return ValidatorInterface
@@ -40,7 +106,7 @@ protected function getValidator()
{
if (null === $this->validator) {
$inArrayValidator = new InArrayValidator(array(
- 'haystack' => $this->getOptionAttributeValues(),
+ 'haystack' => $this->getValueOptionsValues(),
'strict' => false,
));
$this->validator = new ExplodeValidator(array(
@@ -56,10 +122,10 @@ protected function getValidator()
*
* @return array
*/
- protected function getOptionAttributeValues()
+ protected function getValueOptionsValues()
{
$values = array();
- $options = $this->getAttribute('options');
+ $options = $this->getValueOptions();
foreach ($options as $key => $optionSpec) {
$value = (is_array($optionSpec)) ? $optionSpec['value'] : $key;
$values[] = $value;
View
2  library/Zend/Form/Element/Radio.php
@@ -38,7 +38,7 @@ protected function getValidator()
{
if (null === $this->validator) {
$this->validator = new InArrayValidator(array(
- 'haystack' => $this->getOptionAttributeValues(),
+ 'haystack' => $this->getValueOptionsValues(),
'strict' => false,
));
}
View
87 library/Zend/Form/Element/Select.php
@@ -43,25 +43,90 @@ class Select extends Element implements InputProviderInterface
* @var array
*/
protected $attributes = array(
- 'type' => 'select',
- 'options' => array(),
+ 'type' => 'select',
);
/**
- * @var ValidatorInterface
- */
+ * @var ValidatorInterface
+ */
protected $validator;
/**
- * Get validator
- *
- * @return ValidatorInterface
- */
+ * @var array
+ */
+ protected $valueOptions = array();
+
+ /**
+ * @return array
+ */
+ public function getValueOptions()
+ {
+ return $this->valueOptions;
+ }
+
+ /**
+ * @param array $options
+ * @return Select
+ */
+ public function setValueOptions(array $options)
+ {
+ $this->valueOptions = $options;
+ return $this;
+ }
+
+ /**
+ * Set options for an element. Accepted options are:
+ * - label: label to associate with the element
+ * - label_attributes: attributes to use when the label is rendered
+ * - value_options: list of values and labels for the select options
+ *
+ * @param array|\Traversable $options
+ * @return Select|ElementInterface
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setOptions($options)
+ {
+ parent::setOptions($options);
+
+ if (isset($this->options['value_options'])) {
+ $this->setValueOptions($this->options['value_options']);
+ }
+ // Alias for 'value_options'
+ if (isset($this->options['options'])) {
+ $this->setValueOptions($this->options['options']);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Set a single element attribute
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return Select|ElementInterface
+ */
+ public function setAttribute($key, $value)
+ {
+ // Do not include the options in the list of attributes
+ // TODO: Deprecate this
+ if ($key === 'options') {
+ $this->setValueOptions($value);
+ return $this;
+ }
+ return parent::setAttribute($key, $value);
+ }
+
+ /**
+ * Get validator
+ *
+ * @return ValidatorInterface
+ */
protected function getValidator()
{
if (null === $this->validator) {
$validator = new InArrayValidator(array(
- 'haystack' => $this->getOptionAttributeValues(),
+ 'haystack' => $this->getValueOptionsValues(),
'strict' => false
));
@@ -105,10 +170,10 @@ public function getInputSpecification()
*
* @return array
*/
- protected function getOptionAttributeValues()
+ protected function getValueOptionsValues()
{
$values = array();
- $options = $this->getAttribute('options');
+ $options = $this->getValueOptions();
foreach ($options as $key => $optionSpec) {
$value = (is_array($optionSpec)) ? $optionSpec['value'] : $key;
$values[] = $value;
View
26 library/Zend/Form/Factory.php
@@ -348,39 +348,45 @@ protected function prepareAndInjectObject($objectName, FieldsetInterface $fields
/**
* Prepare and inject a named hydrator
*
- * Takes a string indicating a hydrator class name, instantiates the class
+ * Takes a string indicating a hydrator class name (or a concrete instance), instantiates the class
* by that name, and injects the hydrator instance into the form.
*
- * @param string $hydratorName
+ * @param string $hydratorOrName
* @param FieldsetInterface $fieldset
* @param string $method
* @return void
- * @throws Exception\DomainException if $hydratorName is not a string, does not resolve to a known class, or the class does not implement Hydrator\HydratorInterface
+ * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or
+ * the class does not implement Hydrator\HydratorInterface
*/
- protected function prepareAndInjectHydrator($hydratorName, FieldsetInterface $fieldset, $method)
+ protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method)
{
- if (!is_string($hydratorName)) {
+ if (is_object($hydratorOrName) && $hydratorOrName instanceof Hydrator\HydratorInterface) {
+ $fieldset->setHydrator($hydratorOrName);
+ return;
+ }
+
+ if (!is_string($hydratorOrName)) {
throw new Exception\DomainException(sprintf(
'%s expects string hydrator class name; received "%s"',
$method,
- (is_object($hydratorName) ? get_class($hydratorName) : gettype($hydratorName))
+ (is_object($hydratorOrName) ? get_class($hydratorOrName) : gettype($hydratorOrName))
));
}
- if (!class_exists($hydratorName)) {
+ if (!class_exists($hydratorOrName)) {
throw new Exception\DomainException(sprintf(
'%s expects string hydrator name to be a valid class name; received "%s"',
$method,
- $hydratorName
+ $hydratorOrName
));
}
- $hydrator = new $hydratorName;
+ $hydrator = new $hydratorOrName;
if (!$hydrator instanceof Hydrator\HydratorInterface) {
throw new Exception\DomainException(sprintf(
'%s expects a valid implementation of Zend\Form\Hydrator\HydratorInterface; received "%s"',
$method,
- $hydratorName
+ $hydratorOrName
));
}
View
4 library/Zend/Form/Form.php
@@ -577,6 +577,10 @@ public function getInputFilter()
}
}
+ if (null === $this->filter) {
+ $this->filter = new InputFilter();
+ }
+
if ($this->filter instanceof InputFilterInterface && $this->useInputFilterDefaults()) {
$this->attachInputFilterDefaults($this->filter, $this);
}
View
9 library/Zend/Form/View/Helper/FormElement.php
@@ -68,8 +68,7 @@ public function render(ElementInterface $element)
return $helper($element);
}
- $type = $element->getAttribute('type');
- $options = $element->getAttribute('options');
+ $type = $element->getAttribute('type');
if ('checkbox' == $type) {
$helper = $renderer->plugin('form_checkbox');
@@ -121,7 +120,7 @@ public function render(ElementInterface $element)
return $helper($element);
}
- if ('multi_checkbox' == $type && is_array($options)) {
+ if ('multi_checkbox' == $type) {
$helper = $renderer->plugin('form_multi_checkbox');
return $helper($element);
}
@@ -136,7 +135,7 @@ public function render(ElementInterface $element)
return $helper($element);
}
- if ('radio' == $type && is_array($options)) {
+ if ('radio' == $type) {
$helper = $renderer->plugin('form_radio');
return $helper($element);
}
@@ -156,7 +155,7 @@ public function render(ElementInterface $element)
return $helper($element);
}
- if ('select' == $type && is_array($options)) {
+ if ('select' == $type) {
$helper = $renderer->plugin('form_select');
return $helper($element);
}
View
39 library/Zend/Form/View/Helper/FormMultiCheckbox.php
@@ -12,6 +12,7 @@
use Traversable;
use Zend\Form\ElementInterface;
+use Zend\Form\Element\MultiCheckbox as MultiCheckboxElement;
use Zend\Form\Exception;
/**
@@ -190,6 +191,13 @@ public function setUncheckedValue($value)
*/
public function render(ElementInterface $element)
{
+ if (!$element instanceof MultiCheckboxElement) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ '%s requires that the element is of type Zend\Form\Element\MultiCheckbox',
+ __METHOD__
+ ));
+ }
+
$name = static::getName($element);
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf(
@@ -198,20 +206,15 @@ public function render(ElementInterface $element)
));
}
- $attributes = $element->getAttributes();
-
- if (!isset($attributes['options'])
- || (!is_array($attributes['options']) && !$attributes['options'] instanceof Traversable)
- ) {
+ $options = $element->getValueOptions();
+ if (empty($options)) {
throw new Exception\DomainException(sprintf(
- '%s requires that the element has an array or Traversable "options" attribute; none found',
+ '%s requires that the element has "value_options"; none found',
__METHOD__
));
}
- $options = $attributes['options'];
- unset($attributes['options']);
-
+ $attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getInputType();
$selectedOptions = (array) $element->getValue();
@@ -233,13 +236,13 @@ public function render(ElementInterface $element)
/**
* Render options
*
- * @param ElementInterface $element
- * @param array $options
- * @param array $selectedOptions
- * @param array $attributes
+ * @param MultiCheckboxElement $element
+ * @param array $options
+ * @param array $selectedOptions
+ * @param array $attributes
* @return string
*/
- protected function renderOptions(ElementInterface $element, array $options, array $selectedOptions,
+ protected function renderOptions(MultiCheckboxElement $element, array $options, array $selectedOptions,
array $attributes)
{
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
@@ -263,7 +266,7 @@ protected function renderOptions(ElementInterface $element, array $options, arra
}
$value = '';
- $label = $key;
+ $label = '';
$selected = false;
$disabled = false;
$inputAttributes = $attributes;
@@ -339,11 +342,11 @@ protected function renderOptions(ElementInterface $element, array $options, arra
/**
* Render a hidden element for empty/unchecked value
*
- * @param ElementInterface $element
- * @param array $attributes
+ * @param MultiCheckboxElement $element
+ * @param array $attributes
* @return string
*/
- protected function renderHiddenElement(ElementInterface $element, array $attributes)
+ protected function renderHiddenElement(MultiCheckboxElement $element, array $attributes)
{
$closingBracket = $this->getInlineClosingBracket();
View
36 library/Zend/Form/View/Helper/FormReset.php
@@ -11,6 +11,7 @@
namespace Zend\Form\View\Helper;
use Zend\Form\ElementInterface;
+use Zend\Form\Exception;
/**
* @category Zend
@@ -43,4 +44,39 @@ protected function getType(ElementInterface $element)
{
return 'reset';
}
+
+ /**
+ * Render a form <input> element from the provided $element
+ *
+ * @param ElementInterface $element
+ * @return string
+ */
+ public function render(ElementInterface $element)
+ {
+ $name = $element->getName();
+ if ($name === null || $name === '') {
+ throw new Exception\DomainException(sprintf(
+ '%s requires that the element has an assigned name; none discovered',
+ __METHOD__
+ ));
+ }
+
+ $resetValue = $element->getValue();
+ if (null !== ($translator = $this->getTranslator())) {
+ $resetValue = $translator->translate(
+ $resetValue, $this->getTranslatorTextDomain()
+ );
+ }
+
+ $attributes = $element->getAttributes();
+ $attributes['name'] = $name;
+ $attributes['type'] = $this->getType($element);
+ $attributes['value'] = $resetValue;
+
+ return sprintf(
+ '<input %s%s',
+ $this->createAttributesString($attributes),
+ $this->getInlineClosingBracket()
+ );
+ }
}
View
47 library/Zend/Form/View/Helper/FormRow.php
@@ -30,6 +30,11 @@ class FormRow extends AbstractHelper
protected $labelPosition = self::LABEL_PREPEND;
/**
+ * @var bool
+ */
+ protected $renderErrors = true;
+
+ /**
* @var array
*/
protected $labelAttributes;
@@ -65,7 +70,6 @@ public function render(ElementInterface $element)
$elementErrorsHelper = $this->getElementErrorsHelper();
$label = $element->getLabel();
$elementString = $elementHelper->render($element);
- $elementErrors = $elementErrorsHelper->render($element);
if (!empty($label)) {
$label = $escapeHtmlHelper($label);
@@ -95,16 +99,24 @@ public function render(ElementInterface $element)
switch ($this->labelPosition) {
case self::LABEL_PREPEND:
- $markup = $labelOpen . $label . $elementString . $labelClose . $elementErrors;
+ $markup = $labelOpen . '<span>' . $label . '</span>'. $elementString . $labelClose;
break;
case self::LABEL_APPEND:
default:
- $markup = $labelOpen . $elementString . $label . $labelClose . $elementErrors;
+ $markup = $labelOpen . $elementString . '<span>' . $label . '</span>' . $labelClose;
break;
}
+
+ if ($this->renderErrors) {
+ $markup .= $elementErrorsHelper->render($element);
+ }
}
} else {
- $markup = $elementString . $elementErrors;
+ if ($this->renderErrors) {
+ $markup = $elementString . $elementErrorsHelper->render($element);
+ } else {
+ $markup = $elementString;
+ }
}
return $markup;
@@ -116,10 +128,11 @@ public function render(ElementInterface $element)
* Proxies to {@link render()}.
*
* @param null|ElementInterface $element
- * @param null|string $labelPosition
+ * @param null|string $labelPosition
+ * @param bool $renderErrors
* @return string|FormRow
*/
- public function __invoke(ElementInterface $element = null, $labelPosition = null)
+ public function __invoke(ElementInterface $element = null, $labelPosition = null, $renderErrors = true)
{
if (!$element) {
return $this;
@@ -129,6 +142,8 @@ public function __invoke(ElementInterface $element = null, $labelPosition = null
$this->setLabelPosition($labelPosition);
}
+ $this->setRenderErrors($renderErrors);
+
return $this->render($element);
}
@@ -167,6 +182,26 @@ public function getLabelPosition()
}
/**
+ * Are the errors rendered by this helper ?
+ *
+ * @param bool $renderErrors
+ * @return FormRow
+ */
+ public function setRenderErrors($renderErrors)
+ {
+ $this->renderErrors = (bool) $renderErrors;
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function getRenderErrors()
+ {
+ return $this->renderErrors;
+ }
+
+ /**
* Set the attributes for the row label
*
* @param array $labelAttributes
View
22 library/Zend/Form/View/Helper/FormSelect.php
@@ -12,6 +12,7 @@
use Traversable;
use Zend\Form\ElementInterface;
+use Zend\Form\Element\Select as SelectElement;
use Zend\Form\Exception;
/**
@@ -60,6 +61,13 @@ class FormSelect extends AbstractHelper
*/
public function render(ElementInterface $element)
{
+ if (!$element instanceof SelectElement) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ '%s requires that the element is of type Zend\Form\Element\Select',
+ __METHOD__
+ ));
+ }
+
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf(
@@ -68,21 +76,17 @@ public function render(ElementInterface $element)
));
}
- $attributes = $element->getAttributes();
- if (!isset($attributes['options'])
- || (!is_array($attributes['options']) && !$attributes['options'] instanceof Traversable)
- ) {
+ $options = $element->getValueOptions();
+ if (empty($options)) {
throw new Exception\DomainException(sprintf(
- '%s requires that the element has an array or Traversable "options" attribute; none found',
+ '%s requires that the element has "value_options"; none found',
__METHOD__
));
}
- $options = (array) $attributes['options'];
- unset($attributes['options']);
-
- $value = $this->validateMultiValue($element->getValue(), $attributes);
+ $attributes = $element->getAttributes();
+ $value = $this->validateMultiValue($element->getValue(), $attributes);
$attributes['name'] = $name;
if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
View
36 library/Zend/Form/View/Helper/FormSubmit.php
@@ -11,6 +11,7 @@
namespace Zend\Form\View\Helper;
use Zend\Form\ElementInterface;
+use Zend\Form\Exception;
/**
* @category Zend
@@ -48,4 +49,39 @@ protected function getType(ElementInterface $element)
{
return 'submit';
}
+
+ /**
+ * Render a form <input> element from the provided $element
+ *
+ * @param ElementInterface $element
+ * @return string
+ */
+ public function render(ElementInterface $element)
+ {
+ $name = $element->getName();
+ if ($name === null || $name === '') {
+ throw new Exception\DomainException(sprintf(
+ '%s requires that the element has an assigned name; none discovered',
+ __METHOD__
+ ));
+ }
+
+ $submitValue = $element->getValue();
+ if (null !== ($translator = $this->getTranslator())) {
+ $submitValue = $translator->translate(
+ $submitValue, $this->getTranslatorTextDomain()
+ );
+ }
+
+ $attributes = $element->getAttributes();
+ $attributes['name'] = $name;
+ $attributes['type'] = $this->getType($element);
+ $attributes['value'] = $submitValue;
+
+ return sprintf(
+ '<input %s%s',
+ $this->createAttributesString($attributes),
+ $this->getInlineClosingBracket()
+ );
+ }
}
View
10 library/Zend/Http/PhpEnvironment/Request.php
@@ -264,6 +264,16 @@ public function setServer(ParametersInterface $server)
if (isset($this->serverParams['SERVER_PORT'])) {
$port = (int) $this->serverParams['SERVER_PORT'];
}
+ // Check for missinterpreted IPv6-Address
+ // Reported at least for Safari on Windows
+ if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
+ $host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
+ if ($port . ']' == substr($host, strrpos($host, ':')+1)) {
+ // The last digit of the IPv6-Address has been taken as port
+ // Unset the port so the default port can be used
+ $port = null;
+ }
+ }
} elseif ($this->getHeaders()->get('host')) {
$host = $this->getHeaders()->get('host')->getFieldValue();
// works for regname, IPv4 & IPv6
View
8 ...y/Zend/I18n/Translator/Loader/LoaderInterface.php → ...nd/I18n/Translator/Loader/FileLoaderInterface.php
@@ -11,20 +11,20 @@
namespace Zend\I18n\Translator\Loader;
/**
- * Loader interface.
+ * File loader interface.
*
* @category Zend
* @package Zend_I18n
* @subpackage Translator
*/
-interface LoaderInterface
+interface FileLoaderInterface
{
/**
* Load translations from a file.
*
- * @param string $filename
* @param string $locale
+ * @param string $filename
* @return \Zend\I18n\Translator\TextDomain|null
*/
- public function load($filename, $locale);
+ public function load($locale, $filename);
}
View
10 library/Zend/I18n/Translator/Loader/Gettext.php
@@ -22,7 +22,7 @@
* @package Zend_I18n
* @subpackage Translator
*/
-class Gettext implements LoaderInterface
+class Gettext implements FileLoaderInterface
{
/**
* Current file pointer.
@@ -39,15 +39,15 @@ class Gettext implements LoaderInterface
protected $littleEndian;
/**
- * load(): defined by LoaderInterface.
+ * load(): defined by FileLoaderInterface.
*
- * @see LoaderInterface::load()
- * @param string $filename
+ * @see FileLoaderInterface::load()
* @param string $locale
+ * @param string $filename
* @return TextDomain
* @throws Exception\InvalidArgumentException
*/
- public function load($filename, $locale)
+ public function load($locale, $filename)
{
if (!is_file($filename) || !is_readable($filename)) {
throw new Exception\InvalidArgumentException(sprintf(
View
10 library/Zend/I18n/Translator/Loader/PhpArray.php
@@ -21,18 +21,18 @@
* @package Zend_I18n
* @subpackage Translator
*/
-class PhpArray implements LoaderInterface
+class PhpArray implements FileLoaderInterface
{
/**
- * load(): defined by LoaderInterface.
+ * load(): defined by FileLoaderInterface.
*
- * @see LoaderInterface::load()
- * @param string $filename
+ * @see FileLoaderInterface::load()
* @param string $locale
+ * @param string $filename
* @return TextDomain|null
* @throws Exception\InvalidArgumentException
*/
- public function load($filename, $locale)
+ public function load($locale, $filename)
{
if (!is_file($filename) || !is_readable($filename)) {
throw new Exception\InvalidArgumentException(sprintf(
View
30 library/Zend/I18n/Translator/Loader/RemoteLoaderInterface.php
@@ -0,0 +1,30 @@
+<?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_I18n
+ */
+
+namespace Zend\I18n\Translator\Loader;
+
+/**
+ * Remote loader interface.
+ *
+ * @category Zend
+ * @package Zend_I18n
+ * @subpackage Translator
+ */
+interface RemoteLoaderInterface
+{
+ /**
+ * Load translations from a remote source.
+ *
+ * @param string $locale
+ * @param string $textDomain
+ * @return \Zend\I18n\Translator\TextDomain|null
+ */
+ public function load($locale, $textDomain);
+}
View
17 library/Zend/I18n/Translator/LoaderPluginManager.php
@@ -16,9 +16,9 @@
/**
* Plugin manager implementation for translation loaders.
*
- * Enforces that filters retrieved are either callbacks or instances of
- * Loader\LoaderInterface. Additionally, it registers a number of default
- * loaders.
+ * Enforces that loaders retrieved are either instances of
+ * Loader\FileLoaderInterface or Loader\RemoteLoaderInterface. Additionally,
+ * it registers a number of default loaders.
*
* @category Zend
* @package Zend_I18n
@@ -27,7 +27,7 @@
class LoaderPluginManager extends AbstractPluginManager
{
/**
- * Default set of loaders
+ * Default set of loaders.
*
* @var array
*/
@@ -37,9 +37,10 @@ class LoaderPluginManager extends AbstractPluginManager
);
/**
- * Validate the plugin
+ * Validate the plugin.
*
- * Checks that the filter loaded is an instance of Loader\LoaderInterface.
+ * Checks that the filter loaded is an instance of
+ * Loader\FileLoaderInterface or Loader\RemoteLoaderInterface.
*
* @param mixed $plugin
* @return void
@@ -47,13 +48,13 @@ class LoaderPluginManager extends AbstractPluginManager
*/
public function validatePlugin($plugin)
{
- if ($plugin instanceof Loader\LoaderInterface) {
+ if ($plugin instanceof Loader\FileLoaderInterface || $plugin instanceof Loader\RemoteLoaderInterface) {
// we're okay
return;
}
throw new Exception\RuntimeException(sprintf(
- 'Plugin of type %s is invalid; must implement %s\Loader\LoaderInterface',
+ 'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface or %s\Loader\RemoteLoaderInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
View
106 library/Zend/I18n/Translator/Translator.php
@@ -15,6 +15,8 @@
use Zend\Cache;
use Zend\Cache\Storage\StorageInterface as CacheStorage;
use Zend\I18n\Exception;
+use Zend\I18n\Translator\Loader\FileLoaderInterface;
+use Zend\I18n\Translator\Loader\RemoteLoaderInterface;
use Zend\Stdlib\ArrayUtils;
/**
@@ -48,6 +50,13 @@ class Translator
protected $patterns = array();
/**
+ * Remote locations for loading messages.
+ *
+ * @var array
+ */
+ protected $remote = array();
+
+ /**
* Default locale.
*
* @var string
@@ -105,16 +114,16 @@ public static function factory($options)
}
}
- // patterns
- if (isset($options['translation_patterns'])) {
- if (!is_array($options['translation_patterns'])) {
+ // file patterns
+ if (isset($options['translation_file_patterns'])) {
+ if (!is_array($options['translation_file_patterns'])) {
throw new Exception\InvalidArgumentException(
'"translation_patterns" should be an array'
);
}
$requiredKeys = array('type', 'base_dir', 'pattern');
- foreach ($options['translation_patterns'] as $pattern) {
+ foreach ($options['translation_file_patterns'] as $pattern) {
foreach ($requiredKeys as $key) {
if (!isset($pattern[$key])) {
throw new Exception\InvalidArgumentException(
@@ -159,6 +168,31 @@ public static function factory($options)
}
}
+ // remote
+ if (isset($options['remote_translation'])) {
+ if (!is_array($options['remote_translation'])) {
+ throw new Exception\InvalidArgumentException(
+ '"remote_translation" should be an array'
+ );
+ }
+
+ $requiredKeys = array('type');
+ foreach ($options['remote_translation'] as $remote) {
+ foreach ($requiredKeys as $key) {
+ if (!isset($remote[$key])) {
+ throw new Exception\InvalidArgumentException(
+ "'{$key}' is missing for remote translation options"
+ );
+ }
+ }
+
+ $translator->addRemoteTranslations(
+ $remote['type'],
+ isset($remote['text_domain']) ? $remote['text_domain'] : 'default'
+ );
+ }
+ }
+
// cache
if (isset($options['cache'])) {
if ($options['cache'] instanceof CacheStorage) {
@@ -403,7 +437,7 @@ public function addTranslationFile(
}
/**
- * Add multiple translations with a pattern.
+ * Add multiple translations with a file pattern.
*
* @param string $type
* @param string $baseDir
@@ -411,7 +445,7 @@ public function addTranslationFile(
* @param string $textDomain
* @return Translator
*/
- public function addTranslationPattern(
+ public function addTranslationFilePattern(
$type,
$baseDir,
$pattern,
@@ -431,6 +465,24 @@ public function addTranslationPattern(
}
/**
+ * Add remote translations.
+ *
+ * @param string $type
+ * @param string $textDomain
+ * @return Translator
+ */
+ public function addRemoteTranslations($type, $textDomain = 'default')
+ {
+ if (!isset($this->remote[$textDomain])) {
+ $this->remote[$textDomain] = array();
+ }
+
+ $this->remote[$textDomain][] = $type;
+
+ return $this;
+ }
+
+ /**
* Load messages for a given language and domain.
*
* @param string $textDomain
@@ -452,15 +504,34 @@ protected function loadMessages($textDomain, $locale)
}
}
+ // Try to load from remote sources
+ if (isset($this->remote[$textDomain])) {
+ foreach ($this->remote[$textDomain] as $loaderType) {
+ $loader = $this->getPluginManager()->get($loaderType);
+
+ if (!$loader instanceof RemoteLoaderInterface) {
+ throw new Exception\RuntimeException('Specified loader is not a remote loader');
+ }
+
+ $this->messages[$textDomain][$locale] = $loader->load($locale, $textDomain);
+ return;
+ }
+ }
+
// Try to load from pattern
if (isset($this->patterns[$textDomain])) {
foreach ($this->patterns[$textDomain] as $pattern) {
- $filename = $pattern['baseDir']
- . '/' . sprintf($pattern['pattern'], $locale);
+ $filename = $pattern['baseDir'] . '/' . sprintf($pattern['pattern'], $locale);
+
if (is_file($filename)) {
- $this->messages[$textDomain][$locale] = $this->getPluginManager()
- ->get($pattern['type'])
- ->load($filename, $locale);
+ $loader = $this->getPluginManager()->get($pattern['type']);
+
+ if (!$loader instanceof FileLoaderInterface) {
+ throw new Exception\RuntimeException('Specified loader is not a file loader');
+ }
+
+ $this->messages[$textDomain][$locale] = $loader->load($locale, $filename);
+ return;
}
}
}
@@ -471,12 +542,17 @@ protected function loadMessages($textDomain, $locale)
continue;
}
- $file = $this->files[$textDomain][$currentLocale];
- $this->messages[$textDomain][$locale] = $this->getPluginManager()
- ->get($file['type'])
- ->load($file['filename'], $locale);
+ $file = $this->files[$textDomain][$currentLocale];
+ $loader = $this->getPluginManager()->get($file['type']);
+
+ if (!$loader instanceof FileLoaderInterface) {
+ throw new Exception\RuntimeException('Specified loader is not a file loader');
+ }
+
+ $this->messages[$textDomain][$locale] = $loader->load($locale, $file['filename']);
unset($this->files[$textDomain][$currentLocale]);
+ return;
}
// Cache the loaded text domain
View
10 library/Zend/Log/Writer/Syslog.php
@@ -11,8 +11,8 @@
namespace Zend\Log\Writer;
use Zend\Log\Exception;
-use Zend\Log\Formatter;
use Zend\Log\Logger;
+use Zend\Log\Formatter\Simple as SimpleFormatter;
/**
* Writes log messages to syslog
@@ -102,6 +102,8 @@ public function __construct(array $params = array())
if ($runInitializeSyslog) {
$this->initializeSyslog();
}
+
+ $this->setFormatter(new SimpleFormatter('%message%'));
}
/**
@@ -235,11 +237,7 @@ protected function doWrite(array $event)
$this->initializeSyslog();
}
- if ($this->formatter instanceof Formatter) {
- $message = $this->formatter->format($event);
- } else {
- $message = $event['message'];
- }
+ $message = $this->formatter->format($event);
syslog($priority, $message);
}
View
8 library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
@@ -23,10 +23,14 @@
*/
class PostRedirectGet extends AbstractPlugin
{
- public function __invoke($redirect, $redirectToUrl = false)
+ public function __invoke($redirect = null, $redirectToUrl = false)
{
$controller = $this->getController();
- $request = $controller->getRequest();
+ $request = $controller->getRequest();
+
+ if (null === $redirect) {
+ $redirect = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
+ }
$container = new Container('prg_post1');
View
67 library/Zend/Paginator/AdapterPluginManager.php
@@ -1,67 +0,0 @@
-<?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_Paginator
- */
-
-namespace Zend\Paginator;
-
-use Zend\ServiceManager\AbstractPluginManager;
-
-/**
- * Plugin manager implementation for pagination adapters
- *
- * Enforces that adapters retrieved are instances of
- * Adapter\AdapterInterface. Additionally, it registers a number
- * of default adapters available.
- *
- * @category Zend
- * @package Zend_Paginator
- */
-class AdapterPluginManager extends AbstractPluginManager
-{
- /**
- * Default set of adapters
- *
- * @var array
- */
- protected $invokableClasses = array(
- 'array' => 'Zend\Paginator\Adapter\ArrayAdapter',
- 'dbselect' => 'Zend\Paginator\Adapter\DbSelect',
- 'dbtableselect' => 'Zend\Paginator\Adapter\DbTableSelect',
- 'iterator' => 'Zend\Paginator\Adapter\Iterator',
- 'null' => 'Zend\Paginator\Adapter\Null',
- );
-
- /**
- * @var bool Do not share by default
- */
- protected $shareByDefault = false;
-
- /**
- * Validate the plugin
- *
- * Checks that the adapter loaded is an instance of Adapter\AdapterInterface.
- *
- * @param mixed $plugin
- * @return void
- * @throws Exception\InvalidArgumentException if invalid
- */
- public function validatePlugin($plugin)
- {
- if ($plugin instanceof Adapter\AdapterInterface) {
- // we're okay
- return;
- }
-
- throw new Exception\InvalidArgumentException(sprintf(
- 'Plugin of type %s is invalid; must implement %s\Adapter\AdapterInterface',
- (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
- __NAMESPACE__
- ));
- }
-}
View
88 library/Zend/Paginator/Paginator.php
@@ -31,12 +31,6 @@
*/
class Paginator implements Countable, IteratorAggregate
{
- /**
- * Specifies that the factory should try to detect the proper adapter type first
- *
- * @var string
- */
- const INTERNAL_ADAPTER = 'Zend\Paginator\Adapter\Internal';
/**
* The cache tag prefix used to namespace Paginator results in the cache
@@ -165,86 +159,12 @@ class Paginator implements Countable, IteratorAggregate
protected $view = null;
/**
- * Factory.
- *
- * @param mixed $data
- * @param string $adapter
- * @throws Exception\InvalidArgumentException
- * @return Paginator
- */
- public static function factory($data, $adapter = self::INTERNAL_ADAPTER)
- {
- if ($data instanceof AdapterAggregateInterface) {
- return new self($data->getPaginatorAdapter());
- }
-
- if ($adapter == self::INTERNAL_ADAPTER) {
- if (is_array($data)) {
- $adapter = 'array';
- } elseif ($data instanceof Sql\Select) {
- $adapter = 'db_select';
- } elseif ($data instanceof Iterator) {
- $adapter = 'iterator';
- } elseif (is_integer($data)) {
- $adapter = 'null';
- } else {
- $type = (is_object($data)) ? get_class($data) : gettype($data);
- throw new Exception\InvalidArgumentException('No adapter for type ' . $type);
- }
- }
-
- $adapters = self::getAdapterPluginManager();
- $adapter = $adapters->get($adapter, $data);
- return new self($adapter);
- }
-
- /**
- * Set the adapter plugin manager
- *
- * @param string|AdapterPluginManager $adapters
- * @throws Exception\InvalidArgumentException
- */
- public static function setAdapterPluginManager($adapters)
- {
- if (is_string($adapters)) {
- if (!class_exists($adapters)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Unable to locate adapter plugin manager with class "%s"; class not found',
- $adapters
- ));
- }
- $adapters = new $adapters();
- }
- if (!$adapters instanceof AdapterPluginManager) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Pagination adapter manager must extend AdapterPluginManager; received "%s"',
- (is_object($adapters) ? get_class($adapters) : gettype($adapters))
- ));
- }
- self::$adapters = $adapters;
- }
-
- /**
- * Returns the adapter plugin manager. If it doesn't exist it's created.
- *
- * @return AdapterPluginManager
- */
- public static function getAdapterPluginManager()
- {
- if (self::$adapters === null) {
- self::setAdapterPluginManager(new AdapterPluginManager());
- }
-
- return self::$adapters;
- }
-
- /**
* Set a global config
*
* @param array|\Traversable $config
* @throws Exception\InvalidArgumentException
*/
- public static function setOptions($config)
+ public static function setGlobalConfig($config)
{
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
@@ -255,12 +175,6 @@ public static function setOptions($config)
self::$config = $config;
- if (isset($config['adapter_plugins'])
- && null !== ($adapters = $config['adapter_plugins'])
- ) {
- self::setAdapterPluginManager($adapters);
- }
-
if (isset($config['scrolling_style_plugins'])