Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.2
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.2', '7.3', '7.4', '8.0', '8.1']

fail-fast: false

Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.2
coverage: none

- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
}
],
"require": {
"php": ">=7.1 <8.2",
"php": ">=7.2 <8.2",
"ext-tokenizer": "*",
"nette/neon": "^3.3",
"nette/php-generator": "^3.3.3",
"nette/robot-loader": "^3.2",
"nette/schema": "^1.1",
"nette/utils": "^3.1.6"
"nette/utils": "^3.2.5"
},
"require-dev": {
"nette/tester": "^2.2",
Expand All @@ -41,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
"dev-master": "3.1-dev"
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The recommended way to install is via Composer:
composer require nette/di
```

It requires PHP version 7.1 and supports PHP up to 8.1.
It requires PHP version 7.2 and supports PHP up to 8.1.


Usage
Expand Down
14 changes: 0 additions & 14 deletions src/DI/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,4 @@ protected function createPhpGenerator(): PhpGenerator
{
return new PhpGenerator($this->builder);
}


/** @deprecated use non-static Compiler::loadDefinitionsFromConfig() */
public static function loadDefinitions(): void
{
throw new Nette\DeprecatedException(__METHOD__ . '() is deprecated, use non-static Compiler::loadDefinitionsFromConfig(array $configList).');
}


/** @deprecated use non-static Compiler::loadDefinitionsFromConfig() */
public static function loadDefinition(): void
{
throw new Nette\DeprecatedException(__METHOD__ . '() is deprecated, use non-static Compiler::loadDefinitionsFromConfig(array $configList).');
}
}
2 changes: 1 addition & 1 deletion src/DI/Config/Adapters/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function process(array $arr): array
} else {
$tmp = $this->process([$val->value]);
if (is_string($tmp[0]) && strpos($tmp[0], '?') !== false) {
trigger_error('Operator ? is deprecated in config files.', E_USER_DEPRECATED);
throw new Nette\DI\InvalidConfigurationException('Operator ? is deprecated in config file.');
}
$val = new Statement($tmp[0], $this->process($val->attributes));
}
Expand Down
9 changes: 2 additions & 7 deletions src/DI/Config/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ final class Helpers
public const PREVENT_MERGING = '_prevent_merging';


/**
* Merges configurations. Left has higher priority than right one.
* @return array|string
*/
/** @deprecated */
public static function merge($left, $right)
{
return Nette\Schema\Helpers::merge($left, $right);
}


/**
* Return true if array prevents merging and removes this information.
*/
/** @deprecated */
public static function takeParent(&$data): bool
{
if (is_array($data) && isset($data[self::PREVENT_MERGING])) {
Expand Down
6 changes: 3 additions & 3 deletions src/DI/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Container
{
use Nette\SmartObject;

/** @var array user parameters */
/** @var array<mixed> user parameters */
public $parameters = [];

/** @var string[] services name => type (complete list of available services) */
Expand All @@ -28,10 +28,10 @@ class Container
/** @var string[] alias => service name */
protected $aliases = [];

/** @var array[] tag name => service name => tag value */
/** @var array<array<mixed>> tag name => service name => tag value */
protected $tags = [];

/** @var array[] type => level => services */
/** @var array<class-string, array<int, array<int, string>>> type => level => services */
protected $wiring = [];

/** @var object[] service name => instance */
Expand Down
8 changes: 0 additions & 8 deletions src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,4 @@ public function formatPhp(string $statement, array $args): string
});
return (new PhpGenerator($this))->formatPhp($statement, $args);
}


/** @deprecated use resolve() */
public function prepareClassList(): void
{
trigger_error(__METHOD__ . '() is deprecated, use resolve()', E_USER_DEPRECATED);
$this->resolve();
}
}
25 changes: 17 additions & 8 deletions src/DI/Definitions/AccessorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function setImplement(string $interface)
{
if (!interface_exists($interface)) {
throw new Nette\InvalidArgumentException(sprintf(
"Service '%s': Interface '%s' not found.",
$this->getName(),
"[%s]\nInterface '%s' not found.",
$this->getDescriptor(),
$interface
));
}
Expand All @@ -45,17 +45,22 @@ public function setImplement(string $interface)
|| count($rc->getMethods()) > 1
) {
throw new Nette\InvalidArgumentException(sprintf(
"Service '%s': Interface %s must have just one non-static method get().",
$this->getName(),
"[%s]\nInterface %s must have just one non-static method get().",
$this->getDescriptor(),
$interface
));
} elseif ($method->getNumberOfParameters()) {
throw new Nette\InvalidArgumentException(sprintf(
"Service '%s': Method %s::get() must have no parameters.",
$this->getName(),
"[%s]\nMethod %s::get() must have no parameters.",
$this->getDescriptor(),
$interface
));
}
try {
Helpers::ensureClassType(Type::fromReflection($method), "return type of $interface::get()", $this->getDescriptor());
} catch (Nette\DI\ServiceCreationException $e) {
trigger_error($e->getMessage(), E_USER_DEPRECATED);
}
return parent::setType($interface);
}

Expand Down Expand Up @@ -112,13 +117,17 @@ public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGe
$class = (new Nette\PhpGenerator\ClassType)
->addImplement($this->getType());

$class->addProperty('container')
$containerType = $generator->getClassName();
$container = $class->addProperty('container')
->setPrivate();
if (PHP_VERSION_ID >= 74000) {
$container->setType($containerType);
}

$class->addMethod('__construct')
->addBody('$this->container = $container;')
->addParameter('container')
->setType($generator->getClassName());
->setType($containerType);

$rm = new \ReflectionMethod($this->getType(), self::METHOD_GET);

Expand Down
29 changes: 27 additions & 2 deletions src/DI/Definitions/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ final public function getName(): ?string
}


final public function isAnonymous(): bool
{
return !$this->name || ctype_digit($this->name);
}


public function getDescriptor(): string
{
if (!$this->isAnonymous()) {
return "Service '$this->name'" . ($this->type ? " of type $this->type" : '');

} elseif ($this->type) {
return "Service of type $this->type";

} elseif ($this->name) {
return "Service '$this->name'";

} else {
return 'Service ?';
}
}


/** @return static */
protected function setType(?string $type)
{
Expand All @@ -65,8 +88,8 @@ protected function setType(?string $type)
$this->type = null;
} elseif (!class_exists($type) && !interface_exists($type)) {
throw new Nette\InvalidArgumentException(sprintf(
"Service '%s': Class or interface '%s' not found.",
$this->name,
"[%s]\nClass or interface '%s' not found.",
$this->getDescriptor(),
$type
));
} else {
Expand Down Expand Up @@ -194,13 +217,15 @@ public function getClass(): ?string
/** @deprecated Use '$def instanceof Nette\DI\Definitions\ImportedDefinition' */
public function isDynamic(): bool
{
trigger_error(sprintf('Service %s: %s() is deprecated, use "instanceof ImportedDefinition".', $this->getName(), __METHOD__), E_USER_DEPRECATED);
return false;
}


/** @deprecated Use Nette\DI\Definitions\FactoryDefinition or AccessorDefinition */
public function getImplement(): ?string
{
trigger_error(sprintf('Service %s: %s() is deprecated.', $this->getName(), __METHOD__), E_USER_DEPRECATED);
return null;
}

Expand Down
Loading