Initialize property for serializers

Serializers and test frameworks skip the constructor using
serialization tricks. This means that if an empty Pimple instance is
serialized and later deserialized that the $values property contains
'null'. This breaks offsetExists() and several other locations that 
assume the $values property contains an array.
added Travis configuration
Introduce static versions of share() and protect()
merged branch igorw/static-share-protect (PR #63)

This PR was squashed before being merged into the master branch (closes #63).

Commits
-------

f3e834d Introduce static versions of share() and protect()

Discussion
----------

Introduce static versions of share() and protect()

I have a use case where I want to be able to pass parameters to an object that will then at some point create and initialize a pimple container. Then set the parameters. I want to be able to override defaults, including services.

Essentially, this:

    createContainer([
        'foo' => Pimple::shareStatic(function () { return new Foo(); }),
    ]);

Since the container does not exist yet, I have no instance to call share() on. Therefore, I want static versions of share and protect, so that this use case is supported properly.

I'm open to:

* Removing the docblocks on the static versions
* Finding better names for the static versions
* Just making the existing `share` and `protect` methods static and abuse the fact that PHP allows them to be called dynamically as well

---------------------------------------------------------------------------

by fabpot at 2013-02-09T10:54:00Z

Option 3 seems better to me (just making the current methods static).

---------------------------------------------------------------------------

by simensen at 2013-02-09T15:19:18Z

:+1:

Option 3 is my favorite as well.

---------------------------------------------------------------------------

by igorw at 2013-02-09T15:20:50Z

In that case I sincerely hope that PHP does not decide to deprecate that in the future. Updating PR.

---------------------------------------------------------------------------

by igorw at 2013-02-09T15:23:31Z

Done, changed to option 3.
Allow invokable objects to be shared, extended, and protected.
Change  Visibility to be protected
merged branch ArabCoders/master (PR #66)

This PR was squashed before being merged into the master branch (closes #66).

Commits
-------

afece3c Change  Visibility to be protected

Discussion
----------

Change $values Visibility to be protected

This change allow other classes to extend Pimple and override some core class function.

EDIT: change public to protected

---------------------------------------------------------------------------

by stof at 2013-02-14T08:26:41Z

Why public ? It make no sense to have it public as some work needs to be done when accessing the values.

---------------------------------------------------------------------------

by ArabCoders at 2013-02-14T09:35:35Z

Hi
@stof,

it does make sense when you want to override(ie: overload) function take the following example

````php
class diDebug extends \Pimple
{
    public function offsetGet($id)
    {
        if (!array_key_exists($id, $this->values)) {
            throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.<BR />%s', $id, $this->get_backtrace() ));
        }

        $isFactory = is_object($this->values[$id]) && method_exists($this->values[$id], '__invoke');

        return $isFactory ? $this->values[$id]($this) : $this->values[$id];
    }

    public function raw($id)
    {
        if (!array_key_exists($id, $this->values)) {
            throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.<BR /> %s', $id, $this->get_backtrace() ));
        }

        return $this->values[$id];
    }
}
````

this example will not work because pimple::$values is set to private, and i dont think its reasonable to expect every call to the dependency injection class to be in try {} catch{} block

---------------------------------------------------------------------------

by fabpot at 2013-02-14T09:37:51Z

protected would be enough.

---------------------------------------------------------------------------

by stof at 2013-02-14T09:40:02Z

@ArabCoders thus, why do you need to include the backtrace in the exception message ? Enable XDebug and the trace will be displayed when an exception occurs.

---------------------------------------------------------------------------

by ArabCoders at 2013-02-14T09:43:22Z

@fabpot, indeed that will works too, i can send another pull request if you want.

@stof that's because most shared hosts dont have xdebug enabled or even compiled, and I have to debug manually.

---------------------------------------------------------------------------

by stof at 2013-02-14T09:45:06Z

are you developing directly on your hosting ?

---------------------------------------------------------------------------

by whatthejeff at 2013-02-14T09:48:27Z

Why not just do this:

```php
class diDebug extends \Pimple
{
    public function offsetGet($id)
    {
        try {
           return parent::offsetGet($id);
        } catch (Exception $exception) {
           // do whatever
        }
    }
}

---------------------------------------------------------------------------

by ArabCoders at 2013-02-14T09:53:35Z

@stof No, Im trying to debug client framework, and i run into this issue the other developer didn't follow any logical patterns, or test environment and the website is huge to be copied over to my test server. to replicate the problem so i had to make do with what is other developer had at that time and invent some hacks to make it work.

Anyway its not about me, i just think $values should be either public or protected so that other classes can extend it without any problems. ^^

---------------------------------------------------------------------------

by ArabCoders at 2013-02-14T09:59:10Z

@whatthejeff Yes it can be done that way too, i only showed an example for use case to make $values [public/protected] not necessarily the only example ^^

---------------------------------------------------------------------------

by stof at 2013-02-14T10:00:47Z

@ArabCoders Making it public means that it is part of the public API. But this is wrong. People should not be able to access the internal storage from the outside.

---------------------------------------------------------------------------

by ArabCoders at 2013-02-14T10:05:35Z

@stof yeah i realized that, that's why i asked if @fabpot wanted me to do another pull request with protected or he would do it :) im kinda new to the whole fork/pull thing.

PS: English is not my first tongue, so forgive any grammar mistakes
merged branch mvriel/patch-1 (PR #56)

This PR was merged into the master branch.

Commits
-------

53ec09c Initialize property for serializers

Discussion
----------

Initialize property for serializers

Serializers and test frameworks skip the constructor using
serialization tricks. This means that if an empty Pimple instance is
serialized and later deserialized that the $values property contains
'null'. This breaks offsetExists() and several other locations that
assume the $values property contains an array.

---------------------------------------------------------------------------

by igorw at 2012-12-18T01:36:38Z

Serializing a pimple instance? Sounds scary.

Btw, see also #54 which is a superset of this PR.

---------------------------------------------------------------------------

by stof at 2012-12-18T10:01:06Z

Yeah, Pimple is meant to contain closures so serializing it sounds really scary

---------------------------------------------------------------------------

by mvriel at 2012-12-18T10:36:20Z

Apparently PHPUnit does it since all my unit tests fail unless I add that initializer. Perhaps I can tweak a setting in PHPUnit to resolve this but haven't had time to dive into which option that should be

---------------------------------------------------------------------------

by SergSerbin at 2012-12-18T11:36:12Z

For PHPUnit you should be able to solve it with adding  ` @backupGlobals disabled` to the phpDoc of a test method (or test class) definition.
http://www.phpunit.de/manual/current/en/appendixes.annotations.html

---------------------------------------------------------------------------

by igorw at 2013-01-13T20:58:09Z

My PR which included this change was closed. @fabpot This PR should be merged.
merged branch whatthejeff/invokables (PR #65)

This PR was merged into the master branch.

Discussion
----------

Alternative to PR #61

This PR is a continuation of a419262.  It allows invokable objects to be shared, extended, and protected.  The unit tests have been updated (where applicable) to use data providers to ensure that invokable objects work in all situations where Closures work.

Unlike #61, this PR contains no major refactoring.

Commits
-------

294533b Allow invokable objects to be shared, extended, and protected.
bumped Pimple version
Remove space between constructor and its parameters
Remove space between testConstructorInjection and braces
merged branch carlosbuenosvinos/patch-1 (PR #79)

This PR was merged into the master branch.

Discussion
----------

Remove space between constructor and its parameters

Commits
-------

a8131ef Remove space between constructor and its parameters
merged branch carlosbuenosvinos/patch-2 (PR #80)

This PR was merged into the master branch.

Discussion
----------

Remove space between testConstructorInjection and braces

Commits
-------

540a301 Remove space between testConstructorInjection and braces
changed services to be shared by default
feature #83 [2.0] changed services to be shared by default (fabpot)

This PR was merged into the master branch.

Discussion
----------

[2.0] changed services to be shared by default

Now that we have several years of experience using Pimple, I think everyone agrees that having to call `share` everytime you need to define a service is cumbersome. And it is even error-prone when calling `extend` as one needs to call `share` again.

#62 proposes a shortcut for the extend use case, but I want to go one step further in Pimple 2.0: remove the need to call `share` altogether.

The reasoning is quite simple: services are 99.9% shared (I don't even have an example for a prototype service).

So, this PR makes closure shared by default. If you need to define a prototype service, call `prototype`.

This change is almost backward compatible as the `share` method is kept as a no-op method. The only BC break is if you have a prototype service in which case you need to wrap it with a `prototype` call.

Of course, Pimple 2.0 will be used in Silex 2.0, which will make things much easier to read and shorter.

TODO:

 - [x] update docs and website for 2.0

Commits
-------

e5309ac changed services to be shared by default
renamed prototype to factory
feature #86 [2.0] renamed prototype to factory (fabpot)

This PR was merged into the master branch.

Discussion
----------

[2.0] renamed prototype to factory

The only valid usage for the `prototype` type of services is factories. So, I'd like to rename prototype to factory in the code to make things easier to understand.

Commits
-------

6d6925b renamed prototype to factory
changed extend to automatically re-assign the extended service and keep it as shared or factory
Frozen container after first service access

A big issue with pimple is that you can instantiate services and then re-
define the factories that produced dependencies of those services, leading
to inconsistent results.

An example:

 * foo depends on baz
 * bar depends on baz

foo and baz are defined, foo is accessed. baz is re-defined, bar is defined.
Although both foo and bar depend on baz, they got a different version of it.

A way to fix this problem is to freeze the container when the first service
is accessed. After the freeze you can still define new services and
parameters, but you cannot override existing ones.

This freezing happens on a per-service basis.

In case you really must re-define a service, you can explicitly unset it,
but that is bad practice and should be avoided.

This is a BC break, as such it targets pimple 2.0.