Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Fixed fatal error cause on memory
Browse files Browse the repository at this point in the history
  • Loading branch information
divineniiquaye committed May 25, 2020
1 parent 3e0fd8b commit f3bc96b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Config/Adapter/IniAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace BiuradPHP\DependencyInjection\Config\Adapter;

use BiuradPHP\Loader\Adapters\IniAdapter as BiuradPHPIniAdapter;
use BiuradPHP\Loader\Files\Adapters\IniAdapter as BiuradPHPIniAdapter;
use Nette;

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Config/Adapter/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,14 @@ function (&$val): void {
*/
private function parseParameters(string $contents): string
{
// So yaml syntax could work properly
$contents = str_replace('~', 'null', $contents);

// Grab any parameter we might need to send
$matches = [];
$default = null;

if (preg_match(Loader::ENV_REGEX, $contents, $matches)) {
$contents = preg_replace_callback(Loader::ENV_REGEX, function ($matches) use ($default) {
// Remove the env() and spaces to we have just the parameter left
$key = ! empty($matches) ? trim($matches[0], '%env()% ') : [];

$key = ! empty($matches) ? substr(trim($matches[0], '%()% '), 4) : '';
if (strpos($key, '|') !== false) {
[$key, $default] = explode('|', $key);
}
Expand All @@ -130,7 +126,8 @@ private function parseParameters(string $contents): string
}, $contents);
}

return $contents;
// So yaml syntax could work properly
return str_replace(['~', '\'false\'', '\'true\''], ['null', 'false', 'true'], $contents);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Config/Adapter/XmlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace BiuradPHP\DependencyInjection\Config\Adapter;

use BiuradPHP\Loader\Adapters\XmlAdapter as BiuradPHPXmlAdapter;
use BiuradPHP\Loader\Files\Adapters\XmlAdapter as BiuradPHPXmlAdapter;
use Nette;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class Loader extends ConfigLoader
{
private const INCLUDES_KEY = 'includes';
public const ENV_REGEX = '/%env\([a-zA-Z0-9\|\-:_]+\)%/';
public const ENV_REGEX = '/s*%env\([a-zA-Z0-9\|\-:_]+\)%*/s';

private $adapters = [
'php' => Adapters\PhpAdapter::class,
Expand Down
50 changes: 46 additions & 4 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use BiuradPHP\DependencyInjection\Exceptions\MissingServiceException;
use BiuradPHP\DependencyInjection\Exceptions\ContainerResolutionException;
use BiuradPHP\DependencyInjection\Exceptions\ParameterNotFoundException;
use Nette\DI\ServiceCreationException;

use function BiuradPHP\Support\array_get;

Expand All @@ -42,7 +41,7 @@
* @author Divine Niiquaye Ibok <divineibok@gmail.com>
* @license BSD-3-Clause
*/
class Container extends NetteContainer implements \ArrayAccess, FactoryInterface
class Container extends NetteContainer implements \ArrayAccess, \Serializable, FactoryInterface
{
/** @var object[] service name => instance */
private $instances = [];
Expand Down Expand Up @@ -461,8 +460,6 @@ public function createInstance(string $class, array $args = [])
// this will be handled in a recursive way...
try {
$instances = $this->autowireArguments($constructor, $args);
} catch (ServiceCreationException $e) {
return $this->createInstance($class, array_values($args));
} catch (MissingServiceException $e) {
// Resolve default pararamters on class, if paramter was not given and
// default paramter exists, why not let's use it.
Expand Down Expand Up @@ -629,6 +626,51 @@ protected function autowire(string $class, array $parameters)
return $instance;
}

public function __serialize(): array
{
return [
'parameters' => $this->parameters,
'types' => $this->types,
'aliases' => $this->aliases,
'tags' => $this->tags,
'wiring' => $this->wiring,
'instances' => $this->instances,
'methods' => $this->methods,
'creating' => $this->creating,
];
}

/**
* @internal
*/
final public function serialize(): string
{
return serialize($this->__serialize());
}

public function __unserialize(array $data): void
{
$this->parameters = $data['parameters'];
$this->types = $data['types'];
$this->aliases = $data['aliases'];
$this->tags = $data['tags'];
$this->wiring = $data['wiring'];
$this->instances = $data['instances'];
$this->methods = $data['methods'];

if (isset($data['creating'])) {
$this->creating = $data['creating'];
}
}

/**
* @internal
*/
final public function unserialize($serialized)
{
$this->__unserialize(unserialize($serialized));
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit f3bc96b

Please sign in to comment.