summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Négrier <d.negrier@thecodingmachine.com>2016-12-29 18:26:35 +0100
committerDavid Négrier <d.negrier@thecodingmachine.com>2016-12-29 18:26:35 +0100
commit7fffdf4535a3c6e246a6fcbcfbb10a84dda54a63 (patch)
treeb07b80fecccc5edd5e0c04f1de1706ee26285c72
parent36d0c089f4b8ab611a2bdda99d3ea59206a93621 (diff)
parent76606cc1c9f1e262beb71d94cf0a6bb7f7978a2e (diff)
downloadfig-standards-7fffdf4535a3c6e246a6fcbcfbb10a84dda54a63.zip
fig-standards-7fffdf4535a3c6e246a6fcbcfbb10a84dda54a63.tar.gz
fig-standards-7fffdf4535a3c6e246a6fcbcfbb10a84dda54a63.tar.bz2
Fixing PSR11 merge conflicts
-rw-r--r--proposed/container-meta.md42
-rw-r--r--proposed/container.md24
-rw-r--r--proposed/simplecache.md44
3 files changed, 73 insertions, 37 deletions
diff --git a/proposed/container-meta.md b/proposed/container-meta.md
index eb41f0e..ae99788 100644
--- a/proposed/container-meta.md
+++ b/proposed/container-meta.md
@@ -184,7 +184,7 @@ In the rest of this meta document, you will see frequent references to
The interface name is the same as the one discussed for `container-interop`
(only the namespace is changed to match the other PSRs).
-It has been thoroughly discussed on `container-interop` [[1]](#link_naming_discussion) and was decided by a vote [[2]](#link_naming_vote).
+It has been thoroughly discussed on `container-interop` [[4]](#link_naming_discussion) and was decided by a vote [[5]](#link_naming_vote).
The list of options considered with their respective votes are:
@@ -199,7 +199,7 @@ The list of options considered with their respective votes are:
## 7. Interface methods
-The choice of which methods the interface would contain was made after a statistical analysis of existing containers. [[3]](#link_statistical_analysis).
+The choice of which methods the interface would contain was made after a statistical analysis of existing containers. [[6]](#link_statistical_analysis).
The summary of the analysis showed that:
@@ -213,7 +213,7 @@ The summary of the analysis showed that:
- a large majority of the containers throw an exception rather than returning null when an entry is not found in `get()`
- a large majority of the containers don't implement `ArrayAccess`
-The question of whether to include methods to define entries has been discussed at the very start of the container-interop project [[1]](#link_naming_discussion).
+The question of whether to include methods to define entries has been discussed at the very start of the container-interop project [[4]](#link_naming_discussion).
It has been judged that such methods do not belong in the interface described here because it is out of its scope
(see the "Goal" section).
@@ -228,7 +228,16 @@ While `ContainerInterface` only defines one mandatory parameter in `get()`, it i
existing containers that have additional optional parameters. PHP allows an implementation to offer more parameters
as long as they are optional, because the implementation *does* satisfy the interface.
-This issue has been discussed in [container-interop's issue #6](https://github.com/container-interop/container-interop/issues/6).
+Difference with container-interop: [The container-interop spec](https://github.com/container-interop/container-interop/blob/master/docs/ContainerInterface.md) stated that:
+
+> While `ContainerInterface` only defines one mandatory parameter in `get()`, implementations MAY accept additional optional parameters.
+
+This sentence was removed from PSR-11 because:
+
+- It is something that stems from OO principles in PHP, so this is not directly related to PSR-11
+- We do not want to encourage implementors to add additional parameters as we recommend coding against the interface and not the implementation
+
+However, some implementations have extra optional parameters; that's technically legal. Such implementations are compatible with PSR-11. [[11]](#link_get_optional_parameters)
### 7.2. Type of the `$id` parameter
@@ -240,7 +249,7 @@ anything (such as objects) could allow containers to offer a more advanced query
An example given was to use the container as an object builder. The `$id` parameter would then be an
object that would describe how to create an instance.
-The conclusion of the discussion [[4]](#link_method_and_parameters_details) was that this was beyond the scope of getting entries from a container without
+The conclusion of the discussion [[7]](#link_method_and_parameters_details) was that this was beyond the scope of getting entries from a container without
knowing how the container provided them, and it was more fit for a factory.
### 7.3. Exceptions thrown
@@ -258,7 +267,7 @@ It is expected that any exception that is part of the domain of the container im
However, if the exception is thrown by some code out of the container's scope (for instance an exception thrown while instantiating an entry), the container is not required to wrap this exception in a custom exception implementing the `ContainerExceptionInterface`.
-The usefulness of the base exception interface was questioned: it is not an exception one would typically catch [[5]](#link_base_exception_usefulness).
+The usefulness of the base exception interface was questioned: it is not an exception one would typically catch [[8]](#link_base_exception_usefulness).
However, most PHP-FIG members considered it to be a best practice. Base exception interface are implemented in previous PSRs and several member projects. The base exception interface was therefore kept.
@@ -276,7 +285,7 @@ For a given identifier:
When discussing the `ǸotFoundException`, a question arose to know whether the `NotFoundExceptionInterface` should have a `getMissingIdentifier()` method allowing the user catching the exception to know which identifier was not found.
Indeed, a `ǸotFoundExceptionInterface` may have been triggered by a call to `get` in one of the dependencies, which is different from a call to `get` on a non existing identifier.
-After some discussion [[6]](#link_not_found_behaviour), it was decided that the `getIdentifier` method was not needed. Instead, it is important to stress out that the `get` method of the container SHOULD NOT throw a `NotFoundExceptionInterface` in case of a missing dependency. Instead, the container is expected to wrap the `NotFoundExceptionInterface` into another exception simply implementing the `ContainerExceptionInterface`.
+After some discussion [[9]](#link_not_found_behaviour), it was decided that the `getIdentifier` method was not needed. Instead, it is important to stress out that the `get` method of the container SHOULD NOT throw a `NotFoundExceptionInterface` in case of a missing dependency. Instead, the container is expected to wrap the `NotFoundExceptionInterface` into another exception simply implementing the `ContainerExceptionInterface`.
In pseudo-code, a correct implementation of `get` should look like this:
@@ -369,12 +378,13 @@ Are listed here all people that contributed in the discussions or votes (on cont
10. Relevant links
------------------
-- [Discussion about the container PSR and the service locator](https://groups.google.com/forum/#!topic/php-fig/pyTXRvLGpsw)
-- [Container-interop's `ContainerInterface.php`](https://github.com/container-interop/container-interop/blob/master/src/Interop/Container/ContainerInterface.php)
-- [List of all issues](https://github.com/container-interop/container-interop/issues?labels=ContainerInterface&milestone=&page=1&state=closed)
-- <a name="link_naming_discussion"></a>[Discussion about the interface name and container-interop scope](https://github.com/container-interop/container-interop/issues/1)
-- <a name="link_naming_vote"></a>[Vote for the interface name](https://github.com/container-interop/container-interop/wiki/%231-interface-name:-Vote)
-- <a name="link_statistical_analysis"></a>[Statistical analysis of existing containers method names](https://gist.github.com/mnapoli/6159681)
-- <a name="link_method_and_parameters_details"></a>[Discussion about the method names and parameters](https://github.com/container-interop/container-interop/issues/6)
-- <a name="link_base_exception_usefulness"></a>[Discussion about the usefulness of the base exception](https://groups.google.com/forum/#!topic/php-fig/_vdn5nLuPBI)
-- <a name="link_not_found_behaviour"></a>[Discussion about the `NotFoundExceptionInterface` structure](https://github.com/container-interop/container-interop/issues/37)
+1. [Discussion about the container PSR and the service locator](https://groups.google.com/forum/#!topic/php-fig/pyTXRvLGpsw)
+1. [Container-interop's `ContainerInterface.php`](https://github.com/container-interop/container-interop/blob/master/src/Interop/Container/ContainerInterface.php)
+1. [List of all issues](https://github.com/container-interop/container-interop/issues?labels=ContainerInterface&milestone=&page=1&state=closed)
+1. <a name="link_naming_discussion"></a>[Discussion about the interface name and container-interop scope](https://github.com/container-interop/container-interop/issues/1)
+1. <a name="link_naming_vote"></a>[Vote for the interface name](https://github.com/container-interop/container-interop/wiki/%231-interface-name:-Vote)
+1. <a name="link_statistical_analysis"></a>[Statistical analysis of existing containers method names](https://gist.github.com/mnapoli/6159681)
+1. <a name="link_method_and_parameters_details"></a>[Discussion about the method names and parameters](https://github.com/container-interop/container-interop/issues/6)
+1. <a name="link_base_exception_usefulness"></a>[Discussion about the usefulness of the base exception](https://groups.google.com/forum/#!topic/php-fig/_vdn5nLuPBI)
+1. <a name="link_not_found_behaviour"></a>[Discussion about the `NotFoundExceptionInterface` structure](https://github.com/container-interop/container-interop/issues/37)
+1. <a name="link_get_optional_parameters"></a>Discussion about get optional parameters [in container-interop](https://github.com/container-interop/container-interop/issues/6) and on the [PHP-FIG mailing list](https://groups.google.com/forum/#!topic/php-fig/zY6FAG4-oz8)
diff --git a/proposed/container.md b/proposed/container.md
index 529adaa..0cc5e7f 100644
--- a/proposed/container.md
+++ b/proposed/container.md
@@ -21,6 +21,12 @@ Users of dependency injections containers (DIC) are referred to as `user`.
### 1.1 Basics
+#### 1.1.1 Entry Identifiers
+
+An entry identifier is any PHP-legal string of at least one character that uniquely identifies an item within a container. An entry identifier is an opaque string, so callers SHOULD NOT assume that the structure of the string caries any semantic meaning.
+
+#### 1.1.2 Reading from a container
+
- The `Psr\Container\ContainerInterface` exposes two methods : `get` and `has`.
- `get` takes one mandatory parameter: an entry identifier. It MUST be a string.
@@ -29,21 +35,20 @@ Users of dependency injections containers (DIC) are referred to as `user`.
identifier SHOULD return the same value. However, depending on the `implementor`
design and/or `user` configuration, different values might be returned, so
`user` SHOULD NOT rely on getting the same value on 2 successive calls.
- While `ContainerInterface` only defines one mandatory parameter in `get()`, implementations
- MAY accept additional optional parameters.
- `has` takes one unique parameter: an entry identifier. It MUST return `true`
if an entry identifier is known to the container and `false` if it is not.
`has($id)` returning true does not mean that `get($id)` will not throw an exception.
It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
+
### 1.2 Exceptions
Exceptions directly thrown by the container SHOULD implement the
-[`Psr\Container\Exception\ContainerExceptionInterface`](#container-exception).
+[`Psr\Container\ContainerExceptionInterface`](#container-exception).
A call to the `get` method with a non-existing id MUST throw a
-[`Psr\Container\Exception\NotFoundExceptionInterface`](#not-found-exception).
+[`Psr\Container\NotFoundExceptionInterface`](#not-found-exception).
A call to `get` can trigger additional calls to `get` (to fetch the dependencies).
If one of those dependencies is missing, the `NotFoundExceptionInterface` triggered by the
@@ -79,9 +84,6 @@ Projects requiring an implementation should require `psr/container-implementatio
<?php
namespace Psr\Container;
-use Psr\Container\Exception\ContainerExceptionInterface;
-use Psr\Container\Exception\NotFoundExceptionInterface;
-
/**
* Describes the interface of a container that exposes methods to read its entries.
*/
@@ -115,11 +117,11 @@ interface ContainerInterface
~~~
<a name="container-exception"></a>
-### 3.2. `Psr\Container\Exception\ContainerExceptionInterface`
+### 2.2. `Psr\Container\ContainerExceptionInterface`
~~~php
<?php
-namespace Psr\Container\Exception;
+namespace Psr\Container;
/**
* Base interface representing a generic exception in a container.
@@ -130,11 +132,11 @@ interface ContainerExceptionInterface
~~~
<a name="not-found-exception"></a>
-### 3.3. `Psr\Container\Exception\NotFoundExceptionInterface`
+### 2.3. `Psr\Container\NotFoundExceptionInterface`
~~~php
<?php
-namespace Psr\Container\Exception;
+namespace Psr\Container;
/**
* No entry was found in the container.
diff --git a/proposed/simplecache.md b/proposed/simplecache.md
index 3121b79..c90dfb0 100644
--- a/proposed/simplecache.md
+++ b/proposed/simplecache.md
@@ -1,5 +1,5 @@
-Common Interface for Caching libraries
-================
+Common Interface for Caching Libraries
+======================================
This document describes a simple yet extensible interface for a cache item and
a cache driver.
@@ -54,8 +54,7 @@ by an integer representing time in seconds, or a DateInterval object.
* **Expiration** - The actual time when an item is set to go stale. This is
calculated by adding the TTL to the time when an object is stored.
- An item with a 300 second TTL stored at 1:30:00 will have an expiration of
- 1:35:00.
+ An item with a 300 second TTL stored at 1:30:00 will have an expiration of 1:35:00.
Implementing Libraries MAY expire an item before its requested Expiration Time,
but MUST treat an item as expired once its Expiration Time is reached. If a calling
@@ -92,6 +91,31 @@ is provided implementations MUST default to the maximum legal value allowed by
the underlying implementation. If the underlying implementation does not
support TTL, the user-specified TTL MUST be silently ignored.
+### 1.4 Data
+
+Implementing libraries MUST support all serializable PHP data types, including:
+
+* **Strings** - Character strings of arbitrary size in any PHP-compatible encoding.
+* **Integers** - All integers of any size supported by PHP, up to 64-bit signed.
+* **Floats** - All signed floating point values.
+* **Boolean** - True and False.
+* **Null** - The null value (although it will not be distinguishable from a
+cache miss when reading it back out).
+* **Arrays** - Indexed, associative and multidimensional arrays of arbitrary depth.
+* **Object** - Any object that supports lossless serialization and
+deserialization such that $o == unserialize(serialize($o)). Objects MAY
+leverage PHP's Serializable interface, `__sleep()` or `__wakeup()` magic methods,
+or similar language functionality if appropriate.
+
+All data passed into the Implementing Library MUST be returned exactly as
+passed. That includes the variable type. That is, it is an error to return
+(string) 5 if (int) 5 was the value saved. Implementing Libraries MAY use PHP's
+serialize()/unserialize() functions internally but are not required to do so.
+Compatibility with them is simply used as a baseline for acceptable object values.
+
+If it is not possible to return the exact saved value for any reason, implementing
+libraries MUST respond with a cache miss rather than corrupted data.
+
2. Interfaces
-------------
@@ -168,10 +192,10 @@ interface CacheInterface
/**
* Obtains multiple cache items by their unique keys.
*
- * @param array|\Traversable $keys A list of keys that can obtained in a single operation.
- * @param mixed $default Default value to return for keys that do not exist.
+ * @param iterable $keys A list of keys that can obtained in a single operation.
+ * @param mixed $default Default value to return for keys that do not exist.
*
- * @return array|\Traversable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
+ * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,
@@ -182,7 +206,7 @@ interface CacheInterface
/**
* Persists a set of key => value pairs in the cache, with an optional TTL.
*
- * @param array|\Traversable $values A list of key => value pairs for a multiple-set operation.
+ * @param iterable $values A list of key => value pairs for a multiple-set operation.
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
@@ -198,9 +222,9 @@ interface CacheInterface
/**
* Deletes multiple cache items in a single operation.
*
- * @param array|\Traversable $keys A list of string-based keys to be deleted.
+ * @param iterable $keys A list of string-based keys to be deleted.
*
- * @return bool True if the item was successfully removed. False if there was an error.
+ * @return bool True if the items were successfully removed. False if there was an error.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,