Skip to content

Commit

Permalink
Refactor container. Remove old features.
Browse files Browse the repository at this point in the history
This is a moderate refactoring of the container to clean up code and
remove some legacy features that haven’t been documented in several
years. The make() method no longer accepts a second argument of
parameters - needing this feature indicates a code smell and you can
always construct the object in another way. It simply complicated the
container and code and made it hard to read.

Secondly, the share() method has been removed. This method was an old
method to provide backwards compatibility with Pimple. It has not been
documented in a few years and the more popular “singleton()” method is
easier to use.

Thirdly, the Normalize() method has been removed. This is the most
called method in all of Laravel and it is called almost 1,000 times on
every request because of the heavy usage of the container. On a fresh
opcache enabled run of Laravel it is actually uses about 8-9% of the
entire request processing time. It’s whole purpose is to allow you to
bind objects into the container with a leading slash; however,
Foo::class never returns a leading slash and if you pass a string we
can simply document that a leading slash should not be provided.
  • Loading branch information
taylorotwell committed Dec 23, 2016
1 parent 5e5be5c commit ff993b8
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 332 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Container/BoundMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected static function normalizeMethod($container, $callback)
{
$class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]);

return $container->normalize("{$class}@{$callback[1]}");
return "{$class}@{$callback[1]}";
}

/**
Expand Down
Loading

4 comments on commit ff993b8

@vlakoff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refs #11258 :-)

@djtarazona
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@Braunson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ 👍

@crynobone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell Illuminate\Database\Connectors\ConnectionFactory need to be updated, especially

if ($this->container->bound($key = "db.connection.{$driver}")) {
    return $this->container->make($key, [$connection, $database, $prefix, $config]);
}

this part.

Please sign in to comment.