<?php declare(strict_types=1);

/**
 * This file is part of the Nette Framework (https://nette.org)
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 */

namespace Nette\PhpGenerator;


/**
 * PHP literal value.
 */
class Literal
{
	/**
	 * Creates a literal representing the creation of an object using the new operator.
	 * @param  mixed[]  $args
	 */
	public static function new(string $class, array $args = []): self
	{
		return new self('new ' . $class . '(...?:)', [$args]);
	}


	public function __construct(
		private readonly string $value,
		/** @var ?mixed[] */
		private readonly ?array $args = null,
	) {
	}


	public function __toString(): string
	{
		return $this->formatWith(new Dumper);
	}


	/** @internal */
	public function formatWith(Dumper $dumper): string
	{
		return $this->args === null
			? $this->value
			: $dumper->format($this->value, ...$this->args);
	}
}
                                                                                                                               {
	"name": "nette/php-generator",
	"description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.",
	"keywords": ["nette", "php", "code", "scaffolding"],
	"homepage": "https://nette.org",
	"license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"],
	"authors": [
		{
			"name": "David Grudl",
			"homepage": "https://davidgrudl.com"
		},
		{
			"name": "Nette Community",
			"homepage": "https://nette.org/contributors"
		}
	],
	"require": {
		"php": "8.1 - 8.5",
		"nette/utils": "^4.0.6"
	},
	"require-dev": {
		"nette/tester": "^2.6",
		"nikic/php-parser": "^5.0",
		"tracy/tracy": "^2.8",
		"phpstan/phpstan": "^2.1.40@stable",
		"phpstan/extension-installer": "^1.4@stable",
		"nette/phpstan-rules": "^1.0",
		"jetbrains/phpstorm-attributes": "^1.2"
	},
	"suggest": {
		"nikic/php-parser": "to use ClassType::from(withBodies: true) & ClassType::fromCode()"
	},
	"autoload": {
		"classmap": ["src/"],
		"psr-4": {
			"Nette\\": "src"
		}
	},
	"minimum-stability": "dev",
	"scripts": {
		"phpstan": "phpstan analyse",
		"tester": "tester tests -s"
	},
	"extra": {
		"branch-alias": {
			"dev-master": "4.2-dev"
		}
	},
	"config": {
		"allow-plugins": {
			"phpstan/extension-installer": true
		}
	}
}
