Skip to content

Commit 02a0107

Browse files
committed
added Literal as alias for PhpLiteral
1 parent bed5a1e commit 02a0107

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ It can be used also for functions, closures, namespaces etc.
207207
Literals
208208
--------
209209

210-
You can pass any PHP code to property or parameter default values via `PhpLiteral`:
210+
You can pass any PHP code to property or parameter default values via `Literal`:
211211

212212
```php
213-
use Nette\PhpGenerator\PhpLiteral;
213+
use Nette\PhpGenerator\Literal;
214214

215215
$class = new Nette\PhpGenerator\ClassType('Demo');
216216

217-
$class->addProperty('foo', new PhpLiteral('Iterator::SELF_FIRST'));
217+
$class->addProperty('foo', new Literal('Iterator::SELF_FIRST'));
218218

219219
$class->addMethod('bar')
220-
->addParameter('id', new PhpLiteral('1 + 2'));
220+
->addParameter('id', new Literal('1 + 2'));
221221

222222
echo $class;
223223
```

src/PhpGenerator/Dumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function dump($var, int $column = 0): string
3737

3838
private function dumpVar(&$var, array $parents = [], int $level = 0, int $column = 0): string
3939
{
40-
if ($var instanceof PhpLiteral) {
40+
if ($var instanceof Literal) {
4141
return ltrim(Nette\Utils\Strings::indent(trim((string) $var), $level), "\t");
4242

4343
} elseif ($var === null) {
@@ -189,7 +189,7 @@ public function format(string $statement, ...$args): string
189189

190190
} else { // $ -> ::
191191
$arg = array_shift($args);
192-
if ($arg instanceof PhpLiteral || !Helpers::isIdentifier($arg)) {
192+
if ($arg instanceof Literal || !Helpers::isIdentifier($arg)) {
193193
$arg = '{' . $this->dumpVar($arg) . '}';
194194
}
195195
$res .= substr($token, 0, -1) . $arg;

src/PhpGenerator/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
109109
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
110110
if ($from->isDefaultValueAvailable()) {
111111
$param->setDefaultValue($from->isDefaultValueConstant()
112-
? new PhpLiteral($from->getDefaultValueConstantName())
112+
? new Literal($from->getDefaultValueConstantName())
113113
: $from->getDefaultValue());
114114
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== null);
115115
}

src/PhpGenerator/Literal.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Nette\PhpGenerator;
11+
12+
13+
/**
14+
* PHP literal value.
15+
*/
16+
class Literal
17+
{
18+
/** @var string */
19+
private $value;
20+
21+
22+
public function __construct(string $value)
23+
{
24+
$this->value = $value;
25+
}
26+
27+
28+
public function __toString(): string
29+
{
30+
return $this->value;
31+
}
32+
}

src/PhpGenerator/PhpLiteral.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@
1010
namespace Nette\PhpGenerator;
1111

1212

13-
/**
14-
* PHP literal value.
15-
*/
16-
class PhpLiteral
13+
class PhpLiteral extends Literal
1714
{
18-
/** @var string */
19-
private $value;
20-
21-
22-
public function __construct(string $value)
23-
{
24-
$this->value = $value;
25-
}
26-
27-
28-
public function __toString(): string
29-
{
30-
return $this->value;
31-
}
3215
}

0 commit comments

Comments
 (0)