Skip to content

Commit eba6f05

Browse files
committed
Revert "Merge pull request #605 from holtkamp/hash-compiled-container-function-names"
This reverts commit 9cfb4bd, reversing changes made to f16f27b.
1 parent 5fe47fc commit eba6f05

File tree

2 files changed

+4
-96
lines changed

2 files changed

+4
-96
lines changed

src/Compiler/Compiler.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,15 @@ public function compile(
157157
return $fileName;
158158
}
159159

160-
/**
161-
* Use a hash to ensure that the used method names in the CompiledContainer are both unique and idempotent.
162-
*/
163-
private function getHashedValue(string $prefix, string $value): string
164-
{
165-
return $prefix . md5($value);
166-
}
167-
168160
/**
169161
* @throws DependencyException
170162
* @throws InvalidDefinition
171163
* @return string The method name
172164
*/
173165
private function compileDefinition(string $entryName, Definition $definition) : string
174166
{
175-
$methodName = $this->getHashedValue('get', $entryName);
176-
177-
//In case an Entry is already added, the used method should be equal
178-
if(isset($this->entryToMethodMapping[$entryName]) && $this->entryToMethodMapping[$entryName] !== $methodName){
179-
throw new InvalidDefinition(sprintf(
180-
'Entry "%s" cannot be compiled. An Entry with the same name already exists pointing to method %s(), while this one points to method %s().',
181-
$entryName,
182-
$this->entryToMethodMapping[$entryName],
183-
$methodName
184-
));
185-
}
186-
167+
// Generate a unique method name
168+
$methodName = str_replace('.', '', uniqid('get', true));
187169
$this->entryToMethodMapping[$entryName] = $methodName;
188170

189171
switch (true) {
@@ -294,8 +276,8 @@ public function compileValue($value) : string
294276
}
295277

296278
if ($value instanceof Definition) {
297-
$subEntryName = $this->getHashedValue('SubEntry', $value->getName() . $value);
298-
279+
// Give it an arbitrary unique name
280+
$subEntryName = uniqid('SubEntry');
299281
// Compile the sub-definition in another method
300282
$methodName = $this->compileDefinition($subEntryName, $value);
301283
// The value is now a method call to that method (which returns the value)

tests/IntegrationTest/CompiledContainerTest.php

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -56,54 +56,6 @@ public function the_container_is_compiled_once_and_never_recompiled_after()
5656
self::assertEquals('bar', $container->get('foo'));
5757
}
5858

59-
/** @test */
60-
public function the_compiled_container_is_idempotent()
61-
{
62-
$compiledContainerClass1 = self::generateCompiledClassName();
63-
$compiledContainerClass2 = self::generateCompiledClassName();
64-
65-
$definitions = [
66-
'foo' => 'barFromFoo',
67-
'fooReference' => \DI\get('foo'),
68-
'factory' => function () {
69-
return 'barFromFactory';
70-
},
71-
'factoryReference' => \DI\get('factory'),
72-
'array' => [
73-
1,
74-
2,
75-
3,
76-
'fooBar',
77-
],
78-
'arrayValue' => \DI\value('array'),
79-
CompiledContainerTest\AllKindsOfInjections::class => create()
80-
->constructor(create('stdClass'))
81-
->property('property', autowire(CompiledContainerTest\Autowireable::class))
82-
->method('method', \DI\factory(
83-
function () {
84-
return new \stdClass;
85-
}
86-
)
87-
),
88-
CompiledContainerTest\Autowireable::class => \DI\autowire(),
89-
];
90-
91-
// Create a compiled container in a specific file
92-
$builder1 = new ContainerBuilder;
93-
$builder1->addDefinitions($definitions);
94-
$builder1->enableCompilation(self::COMPILATION_DIR, $compiledContainerClass1);
95-
$builder1->build();
96-
97-
// Create a second compiled container with the same configuration but in a different file
98-
$builder2 = new ContainerBuilder;
99-
$builder2->addDefinitions($definitions);
100-
$builder2->enableCompilation(self::COMPILATION_DIR, $compiledContainerClass2);
101-
$builder2->build();
102-
103-
// The method mapping of the resulting CompiledContainers should be equal
104-
self::assertEquals($compiledContainerClass1::METHOD_MAPPING, $compiledContainerClass2::METHOD_MAPPING);
105-
}
106-
10759
/**
10860
* @test
10961
* @expectedException \DI\Definition\Exception\InvalidDefinition
@@ -320,29 +272,3 @@ public function __construct(AbstractClass $param)
320272
abstract class AbstractClass
321273
{
322274
}
323-
324-
class AllKindsOfInjections
325-
{
326-
public $property;
327-
public $constructorParameter;
328-
public $methodParameter;
329-
public function __construct($constructorParameter)
330-
{
331-
$this->constructorParameter = $constructorParameter;
332-
}
333-
public function method($methodParameter)
334-
{
335-
$this->methodParameter = $methodParameter;
336-
}
337-
}
338-
class Autowireable
339-
{
340-
private $dependency;
341-
public function __construct(AutowireableDependency $dependency)
342-
{
343-
$this->dependency = $dependency;
344-
}
345-
}
346-
class AutowireableDependency
347-
{
348-
}

0 commit comments

Comments
 (0)