✨feature: Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
phpcs-results.txt
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"tree.indentGuidesStroke": "#3d92ec",
|
||||||
|
"activityBar.background": "#053241",
|
||||||
|
"titleBar.activeBackground": "#07465B",
|
||||||
|
"titleBar.activeForeground": "#F3FBFE",
|
||||||
|
"titleBar.inactiveBackground": "#053241",
|
||||||
|
"titleBar.inactiveForeground": "#F3FBFE",
|
||||||
|
"statusBar.background": "#053241",
|
||||||
|
"statusBar.foreground": "#F3FBFE",
|
||||||
|
"statusBar.debuggingBackground": "#053241",
|
||||||
|
"statusBar.debuggingForeground": "#F3FBFE",
|
||||||
|
"statusBar.noFolderBackground": "#053241",
|
||||||
|
"statusBar.noFolderForeground": "#F3FBFE"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# IronKanban
|
||||||
|
|
||||||
|
I'm currently using this project https://github.com/OlaProeis/ironPad in a custom docker container I wrapped it in. While it works, and I like the flat-file git-backed nature of it, I'm not thrilled with the interaction pattern. I would like to keep the markdown powered (using the same format for the notes and projects if at all possible) git repo aspect of it, but build it out into a kanban-style interface.
|
||||||
|
|
||||||
|
I would also like to move away from the stack IronPad is using, and move to something I'm more comfortable with. I would prefer PHP with vanilla javascript as needed. That said, I would like to have the abilty to drag and drop cards between columns, and have the interface update in real time as changes are made. I would also like to have the ability to create new columns and cards, and have those changes reflected in the underlying markdown files.
|
||||||
|
|
||||||
|
Each Project is currently built as a folder that is laid out like this:
|
||||||
|
|
||||||
|
```plain
|
||||||
|
project-name/
|
||||||
|
├── index.md
|
||||||
|
├── notes/
|
||||||
|
│ └── 20260314-154222.md
|
||||||
|
├── tasks/
|
||||||
|
│ ├── task-20260227-124827.md
|
||||||
|
│ ├── task-20260227-124901.md
|
||||||
|
│ ├── task-20260227-165334.md
|
||||||
|
│ └── task-20260314-154158.md
|
||||||
|
```
|
||||||
|
|
||||||
|
I have uploaded a sample project for reference (filenames above are based on the uploaded project). The `index.md` file contains the project description and any relevant information about the project. The optional `notes` folder contains any notes related to the project, and the `tasks` folder contains the individual tasks for the project.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"symfony/yaml": "^7.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+245
@@ -0,0 +1,245 @@
|
|||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "9b92e985110e1787699365cd0f20c978",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "symfony/deprecation-contracts",
|
||||||
|
"version": "v3.6.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||||
|
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||||
|
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"url": "https://github.com/symfony/contracts",
|
||||||
|
"name": "symfony/contracts"
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "3.6-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"function.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nicolas Grekas",
|
||||||
|
"email": "p@tchwork.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A generic function and convention to trigger deprecation notices",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-09-25T14:21:43+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/polyfill-ctype",
|
||||||
|
"version": "v1.33.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||||
|
"reference": "a3cc8b044a6ea513310cbd48ef7333b384945638"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638",
|
||||||
|
"reference": "a3cc8b044a6ea513310cbd48ef7333b384945638",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.2"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"ext-ctype": "*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-ctype": "For best performance"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"url": "https://github.com/symfony/polyfill",
|
||||||
|
"name": "symfony/polyfill"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"bootstrap.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Polyfill\\Ctype\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Gert de Pagter",
|
||||||
|
"email": "BackEndTea@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony polyfill for ctype functions",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"ctype",
|
||||||
|
"polyfill",
|
||||||
|
"portable"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.33.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-09-09T11:45:10+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/yaml",
|
||||||
|
"version": "v7.4.6",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/yaml.git",
|
||||||
|
"reference": "58751048de17bae71c5aa0d13cb19d79bca26391"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/yaml/zipball/58751048de17bae71c5aa0d13cb19d79bca26391",
|
||||||
|
"reference": "58751048de17bae71c5aa0d13cb19d79bca26391",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
|
"symfony/deprecation-contracts": "^2.5|^3",
|
||||||
|
"symfony/polyfill-ctype": "^1.8"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/console": "<6.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/console": "^6.4|^7.0|^8.0"
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"Resources/bin/yaml-lint"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Yaml\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Loads and dumps YAML files",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/yaml/tree/v7.4.6"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-02-09T09:33:46+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": {},
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": {},
|
||||||
|
"platform-dev": {},
|
||||||
|
"plugin-api-version": "2.9.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="Coding Style Checks">
|
||||||
|
<description>Coding Style Checks</description>
|
||||||
|
<ini name="error_reporting" value="E_ALL & ~E_DEPRECATED" />
|
||||||
|
|
||||||
|
<arg value="sp"/>
|
||||||
|
<arg name="colors"/>
|
||||||
|
<arg name="extensions" value="php,html,css"/>
|
||||||
|
<arg name="parallel" value="2048"/>
|
||||||
|
|
||||||
|
<exclude-pattern>vendor/</exclude-pattern>
|
||||||
|
<exclude-pattern>node_modules/</exclude-pattern>
|
||||||
|
|
||||||
|
<rule ref="PEAR">
|
||||||
|
<exclude name="PEAR.Classes.ClassDeclaration"/>
|
||||||
|
<exclude name="PEAR.Functions.FunctionDeclaration"/>
|
||||||
|
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
|
||||||
|
<exclude name="Generic.Functions.CallTimePassByReference"/>
|
||||||
|
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag"/>
|
||||||
|
<exclude name="Squiz.Commenting.FileComment.Missing"/>
|
||||||
|
<exclude name="Squiz.Commenting.FileComment.WrongStyle"/>
|
||||||
|
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="Internal.NoCodeFound">
|
||||||
|
<severity>0</severity>
|
||||||
|
</rule>
|
||||||
|
</ruleset>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task Domain Model
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* Represents a task entity with all its properties.
|
||||||
|
*
|
||||||
|
* @category DomainModel
|
||||||
|
* @package IronKanban\Domain
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task class represents a domain model for a task
|
||||||
|
*
|
||||||
|
* @category DomainModel
|
||||||
|
* @package IronKanban\Domain
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class Task {
|
||||||
|
/**
|
||||||
|
* Constructor for Task
|
||||||
|
*
|
||||||
|
* @param string $id The task identifier
|
||||||
|
* @param string $title The task title
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
* @param string $column The column the task belongs to
|
||||||
|
* @param int $order The order of the task
|
||||||
|
* @param bool $completed Whether the task is completed
|
||||||
|
* @param string $priority The priority level of the task
|
||||||
|
* @param bool $isActive Whether the task is active
|
||||||
|
* @param string $body The task description
|
||||||
|
* @param array $meta Additional metadata (optional)
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public string $id,
|
||||||
|
public string $title,
|
||||||
|
public string $projectId,
|
||||||
|
public string $column,
|
||||||
|
public int $order,
|
||||||
|
public bool $completed,
|
||||||
|
public string $priority,
|
||||||
|
public bool $isActive,
|
||||||
|
public string $body,
|
||||||
|
public array $meta = []
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Front Matter Document
|
||||||
|
*
|
||||||
|
* Represents a parsed markdown document with YAML front matter.
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* @category Markdown
|
||||||
|
* @package IronKanban\Markdown
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Markdown;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FrontMatterDocument represents a markdown document with YAML front matter
|
||||||
|
*
|
||||||
|
* @category Markdown
|
||||||
|
* @package IronKanban\Markdown
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class FrontMatterDocument {
|
||||||
|
/**
|
||||||
|
* Constructor for FrontMatterDocument
|
||||||
|
*
|
||||||
|
* @param array $meta The front matter metadata
|
||||||
|
* @param string $body The document body content
|
||||||
|
*/
|
||||||
|
public function __construct( public array $meta, public string $body ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front Matter Parser
|
||||||
|
*
|
||||||
|
* Parses markdown files with YAML front matter sections.
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* @category Markdown
|
||||||
|
* @package IronKanban\Markdown
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Markdown;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FrontMatterParser parses markdown files with YAML front matter
|
||||||
|
*
|
||||||
|
* @category Markdown
|
||||||
|
* @package IronKanban\Markdown
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class FrontMatterParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Parse a markdown file and extract front matter
|
||||||
|
*
|
||||||
|
* @param string $filePath Path to the markdown file
|
||||||
|
*
|
||||||
|
* @return FrontMatterDocument The parsed document
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If file cannot be read
|
||||||
|
*/
|
||||||
|
public function parseFile(string $filePath): FrontMatterDocument
|
||||||
|
{
|
||||||
|
if (!is_file($filePath)) {
|
||||||
|
throw new RuntimeException("Markdown file not found: {$filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$contents = file_get_contents($filePath);
|
||||||
|
|
||||||
|
if ($contents === false) {
|
||||||
|
throw new RuntimeException("Unable to read markdown file: {$filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->parseString($contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a markdown string and extract front matter
|
||||||
|
*
|
||||||
|
* @param string $contents The markdown content to parse
|
||||||
|
*
|
||||||
|
* @return FrontMatterDocument The parsed document
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If YAML parsing fails
|
||||||
|
*/
|
||||||
|
public function parseString(string $contents): FrontMatterDocument
|
||||||
|
{
|
||||||
|
$contents = str_replace(["\r\n", "\r"], "\n", $contents);
|
||||||
|
|
||||||
|
if (!str_starts_with($contents, "---\n")) {
|
||||||
|
return new FrontMatterDocument([], ltrim($contents, "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$closingPos = strpos($contents, "\n---\n", 4);
|
||||||
|
|
||||||
|
if ($closingPos === false) {
|
||||||
|
return new FrontMatterDocument([], ltrim($contents, "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$yamlStart = 4;
|
||||||
|
$yamlLength = $closingPos - $yamlStart;
|
||||||
|
$yamlText = substr($contents, $yamlStart, $yamlLength);
|
||||||
|
$bodyStart = $closingPos + 5;
|
||||||
|
$body = substr($contents, $bodyStart);
|
||||||
|
|
||||||
|
if ($body === false) {
|
||||||
|
$body = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$meta = Yaml::parse($yamlText);
|
||||||
|
} catch (ParseException $e) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
'Failed to parse YAML front matter: ' . $e->getMessage(),
|
||||||
|
0,
|
||||||
|
$e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($meta)) {
|
||||||
|
$meta = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FrontMatterDocument($meta, ltrim($body, "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dump a document to markdown string with front matter
|
||||||
|
*
|
||||||
|
* @param FrontMatterDocument $document The document to dump
|
||||||
|
*
|
||||||
|
* @return string The markdown content with front matter
|
||||||
|
*/
|
||||||
|
public function dump(FrontMatterDocument $document): string
|
||||||
|
{
|
||||||
|
$yaml = Yaml::dump(
|
||||||
|
$document->meta,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK
|
||||||
|
);
|
||||||
|
|
||||||
|
$body = str_replace(["\r\n", "\r"], "\n", $document->body);
|
||||||
|
$body = ltrim($body, "\n");
|
||||||
|
|
||||||
|
return "---\n{$yaml}---\n\n{$body}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,393 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task Repository
|
||||||
|
*
|
||||||
|
* Manages persisting and retrieving tasks from markdown files.
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* @category Repository
|
||||||
|
* @package IronKanban\Repository
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Repository;
|
||||||
|
|
||||||
|
use IronKanban\Domain\Task;
|
||||||
|
use IronKanban\Markdown\FrontMatterDocument;
|
||||||
|
use IronKanban\Markdown\FrontMatterParser;
|
||||||
|
use IronKanban\Support\FileLock;
|
||||||
|
use IronKanban\Support\Paths;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TaskRepository manages task persistence and retrieval
|
||||||
|
*
|
||||||
|
* @category Repository
|
||||||
|
* @package IronKanban\Repository
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class TaskRepository {
|
||||||
|
/**
|
||||||
|
* Constructor for TaskRepository
|
||||||
|
*
|
||||||
|
* @param Paths $paths The paths helper
|
||||||
|
* @param FrontMatterParser $frontMatterParser The front matter parser
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private readonly Paths $paths,
|
||||||
|
private readonly FrontMatterParser $frontMatterParser
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all tasks for a project
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
*
|
||||||
|
* @return Task[] Array of tasks
|
||||||
|
*/
|
||||||
|
public function getAll(string $projectId): array {
|
||||||
|
$tasksPath = $this->paths->getTasksPath($projectId);
|
||||||
|
$files = glob($tasksPath . DIRECTORY_SEPARATOR . '*.md');
|
||||||
|
|
||||||
|
if ($files === false) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tasks = [];
|
||||||
|
|
||||||
|
foreach ($files as $filePath) {
|
||||||
|
if (!is_file($filePath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tasks[] = $this->_mapFileToTask($projectId, $filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
usort(
|
||||||
|
$tasks, function (Task $a, Task $b): int {
|
||||||
|
if ($a->column === $b->column) {
|
||||||
|
return $a->order <=> $b->order;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strcmp($a->column, $b->column);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific task by ID
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
* @param string $taskId The task identifier
|
||||||
|
*
|
||||||
|
* @return Task The task
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If task not found
|
||||||
|
*/
|
||||||
|
public function get(string $projectId, string $taskId): Task {
|
||||||
|
$filePath = $this->paths->getTaskFilePath($projectId, $taskId);
|
||||||
|
|
||||||
|
if (!is_file($filePath)) {
|
||||||
|
throw new RuntimeException("Task not found: {$taskId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_mapFileToTask($projectId, $filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a task
|
||||||
|
*
|
||||||
|
* @param Task $task The task to save
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function save(Task $task): void {
|
||||||
|
$this->paths->ensureTasksPath($task->projectId);
|
||||||
|
|
||||||
|
$filePath = $this->paths->getTaskFilePath($task->projectId, $task->id);
|
||||||
|
$lockPath = $filePath . '.lock';
|
||||||
|
|
||||||
|
FileLock::run(
|
||||||
|
$lockPath, function () use ($task, $filePath): void {
|
||||||
|
$document = $this->_mapTaskToDocument($task);
|
||||||
|
$contents = $this->frontMatterParser->dump($document);
|
||||||
|
|
||||||
|
$this->_atomicWrite($filePath, $contents);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new task
|
||||||
|
*
|
||||||
|
* @param array $data The task data
|
||||||
|
*
|
||||||
|
* @return Task The created task
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If required fields are missing
|
||||||
|
*/
|
||||||
|
public function create(array $data): Task {
|
||||||
|
$projectId = $this->_requireString($data, 'projectId');
|
||||||
|
$title = $this->_requireString($data, 'title');
|
||||||
|
$body = (string) ($data['body'] ?? '');
|
||||||
|
$column = $this->_normalizeColumn((string) ($data['column'] ?? 'backlog'));
|
||||||
|
$priority = (string) ($data['priority'] ?? 'normal');
|
||||||
|
$completed = (bool) ($data['completed'] ?? false);
|
||||||
|
$isActive = (bool) ($data['isActive'] ?? true);
|
||||||
|
$order = isset($data['order']) ? (int) $data['order'] : 100;
|
||||||
|
$now = gmdate('c');
|
||||||
|
|
||||||
|
$taskId = $this->_generateTaskId();
|
||||||
|
|
||||||
|
$meta = [
|
||||||
|
'id' => $taskId,
|
||||||
|
'type' => 'task',
|
||||||
|
'title' => $title,
|
||||||
|
'project_id' => $projectId,
|
||||||
|
'column' => $column,
|
||||||
|
'order' => $order,
|
||||||
|
'completed' => $completed,
|
||||||
|
'priority' => $priority,
|
||||||
|
'is_active' => $isActive,
|
||||||
|
'created' => $now,
|
||||||
|
'updated' => $now,
|
||||||
|
'tags' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($data['status'])) {
|
||||||
|
$meta['status'] = (string) $data['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['statusNote'])) {
|
||||||
|
$meta['status_note'] = (string) $data['statusNote'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$task = new Task(
|
||||||
|
id: $taskId,
|
||||||
|
title: $title,
|
||||||
|
projectId: $projectId,
|
||||||
|
column: $column,
|
||||||
|
order: $order,
|
||||||
|
completed: $completed,
|
||||||
|
priority: $priority,
|
||||||
|
isActive: $isActive,
|
||||||
|
body: $body,
|
||||||
|
meta: $meta
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->save($task);
|
||||||
|
|
||||||
|
return $task;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a task
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
* @param string $taskId The task identifier
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If task not found
|
||||||
|
*/
|
||||||
|
public function delete(string $projectId, string $taskId): void {
|
||||||
|
$filePath = $this->paths->getTaskFilePath($projectId, $taskId);
|
||||||
|
$lockPath = $filePath . '.lock';
|
||||||
|
|
||||||
|
if (!is_file($filePath)) {
|
||||||
|
throw new RuntimeException("Task not found: {$taskId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileLock::run(
|
||||||
|
$lockPath, function () use ($filePath): void {
|
||||||
|
if (!unlink($filePath)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Unable to delete task file: {$filePath}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a markdown file to a task
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
* @param string $filePath The file path to the task
|
||||||
|
*
|
||||||
|
* @return Task The mapped task
|
||||||
|
*/
|
||||||
|
private function _mapFileToTask(string $projectId, string $filePath): Task {
|
||||||
|
$document = $this->frontMatterParser->parseFile($filePath);
|
||||||
|
$meta = $document->meta;
|
||||||
|
|
||||||
|
$id = (string) ($meta['id'] ?? pathinfo($filePath, PATHINFO_FILENAME));
|
||||||
|
$title = (string) ($meta['title'] ?? $id);
|
||||||
|
|
||||||
|
$column = isset($meta['column'])
|
||||||
|
? $this->_normalizeColumn((string) $meta['column'])
|
||||||
|
: $this->_mapLegacySectionToColumn((string) ($meta['section'] ?? 'backlog'));
|
||||||
|
|
||||||
|
$order = isset($meta['order']) ? (int) $meta['order'] : 100;
|
||||||
|
$completed = (bool) ($meta['completed'] ?? false);
|
||||||
|
$priority = (string) ($meta['priority'] ?? 'normal');
|
||||||
|
$isActive = (bool) ($meta['is_active'] ?? true);
|
||||||
|
|
||||||
|
return new Task(
|
||||||
|
id: $id,
|
||||||
|
title: $title,
|
||||||
|
projectId: (string) ($meta['project_id'] ?? $projectId),
|
||||||
|
column: $column,
|
||||||
|
order: $order,
|
||||||
|
completed: $completed,
|
||||||
|
priority: $priority,
|
||||||
|
isActive: $isActive,
|
||||||
|
body: $document->body,
|
||||||
|
meta: $meta
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a task to a front matter document
|
||||||
|
*
|
||||||
|
* @param Task $task The task to map
|
||||||
|
*
|
||||||
|
* @return FrontMatterDocument The mapped document
|
||||||
|
*/
|
||||||
|
private function _mapTaskToDocument(Task $task): FrontMatterDocument {
|
||||||
|
$meta = $task->meta;
|
||||||
|
|
||||||
|
$meta['id'] = $task->id;
|
||||||
|
$meta['type'] = 'task';
|
||||||
|
$meta['title'] = $task->title;
|
||||||
|
$meta['project_id'] = $task->projectId;
|
||||||
|
$meta['column'] = $task->column;
|
||||||
|
$meta['order'] = $task->order;
|
||||||
|
$meta['completed'] = $task->completed;
|
||||||
|
$meta['priority'] = $task->priority;
|
||||||
|
$meta['is_active'] = $task->isActive;
|
||||||
|
|
||||||
|
if (!isset($meta['created']) || (string) $meta['created'] === '') {
|
||||||
|
$meta['created'] = gmdate('c');
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta['updated'] = gmdate('c');
|
||||||
|
|
||||||
|
return new FrontMatterDocument($meta, $task->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atomically write contents to a file
|
||||||
|
*
|
||||||
|
* @param string $filePath The file path
|
||||||
|
* @param string $contents The contents to write
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If write operation fails
|
||||||
|
*/
|
||||||
|
private function _atomicWrite(string $filePath, string $contents): void {
|
||||||
|
$directory = dirname($filePath);
|
||||||
|
$tempPath = tempnam($directory, 'ikb_');
|
||||||
|
|
||||||
|
if ($tempPath === false) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Unable to create temp file in: {$directory}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$bytesWritten = file_put_contents($tempPath, $contents);
|
||||||
|
|
||||||
|
if ($bytesWritten === false) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Unable to write temp file: {$tempPath}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rename($tempPath, $filePath)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Unable to move temp file into place: {$filePath}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (is_file($tempPath)) {
|
||||||
|
@unlink($tempPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a unique task ID
|
||||||
|
*
|
||||||
|
* @return string The generated task ID
|
||||||
|
*/
|
||||||
|
private function _generateTaskId(): string {
|
||||||
|
$randID = substr(bin2hex(random_bytes(3)), 0, 6);
|
||||||
|
$taskID = 'task-' . gmdate('Ymd-His') . '-' . $randID;
|
||||||
|
|
||||||
|
return $taskID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require a string field from data array
|
||||||
|
*
|
||||||
|
* @param array $data The data array
|
||||||
|
* @param string $key The field key
|
||||||
|
*
|
||||||
|
* @return string The string value
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If field is missing or empty
|
||||||
|
*/
|
||||||
|
private function _requireString(array $data, string $key): string {
|
||||||
|
$value = trim((string) ($data[$key] ?? ''));
|
||||||
|
|
||||||
|
if ($value === '') {
|
||||||
|
throw new RuntimeException("Missing required field: {$key}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a column name
|
||||||
|
*
|
||||||
|
* @param string $column The column name to normalize
|
||||||
|
*
|
||||||
|
* @return string The normalized column name
|
||||||
|
*/
|
||||||
|
private function _normalizeColumn(string $column): string {
|
||||||
|
$column = trim(strtolower($column));
|
||||||
|
|
||||||
|
if ($column === '') {
|
||||||
|
return 'backlog';
|
||||||
|
}
|
||||||
|
|
||||||
|
$column = preg_replace('/[^a-z0-9]+/', '-', $column) ?? 'backlog';
|
||||||
|
$column = trim($column, '-');
|
||||||
|
|
||||||
|
return $column !== '' ? $column : 'backlog';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map legacy section to column name
|
||||||
|
*
|
||||||
|
* @param string $section The legacy section name
|
||||||
|
*
|
||||||
|
* @return string The modern column name
|
||||||
|
*/
|
||||||
|
private function _mapLegacySectionToColumn(string $section): string {
|
||||||
|
return $this->_normalizeColumn($section);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File Lock
|
||||||
|
*
|
||||||
|
* Provides file-based locking mechanism for concurrent access control.
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* @category Support
|
||||||
|
* @package IronKanban\Support
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Support;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileLock provides file-based locking mechanism
|
||||||
|
*
|
||||||
|
* @category Support
|
||||||
|
* @package IronKanban\Support
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class FileLock {
|
||||||
|
/**
|
||||||
|
* Run a callback with a file lock
|
||||||
|
*
|
||||||
|
* @param string $lockPath The path to the lock file
|
||||||
|
* @param callable $callback The callback to execute
|
||||||
|
*
|
||||||
|
* @return mixed The result of the callback
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If lock cannot be acquired
|
||||||
|
*/
|
||||||
|
public static function run(string $lockPath, callable $callback): mixed {
|
||||||
|
$handle = fopen($lockPath, 'c+');
|
||||||
|
|
||||||
|
if ($handle === false) {
|
||||||
|
throw new RuntimeException("Unable to open lock file: {$lockPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!flock($handle, LOCK_EX)) {
|
||||||
|
throw new RuntimeException("Unable to acquire lock: {$lockPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $callback();
|
||||||
|
} finally {
|
||||||
|
flock($handle, LOCK_UN);
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paths Helper
|
||||||
|
*
|
||||||
|
* Manages path construction and validation for projects and tasks.
|
||||||
|
*
|
||||||
|
* PHP version 8.2+
|
||||||
|
*
|
||||||
|
* @category Support
|
||||||
|
* @package IronKanban\Support
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace IronKanban\Support;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paths manages path construction and validation
|
||||||
|
*
|
||||||
|
* @category Support
|
||||||
|
* @package IronKanban\Support
|
||||||
|
* @author Keith Solomon <keith@keithsolomon.net>
|
||||||
|
* @license Unlicense https://unlicense.org
|
||||||
|
* @link https://git.keithsolomon.net/keith/IronKanban
|
||||||
|
*/
|
||||||
|
class Paths {
|
||||||
|
/**
|
||||||
|
* Constructor for Paths
|
||||||
|
*
|
||||||
|
* @param string $projectRoot The root directory of the project
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If the project root is invalid
|
||||||
|
*/
|
||||||
|
public function __construct( private readonly string $projectRoot ) {
|
||||||
|
$realRoot = realpath($projectRoot);
|
||||||
|
|
||||||
|
if ($realRoot === false || !is_dir($realRoot)) {
|
||||||
|
throw new RuntimeException("Invalid project root: {$projectRoot}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->projectRoot = $realRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the project root directory
|
||||||
|
*
|
||||||
|
* @return string The project root path
|
||||||
|
*/
|
||||||
|
public function getProjectRoot(): string
|
||||||
|
{
|
||||||
|
return $this->projectRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path for a specific project
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
*
|
||||||
|
* @return string The project path
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If project not found
|
||||||
|
*/
|
||||||
|
public function getProjectPath(string $projectId): string {
|
||||||
|
$safeProjectId = $this->_sanitizeSegment($projectId);
|
||||||
|
$path = $this->projectRoot . DIRECTORY_SEPARATOR . $safeProjectId;
|
||||||
|
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
throw new RuntimeException("Project not found: {$projectId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tasks directory path for a project
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
*
|
||||||
|
* @return string The tasks directory path
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If tasks directory not found
|
||||||
|
*/
|
||||||
|
public function getTasksPath(string $projectId): string {
|
||||||
|
$path = $this->getProjectPath($projectId) . DIRECTORY_SEPARATOR . 'tasks';
|
||||||
|
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Tasks directory not found for project: {$projectId}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file path for a specific task
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
* @param string $taskId The task identifier
|
||||||
|
*
|
||||||
|
* @return string The task file path
|
||||||
|
*/
|
||||||
|
public function getTaskFilePath(string $projectId, string $taskId): string {
|
||||||
|
$tasksPath = $this->getTasksPath($projectId);
|
||||||
|
$safeTaskId = $this->_sanitizeSegment($taskId);
|
||||||
|
|
||||||
|
return $tasksPath . DIRECTORY_SEPARATOR . $safeTaskId . '.md';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure tasks directory exists
|
||||||
|
*
|
||||||
|
* @param string $projectId The project identifier
|
||||||
|
*
|
||||||
|
* @return string The tasks directory path
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If directory cannot be created
|
||||||
|
*/
|
||||||
|
public function ensureTasksPath(string $projectId): string {
|
||||||
|
$path = $this->getProjectPath($projectId) . DIRECTORY_SEPARATOR . 'tasks';
|
||||||
|
|
||||||
|
if (!is_dir($path) && !mkdir($path, 0775, true) && !is_dir($path)) {
|
||||||
|
throw new RuntimeException("Unable to create tasks directory: {$path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize a path segment
|
||||||
|
*
|
||||||
|
* @param string $value The path segment to sanitize
|
||||||
|
*
|
||||||
|
* @return string The sanitized segment
|
||||||
|
*
|
||||||
|
* @throws RuntimeException If segment is invalid
|
||||||
|
*/
|
||||||
|
private function _sanitizeSegment(string $value): string {
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
if ($value === '') {
|
||||||
|
throw new RuntimeException('Path segment cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $value)) {
|
||||||
|
throw new RuntimeException("Invalid path segment: {$value}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload.php @generated by Composer
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID < 50600) {
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
|
}
|
||||||
|
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||||
|
if (!ini_get('display_errors')) {
|
||||||
|
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||||
|
fwrite(STDERR, $err);
|
||||||
|
} elseif (!headers_sent()) {
|
||||||
|
echo $err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException($err);
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
|
return ComposerAutoloaderInit1d14b066a73960476c178ecf92bed18f::getLoader();
|
||||||
Vendored
+119
@@ -0,0 +1,119 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy PHP file generated by Composer
|
||||||
|
*
|
||||||
|
* This file includes the referenced bin path (../symfony/yaml/Resources/bin/yaml-lint)
|
||||||
|
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
||||||
|
*
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer;
|
||||||
|
|
||||||
|
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
||||||
|
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID < 80000) {
|
||||||
|
if (!class_exists('Composer\BinProxyWrapper')) {
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class BinProxyWrapper
|
||||||
|
{
|
||||||
|
private $handle;
|
||||||
|
private $position;
|
||||||
|
private $realpath;
|
||||||
|
|
||||||
|
public function stream_open($path, $mode, $options, &$opened_path)
|
||||||
|
{
|
||||||
|
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
||||||
|
$opened_path = substr($path, 17);
|
||||||
|
$this->realpath = realpath($opened_path) ?: $opened_path;
|
||||||
|
$opened_path = $this->realpath;
|
||||||
|
$this->handle = fopen($this->realpath, $mode);
|
||||||
|
$this->position = 0;
|
||||||
|
|
||||||
|
return (bool) $this->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_read($count)
|
||||||
|
{
|
||||||
|
$data = fread($this->handle, $count);
|
||||||
|
|
||||||
|
if ($this->position === 0) {
|
||||||
|
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->position += strlen($data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_cast($castAs)
|
||||||
|
{
|
||||||
|
return $this->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_close()
|
||||||
|
{
|
||||||
|
fclose($this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_lock($operation)
|
||||||
|
{
|
||||||
|
return $operation ? flock($this->handle, $operation) : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_seek($offset, $whence)
|
||||||
|
{
|
||||||
|
if (0 === fseek($this->handle, $offset, $whence)) {
|
||||||
|
$this->position = ftell($this->handle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_tell()
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_eof()
|
||||||
|
{
|
||||||
|
return feof($this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_stat()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stream_set_option($option, $arg1, $arg2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function url_stat($path, $flags)
|
||||||
|
{
|
||||||
|
$path = substr($path, 17);
|
||||||
|
if (file_exists($path)) {
|
||||||
|
return stat($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
||||||
|
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
||||||
|
) {
|
||||||
|
return include("phpvfscomposer://" . __DIR__ . '/..'.'/symfony/yaml/Resources/bin/yaml-lint');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return include __DIR__ . '/..'.'/symfony/yaml/Resources/bin/yaml-lint';
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
setlocal DISABLEDELAYEDEXPANSION
|
||||||
|
SET BIN_TARGET=%~dp0/yaml-lint
|
||||||
|
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
||||||
|
php "%BIN_TARGET%" %*
|
||||||
Vendored
+579
@@ -0,0 +1,579 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||||
|
*
|
||||||
|
* $loader = new \Composer\Autoload\ClassLoader();
|
||||||
|
*
|
||||||
|
* // register classes with namespaces
|
||||||
|
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||||
|
* $loader->add('Symfony', __DIR__.'/framework');
|
||||||
|
*
|
||||||
|
* // activate the autoloader
|
||||||
|
* $loader->register();
|
||||||
|
*
|
||||||
|
* // to enable searching the include path (eg. for PEAR packages)
|
||||||
|
* $loader->setUseIncludePath(true);
|
||||||
|
*
|
||||||
|
* In this example, if you try to use a class in the Symfony\Component
|
||||||
|
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||||
|
* the autoloader will first look for the class under the component/
|
||||||
|
* directory, and it will then fallback to the framework/ directory if not
|
||||||
|
* found before giving up.
|
||||||
|
*
|
||||||
|
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
* @see https://www.php-fig.org/psr/psr-0/
|
||||||
|
* @see https://www.php-fig.org/psr/psr-4/
|
||||||
|
*/
|
||||||
|
class ClassLoader
|
||||||
|
{
|
||||||
|
/** @var \Closure(string):void */
|
||||||
|
private static $includeFile;
|
||||||
|
|
||||||
|
/** @var string|null */
|
||||||
|
private $vendorDir;
|
||||||
|
|
||||||
|
// PSR-4
|
||||||
|
/**
|
||||||
|
* @var array<string, array<string, int>>
|
||||||
|
*/
|
||||||
|
private $prefixLengthsPsr4 = array();
|
||||||
|
/**
|
||||||
|
* @var array<string, list<string>>
|
||||||
|
*/
|
||||||
|
private $prefixDirsPsr4 = array();
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
private $fallbackDirsPsr4 = array();
|
||||||
|
|
||||||
|
// PSR-0
|
||||||
|
/**
|
||||||
|
* List of PSR-0 prefixes
|
||||||
|
*
|
||||||
|
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
|
||||||
|
*
|
||||||
|
* @var array<string, array<string, list<string>>>
|
||||||
|
*/
|
||||||
|
private $prefixesPsr0 = array();
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
private $fallbackDirsPsr0 = array();
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $useIncludePath = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
private $classMap = array();
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $classMapAuthoritative = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, bool>
|
||||||
|
*/
|
||||||
|
private $missingClasses = array();
|
||||||
|
|
||||||
|
/** @var string|null */
|
||||||
|
private $apcuPrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, self>
|
||||||
|
*/
|
||||||
|
private static $registeredLoaders = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|null $vendorDir
|
||||||
|
*/
|
||||||
|
public function __construct($vendorDir = null)
|
||||||
|
{
|
||||||
|
$this->vendorDir = $vendorDir;
|
||||||
|
self::initializeIncludeClosure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, list<string>>
|
||||||
|
*/
|
||||||
|
public function getPrefixes()
|
||||||
|
{
|
||||||
|
if (!empty($this->prefixesPsr0)) {
|
||||||
|
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, list<string>>
|
||||||
|
*/
|
||||||
|
public function getPrefixesPsr4()
|
||||||
|
{
|
||||||
|
return $this->prefixDirsPsr4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public function getFallbackDirs()
|
||||||
|
{
|
||||||
|
return $this->fallbackDirsPsr0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public function getFallbackDirsPsr4()
|
||||||
|
{
|
||||||
|
return $this->fallbackDirsPsr4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string> Array of classname => path
|
||||||
|
*/
|
||||||
|
public function getClassMap()
|
||||||
|
{
|
||||||
|
return $this->classMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, string> $classMap Class to filename map
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addClassMap(array $classMap)
|
||||||
|
{
|
||||||
|
if ($this->classMap) {
|
||||||
|
$this->classMap = array_merge($this->classMap, $classMap);
|
||||||
|
} else {
|
||||||
|
$this->classMap = $classMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a set of PSR-0 directories for a given prefix, either
|
||||||
|
* appending or prepending to the ones previously set for this prefix.
|
||||||
|
*
|
||||||
|
* @param string $prefix The prefix
|
||||||
|
* @param list<string>|string $paths The PSR-0 root directories
|
||||||
|
* @param bool $prepend Whether to prepend the directories
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function add($prefix, $paths, $prepend = false)
|
||||||
|
{
|
||||||
|
$paths = (array) $paths;
|
||||||
|
if (!$prefix) {
|
||||||
|
if ($prepend) {
|
||||||
|
$this->fallbackDirsPsr0 = array_merge(
|
||||||
|
$paths,
|
||||||
|
$this->fallbackDirsPsr0
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->fallbackDirsPsr0 = array_merge(
|
||||||
|
$this->fallbackDirsPsr0,
|
||||||
|
$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$first = $prefix[0];
|
||||||
|
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||||
|
$this->prefixesPsr0[$first][$prefix] = $paths;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($prepend) {
|
||||||
|
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
|
$paths,
|
||||||
|
$this->prefixesPsr0[$first][$prefix]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
|
$this->prefixesPsr0[$first][$prefix],
|
||||||
|
$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a set of PSR-4 directories for a given namespace, either
|
||||||
|
* appending or prepending to the ones previously set for this namespace.
|
||||||
|
*
|
||||||
|
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||||
|
* @param list<string>|string $paths The PSR-4 base directories
|
||||||
|
* @param bool $prepend Whether to prepend the directories
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addPsr4($prefix, $paths, $prepend = false)
|
||||||
|
{
|
||||||
|
$paths = (array) $paths;
|
||||||
|
if (!$prefix) {
|
||||||
|
// Register directories for the root namespace.
|
||||||
|
if ($prepend) {
|
||||||
|
$this->fallbackDirsPsr4 = array_merge(
|
||||||
|
$paths,
|
||||||
|
$this->fallbackDirsPsr4
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->fallbackDirsPsr4 = array_merge(
|
||||||
|
$this->fallbackDirsPsr4,
|
||||||
|
$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||||
|
// Register directories for a new namespace.
|
||||||
|
$length = strlen($prefix);
|
||||||
|
if ('\\' !== $prefix[$length - 1]) {
|
||||||
|
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||||
|
}
|
||||||
|
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||||
|
$this->prefixDirsPsr4[$prefix] = $paths;
|
||||||
|
} elseif ($prepend) {
|
||||||
|
// Prepend directories for an already registered namespace.
|
||||||
|
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||||
|
$paths,
|
||||||
|
$this->prefixDirsPsr4[$prefix]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Append directories for an already registered namespace.
|
||||||
|
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||||
|
$this->prefixDirsPsr4[$prefix],
|
||||||
|
$paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a set of PSR-0 directories for a given prefix,
|
||||||
|
* replacing any others previously set for this prefix.
|
||||||
|
*
|
||||||
|
* @param string $prefix The prefix
|
||||||
|
* @param list<string>|string $paths The PSR-0 base directories
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function set($prefix, $paths)
|
||||||
|
{
|
||||||
|
if (!$prefix) {
|
||||||
|
$this->fallbackDirsPsr0 = (array) $paths;
|
||||||
|
} else {
|
||||||
|
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a set of PSR-4 directories for a given namespace,
|
||||||
|
* replacing any others previously set for this namespace.
|
||||||
|
*
|
||||||
|
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||||
|
* @param list<string>|string $paths The PSR-4 base directories
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPsr4($prefix, $paths)
|
||||||
|
{
|
||||||
|
if (!$prefix) {
|
||||||
|
$this->fallbackDirsPsr4 = (array) $paths;
|
||||||
|
} else {
|
||||||
|
$length = strlen($prefix);
|
||||||
|
if ('\\' !== $prefix[$length - 1]) {
|
||||||
|
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||||
|
}
|
||||||
|
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||||
|
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns on searching the include path for class files.
|
||||||
|
*
|
||||||
|
* @param bool $useIncludePath
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUseIncludePath($useIncludePath)
|
||||||
|
{
|
||||||
|
$this->useIncludePath = $useIncludePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used to check if the autoloader uses the include path to check
|
||||||
|
* for classes.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getUseIncludePath()
|
||||||
|
{
|
||||||
|
return $this->useIncludePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns off searching the prefix and fallback directories for classes
|
||||||
|
* that have not been registered with the class map.
|
||||||
|
*
|
||||||
|
* @param bool $classMapAuthoritative
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||||
|
{
|
||||||
|
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should class lookup fail if not found in the current class map?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isClassMapAuthoritative()
|
||||||
|
{
|
||||||
|
return $this->classMapAuthoritative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||||
|
*
|
||||||
|
* @param string|null $apcuPrefix
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setApcuPrefix($apcuPrefix)
|
||||||
|
{
|
||||||
|
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getApcuPrefix()
|
||||||
|
{
|
||||||
|
return $this->apcuPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers this instance as an autoloader.
|
||||||
|
*
|
||||||
|
* @param bool $prepend Whether to prepend the autoloader or not
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register($prepend = false)
|
||||||
|
{
|
||||||
|
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||||
|
|
||||||
|
if (null === $this->vendorDir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prepend) {
|
||||||
|
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||||
|
} else {
|
||||||
|
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||||
|
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters this instance as an autoloader.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unregister()
|
||||||
|
{
|
||||||
|
spl_autoload_unregister(array($this, 'loadClass'));
|
||||||
|
|
||||||
|
if (null !== $this->vendorDir) {
|
||||||
|
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given class or interface.
|
||||||
|
*
|
||||||
|
* @param string $class The name of the class
|
||||||
|
* @return true|null True if loaded, null otherwise
|
||||||
|
*/
|
||||||
|
public function loadClass($class)
|
||||||
|
{
|
||||||
|
if ($file = $this->findFile($class)) {
|
||||||
|
$includeFile = self::$includeFile;
|
||||||
|
$includeFile($file);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the path to the file where the class is defined.
|
||||||
|
*
|
||||||
|
* @param string $class The name of the class
|
||||||
|
*
|
||||||
|
* @return string|false The path if found, false otherwise
|
||||||
|
*/
|
||||||
|
public function findFile($class)
|
||||||
|
{
|
||||||
|
// class map lookup
|
||||||
|
if (isset($this->classMap[$class])) {
|
||||||
|
return $this->classMap[$class];
|
||||||
|
}
|
||||||
|
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (null !== $this->apcuPrefix) {
|
||||||
|
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||||
|
if ($hit) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = $this->findFileWithExtension($class, '.php');
|
||||||
|
|
||||||
|
// Search for Hack files if we are running on HHVM
|
||||||
|
if (false === $file && defined('HHVM_VERSION')) {
|
||||||
|
$file = $this->findFileWithExtension($class, '.hh');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $this->apcuPrefix) {
|
||||||
|
apcu_add($this->apcuPrefix.$class, $file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $file) {
|
||||||
|
// Remember that this class does not exist.
|
||||||
|
$this->missingClasses[$class] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently registered loaders keyed by their corresponding vendor directories.
|
||||||
|
*
|
||||||
|
* @return array<string, self>
|
||||||
|
*/
|
||||||
|
public static function getRegisteredLoaders()
|
||||||
|
{
|
||||||
|
return self::$registeredLoaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $class
|
||||||
|
* @param string $ext
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
private function findFileWithExtension($class, $ext)
|
||||||
|
{
|
||||||
|
// PSR-4 lookup
|
||||||
|
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||||
|
|
||||||
|
$first = $class[0];
|
||||||
|
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||||
|
$subPath = $class;
|
||||||
|
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||||
|
$subPath = substr($subPath, 0, $lastPos);
|
||||||
|
$search = $subPath . '\\';
|
||||||
|
if (isset($this->prefixDirsPsr4[$search])) {
|
||||||
|
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||||
|
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||||
|
if (file_exists($file = $dir . $pathEnd)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PSR-4 fallback dirs
|
||||||
|
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||||
|
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PSR-0 lookup
|
||||||
|
if (false !== $pos = strrpos($class, '\\')) {
|
||||||
|
// namespaced class name
|
||||||
|
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||||
|
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||||
|
} else {
|
||||||
|
// PEAR-like class name
|
||||||
|
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->prefixesPsr0[$first])) {
|
||||||
|
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||||
|
if (0 === strpos($class, $prefix)) {
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PSR-0 fallback dirs
|
||||||
|
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||||
|
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PSR-0 include paths.
|
||||||
|
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function initializeIncludeClosure()
|
||||||
|
{
|
||||||
|
if (self::$includeFile !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope isolated include.
|
||||||
|
*
|
||||||
|
* Prevents access to $this/self from included files.
|
||||||
|
*
|
||||||
|
* @param string $file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
self::$includeFile = \Closure::bind(static function($file) {
|
||||||
|
include $file;
|
||||||
|
}, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
+396
@@ -0,0 +1,396 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer;
|
||||||
|
|
||||||
|
use Composer\Autoload\ClassLoader;
|
||||||
|
use Composer\Semver\VersionParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is copied in every Composer installed project and available to all
|
||||||
|
*
|
||||||
|
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||||
|
*
|
||||||
|
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||||
|
*
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
class InstalledVersions
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
private static $selfDir = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var mixed[]|null
|
||||||
|
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
|
||||||
|
*/
|
||||||
|
private static $installed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $installedIsLocalDir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool|null
|
||||||
|
*/
|
||||||
|
private static $canGetVendors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array[]
|
||||||
|
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||||
|
*/
|
||||||
|
private static $installedByVendor = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
* @psalm-return list<string>
|
||||||
|
*/
|
||||||
|
public static function getInstalledPackages()
|
||||||
|
{
|
||||||
|
$packages = array();
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
$packages[] = array_keys($installed['versions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (1 === \count($packages)) {
|
||||||
|
return $packages[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all package names with a specific type e.g. 'library'
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @return string[]
|
||||||
|
* @psalm-return list<string>
|
||||||
|
*/
|
||||||
|
public static function getInstalledPackagesByType($type)
|
||||||
|
{
|
||||||
|
$packagesByType = array();
|
||||||
|
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
foreach ($installed['versions'] as $name => $package) {
|
||||||
|
if (isset($package['type']) && $package['type'] === $type) {
|
||||||
|
$packagesByType[] = $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $packagesByType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given package is installed
|
||||||
|
*
|
||||||
|
* This also returns true if the package name is provided or replaced by another package
|
||||||
|
*
|
||||||
|
* @param string $packageName
|
||||||
|
* @param bool $includeDevRequirements
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (isset($installed['versions'][$packageName])) {
|
||||||
|
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given package satisfies a version constraint
|
||||||
|
*
|
||||||
|
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||||
|
*
|
||||||
|
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||||
|
*
|
||||||
|
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||||
|
* @param string $packageName
|
||||||
|
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||||
|
{
|
||||||
|
$constraint = $parser->parseConstraints((string) $constraint);
|
||||||
|
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||||
|
|
||||||
|
return $provided->matches($constraint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||||
|
*
|
||||||
|
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||||
|
* whether a given version of a package is installed, and not just whether it exists
|
||||||
|
*
|
||||||
|
* @param string $packageName
|
||||||
|
* @return string Version constraint usable with composer/semver
|
||||||
|
*/
|
||||||
|
public static function getVersionRanges($packageName)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (!isset($installed['versions'][$packageName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ranges = array();
|
||||||
|
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||||
|
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||||
|
}
|
||||||
|
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||||
|
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||||
|
}
|
||||||
|
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||||
|
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||||
|
}
|
||||||
|
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||||
|
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' || ', $ranges);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $packageName
|
||||||
|
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||||
|
*/
|
||||||
|
public static function getVersion($packageName)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (!isset($installed['versions'][$packageName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $installed['versions'][$packageName]['version'];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $packageName
|
||||||
|
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||||
|
*/
|
||||||
|
public static function getPrettyVersion($packageName)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (!isset($installed['versions'][$packageName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $installed['versions'][$packageName]['pretty_version'];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $packageName
|
||||||
|
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||||
|
*/
|
||||||
|
public static function getReference($packageName)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (!isset($installed['versions'][$packageName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $installed['versions'][$packageName]['reference'];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $packageName
|
||||||
|
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||||
|
*/
|
||||||
|
public static function getInstallPath($packageName)
|
||||||
|
{
|
||||||
|
foreach (self::getInstalled() as $installed) {
|
||||||
|
if (!isset($installed['versions'][$packageName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
||||||
|
*/
|
||||||
|
public static function getRootPackage()
|
||||||
|
{
|
||||||
|
$installed = self::getInstalled();
|
||||||
|
|
||||||
|
return $installed[0]['root'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the raw installed.php data for custom implementations
|
||||||
|
*
|
||||||
|
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||||
|
* @return array[]
|
||||||
|
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
||||||
|
*/
|
||||||
|
public static function getRawData()
|
||||||
|
{
|
||||||
|
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
if (null === self::$installed) {
|
||||||
|
// only require the installed.php file if this file is loaded from its dumped location,
|
||||||
|
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||||
|
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||||
|
self::$installed = include __DIR__ . '/installed.php';
|
||||||
|
} else {
|
||||||
|
self::$installed = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||||
|
*
|
||||||
|
* @return array[]
|
||||||
|
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||||
|
*/
|
||||||
|
public static function getAllRawData()
|
||||||
|
{
|
||||||
|
return self::getInstalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets you reload the static array from another file
|
||||||
|
*
|
||||||
|
* This is only useful for complex integrations in which a project needs to use
|
||||||
|
* this class but then also needs to execute another project's autoloader in process,
|
||||||
|
* and wants to ensure both projects have access to their version of installed.php.
|
||||||
|
*
|
||||||
|
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||||
|
* the data it needs from this class, then call reload() with
|
||||||
|
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||||
|
* the project in which it runs can then also use this class safely, without
|
||||||
|
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||||
|
*
|
||||||
|
* @param array[] $data A vendor/composer/installed.php data set
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
||||||
|
*/
|
||||||
|
public static function reload($data)
|
||||||
|
{
|
||||||
|
self::$installed = $data;
|
||||||
|
self::$installedByVendor = array();
|
||||||
|
|
||||||
|
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
|
||||||
|
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
|
||||||
|
// so we have to assume it does not, and that may result in duplicate data being returned when listing
|
||||||
|
// all installed packages for example
|
||||||
|
self::$installedIsLocalDir = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function getSelfDir()
|
||||||
|
{
|
||||||
|
if (self::$selfDir === null) {
|
||||||
|
self::$selfDir = strtr(__DIR__, '\\', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$selfDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||||
|
*/
|
||||||
|
private static function getInstalled()
|
||||||
|
{
|
||||||
|
if (null === self::$canGetVendors) {
|
||||||
|
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||||
|
}
|
||||||
|
|
||||||
|
$installed = array();
|
||||||
|
$copiedLocalDir = false;
|
||||||
|
|
||||||
|
if (self::$canGetVendors) {
|
||||||
|
$selfDir = self::getSelfDir();
|
||||||
|
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||||
|
$vendorDir = strtr($vendorDir, '\\', '/');
|
||||||
|
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||||
|
$installed[] = self::$installedByVendor[$vendorDir];
|
||||||
|
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||||
|
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||||
|
$required = require $vendorDir.'/composer/installed.php';
|
||||||
|
self::$installedByVendor[$vendorDir] = $required;
|
||||||
|
$installed[] = $required;
|
||||||
|
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
|
||||||
|
self::$installed = $required;
|
||||||
|
self::$installedIsLocalDir = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
|
||||||
|
$copiedLocalDir = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === self::$installed) {
|
||||||
|
// only require the installed.php file if this file is loaded from its dumped location,
|
||||||
|
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||||
|
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||||
|
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||||
|
$required = require __DIR__ . '/installed.php';
|
||||||
|
self::$installed = $required;
|
||||||
|
} else {
|
||||||
|
self::$installed = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$installed !== array() && !$copiedLocalDir) {
|
||||||
|
$installed[] = self::$installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $installed;
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+21
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_classmap.php @generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(__DIR__);
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||||
|
);
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php @generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(__DIR__);
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
|
||||||
|
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
|
||||||
|
);
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_namespaces.php @generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(__DIR__);
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
);
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_psr4.php @generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(__DIR__);
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
|
||||||
|
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
|
||||||
|
);
|
||||||
Vendored
+50
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
|
class ComposerAutoloaderInit1d14b066a73960476c178ecf92bed18f
|
||||||
|
{
|
||||||
|
private static $loader;
|
||||||
|
|
||||||
|
public static function loadClassLoader($class)
|
||||||
|
{
|
||||||
|
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||||
|
require __DIR__ . '/ClassLoader.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Composer\Autoload\ClassLoader
|
||||||
|
*/
|
||||||
|
public static function getLoader()
|
||||||
|
{
|
||||||
|
if (null !== self::$loader) {
|
||||||
|
return self::$loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
require __DIR__ . '/platform_check.php';
|
||||||
|
|
||||||
|
spl_autoload_register(array('ComposerAutoloaderInit1d14b066a73960476c178ecf92bed18f', 'loadClassLoader'), true, true);
|
||||||
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||||
|
spl_autoload_unregister(array('ComposerAutoloaderInit1d14b066a73960476c178ecf92bed18f', 'loadClassLoader'));
|
||||||
|
|
||||||
|
require __DIR__ . '/autoload_static.php';
|
||||||
|
call_user_func(\Composer\Autoload\ComposerStaticInit1d14b066a73960476c178ecf92bed18f::getInitializer($loader));
|
||||||
|
|
||||||
|
$loader->register(true);
|
||||||
|
|
||||||
|
$filesToLoad = \Composer\Autoload\ComposerStaticInit1d14b066a73960476c178ecf92bed18f::$files;
|
||||||
|
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||||
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
|
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||||
|
|
||||||
|
require $file;
|
||||||
|
}
|
||||||
|
}, null, null);
|
||||||
|
foreach ($filesToLoad as $fileIdentifier => $file) {
|
||||||
|
$requireFile($fileIdentifier, $file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $loader;
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+46
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_static.php @generated by Composer
|
||||||
|
|
||||||
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
|
class ComposerStaticInit1d14b066a73960476c178ecf92bed18f
|
||||||
|
{
|
||||||
|
public static $files = array (
|
||||||
|
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
|
||||||
|
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
|
||||||
|
);
|
||||||
|
|
||||||
|
public static $prefixLengthsPsr4 = array (
|
||||||
|
'S' =>
|
||||||
|
array (
|
||||||
|
'Symfony\\Polyfill\\Ctype\\' => 23,
|
||||||
|
'Symfony\\Component\\Yaml\\' => 23,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
public static $prefixDirsPsr4 = array (
|
||||||
|
'Symfony\\Polyfill\\Ctype\\' =>
|
||||||
|
array (
|
||||||
|
0 => __DIR__ . '/..' . '/symfony/polyfill-ctype',
|
||||||
|
),
|
||||||
|
'Symfony\\Component\\Yaml\\' =>
|
||||||
|
array (
|
||||||
|
0 => __DIR__ . '/..' . '/symfony/yaml',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
public static $classMap = array (
|
||||||
|
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function getInitializer(ClassLoader $loader)
|
||||||
|
{
|
||||||
|
return \Closure::bind(function () use ($loader) {
|
||||||
|
$loader->prefixLengthsPsr4 = ComposerStaticInit1d14b066a73960476c178ecf92bed18f::$prefixLengthsPsr4;
|
||||||
|
$loader->prefixDirsPsr4 = ComposerStaticInit1d14b066a73960476c178ecf92bed18f::$prefixDirsPsr4;
|
||||||
|
$loader->classMap = ComposerStaticInit1d14b066a73960476c178ecf92bed18f::$classMap;
|
||||||
|
|
||||||
|
}, null, ClassLoader::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+241
@@ -0,0 +1,241 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "symfony/deprecation-contracts",
|
||||||
|
"version": "v3.6.0",
|
||||||
|
"version_normalized": "3.6.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||||
|
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||||
|
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.1"
|
||||||
|
},
|
||||||
|
"time": "2024-09-25T14:21:43+00:00",
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"url": "https://github.com/symfony/contracts",
|
||||||
|
"name": "symfony/contracts"
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "3.6-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"installation-source": "dist",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"function.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nicolas Grekas",
|
||||||
|
"email": "p@tchwork.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A generic function and convention to trigger deprecation notices",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"install-path": "../symfony/deprecation-contracts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/polyfill-ctype",
|
||||||
|
"version": "v1.33.0",
|
||||||
|
"version_normalized": "1.33.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||||
|
"reference": "a3cc8b044a6ea513310cbd48ef7333b384945638"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638",
|
||||||
|
"reference": "a3cc8b044a6ea513310cbd48ef7333b384945638",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.2"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"ext-ctype": "*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-ctype": "For best performance"
|
||||||
|
},
|
||||||
|
"time": "2024-09-09T11:45:10+00:00",
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"url": "https://github.com/symfony/polyfill",
|
||||||
|
"name": "symfony/polyfill"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"installation-source": "dist",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"bootstrap.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Polyfill\\Ctype\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Gert de Pagter",
|
||||||
|
"email": "BackEndTea@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony polyfill for ctype functions",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"keywords": [
|
||||||
|
"compatibility",
|
||||||
|
"ctype",
|
||||||
|
"polyfill",
|
||||||
|
"portable"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.33.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"install-path": "../symfony/polyfill-ctype"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/yaml",
|
||||||
|
"version": "v7.4.6",
|
||||||
|
"version_normalized": "7.4.6.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/yaml.git",
|
||||||
|
"reference": "58751048de17bae71c5aa0d13cb19d79bca26391"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/yaml/zipball/58751048de17bae71c5aa0d13cb19d79bca26391",
|
||||||
|
"reference": "58751048de17bae71c5aa0d13cb19d79bca26391",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
|
"symfony/deprecation-contracts": "^2.5|^3",
|
||||||
|
"symfony/polyfill-ctype": "^1.8"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/console": "<6.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/console": "^6.4|^7.0|^8.0"
|
||||||
|
},
|
||||||
|
"time": "2026-02-09T09:33:46+00:00",
|
||||||
|
"bin": [
|
||||||
|
"Resources/bin/yaml-lint"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"installation-source": "dist",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Yaml\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Loads and dumps YAML files",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/yaml/tree/v7.4.6"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"install-path": "../symfony/yaml"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"dev-package-names": []
|
||||||
|
}
|
||||||
Vendored
+50
@@ -0,0 +1,50 @@
|
|||||||
|
<?php return array(
|
||||||
|
'root' => array(
|
||||||
|
'name' => '__root__',
|
||||||
|
'pretty_version' => '1.0.0+no-version-set',
|
||||||
|
'version' => '1.0.0.0',
|
||||||
|
'reference' => null,
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../../',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev' => true,
|
||||||
|
),
|
||||||
|
'versions' => array(
|
||||||
|
'__root__' => array(
|
||||||
|
'pretty_version' => '1.0.0+no-version-set',
|
||||||
|
'version' => '1.0.0.0',
|
||||||
|
'reference' => null,
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../../',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
|
'symfony/deprecation-contracts' => array(
|
||||||
|
'pretty_version' => 'v3.6.0',
|
||||||
|
'version' => '3.6.0.0',
|
||||||
|
'reference' => '63afe740e99a13ba87ec199bb07bbdee937a5b62',
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../symfony/deprecation-contracts',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
|
'symfony/polyfill-ctype' => array(
|
||||||
|
'pretty_version' => 'v1.33.0',
|
||||||
|
'version' => '1.33.0.0',
|
||||||
|
'reference' => 'a3cc8b044a6ea513310cbd48ef7333b384945638',
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
|
'symfony/yaml' => array(
|
||||||
|
'pretty_version' => 'v7.4.6',
|
||||||
|
'version' => '7.4.6.0',
|
||||||
|
'reference' => '58751048de17bae71c5aa0d13cb19d79bca26391',
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../symfony/yaml',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
Vendored
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// platform_check.php @generated by Composer
|
||||||
|
|
||||||
|
$issues = array();
|
||||||
|
|
||||||
|
if (!(PHP_VERSION_ID >= 80200)) {
|
||||||
|
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.2.0". You are running ' . PHP_VERSION . '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($issues) {
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
|
}
|
||||||
|
if (!ini_get('display_errors')) {
|
||||||
|
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||||
|
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||||
|
} elseif (!headers_sent()) {
|
||||||
|
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Composer detected issues in your platform: ' . implode(' ', $issues)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
CHANGELOG
|
||||||
|
=========
|
||||||
|
|
||||||
|
The changelog is maintained for all Symfony contracts at the following URL:
|
||||||
|
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2020-present Fabien Potencier
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
Symfony Deprecation Contracts
|
||||||
|
=============================
|
||||||
|
|
||||||
|
A generic function and convention to trigger deprecation notices.
|
||||||
|
|
||||||
|
This package provides a single global function named `trigger_deprecation()` that triggers silenced deprecation notices.
|
||||||
|
|
||||||
|
By using a custom PHP error handler such as the one provided by the Symfony ErrorHandler component,
|
||||||
|
the triggered deprecations can be caught and logged for later discovery, both on dev and prod environments.
|
||||||
|
|
||||||
|
The function requires at least 3 arguments:
|
||||||
|
- the name of the Composer package that is triggering the deprecation
|
||||||
|
- the version of the package that introduced the deprecation
|
||||||
|
- the message of the deprecation
|
||||||
|
- more arguments can be provided: they will be inserted in the message using `printf()` formatting
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```php
|
||||||
|
trigger_deprecation('symfony/blockchain', '8.9', 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin');
|
||||||
|
```
|
||||||
|
|
||||||
|
This will generate the following message:
|
||||||
|
`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.`
|
||||||
|
|
||||||
|
While not recommended, the deprecation notices can be completely ignored by declaring an empty
|
||||||
|
`function trigger_deprecation() {}` in your application.
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "symfony/deprecation-contracts",
|
||||||
|
"type": "library",
|
||||||
|
"description": "A generic function and convention to trigger deprecation notices",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nicolas Grekas",
|
||||||
|
"email": "p@tchwork.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"function.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "3.6-dev"
|
||||||
|
},
|
||||||
|
"thanks": {
|
||||||
|
"name": "symfony/contracts",
|
||||||
|
"url": "https://github.com/symfony/contracts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!function_exists('trigger_deprecation')) {
|
||||||
|
/**
|
||||||
|
* Triggers a silenced deprecation notice.
|
||||||
|
*
|
||||||
|
* @param string $package The name of the Composer package that is triggering the deprecation
|
||||||
|
* @param string $version The version of the package that introduced the deprecation
|
||||||
|
* @param string $message The message of the deprecation
|
||||||
|
* @param mixed ...$args Values to insert in the message using printf() formatting
|
||||||
|
*
|
||||||
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
*/
|
||||||
|
function trigger_deprecation(string $package, string $version, string $message, mixed ...$args): void
|
||||||
|
{
|
||||||
|
@trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
+232
@@ -0,0 +1,232 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Polyfill\Ctype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctype implementation through regex.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @author Gert de Pagter <BackEndTea@gmail.com>
|
||||||
|
*/
|
||||||
|
final class Ctype
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-alnum
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_alnum($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is a letter, FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-alpha
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_alpha($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-cntrl
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_cntrl($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-digit
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_digit($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-graph
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_graph($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is a lowercase letter.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-lower
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_lower($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-print
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_print($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-punct
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_punct($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-space
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_space($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is an uppercase letter.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-upper
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_upper($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
|
||||||
|
*
|
||||||
|
* @see https://php.net/ctype-xdigit
|
||||||
|
*
|
||||||
|
* @param mixed $text
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function ctype_xdigit($text)
|
||||||
|
{
|
||||||
|
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||||
|
|
||||||
|
return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts integers to their char versions according to normal ctype behaviour, if needed.
|
||||||
|
*
|
||||||
|
* If an integer between -128 and 255 inclusive is provided,
|
||||||
|
* it is interpreted as the ASCII value of a single character
|
||||||
|
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
|
||||||
|
* Any other integer is interpreted as a string containing the decimal digits of the integer.
|
||||||
|
*
|
||||||
|
* @param mixed $int
|
||||||
|
* @param string $function
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private static function convert_int_to_char_for_ctype($int, $function)
|
||||||
|
{
|
||||||
|
if (!\is_int($int)) {
|
||||||
|
return $int;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($int < -128 || $int > 255) {
|
||||||
|
return (string) $int;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 80100) {
|
||||||
|
@trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($int < 0) {
|
||||||
|
$int += 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
return \chr($int);
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2018-present Fabien Potencier
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
Symfony Polyfill / Ctype
|
||||||
|
========================
|
||||||
|
|
||||||
|
This component provides `ctype_*` functions to users who run php versions without the ctype extension.
|
||||||
|
|
||||||
|
More information can be found in the
|
||||||
|
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||||
|
|
||||||
|
License
|
||||||
|
=======
|
||||||
|
|
||||||
|
This library is released under the [MIT license](LICENSE).
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Polyfill\Ctype as p;
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 80000) {
|
||||||
|
return require __DIR__.'/bootstrap80.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('ctype_alnum')) {
|
||||||
|
function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_alpha')) {
|
||||||
|
function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_cntrl')) {
|
||||||
|
function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_digit')) {
|
||||||
|
function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_graph')) {
|
||||||
|
function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_lower')) {
|
||||||
|
function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_print')) {
|
||||||
|
function ctype_print($text) { return p\Ctype::ctype_print($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_punct')) {
|
||||||
|
function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_space')) {
|
||||||
|
function ctype_space($text) { return p\Ctype::ctype_space($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_upper')) {
|
||||||
|
function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_xdigit')) {
|
||||||
|
function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Polyfill\Ctype as p;
|
||||||
|
|
||||||
|
if (!function_exists('ctype_alnum')) {
|
||||||
|
function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_alpha')) {
|
||||||
|
function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_cntrl')) {
|
||||||
|
function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_digit')) {
|
||||||
|
function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_graph')) {
|
||||||
|
function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_lower')) {
|
||||||
|
function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_print')) {
|
||||||
|
function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_punct')) {
|
||||||
|
function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_space')) {
|
||||||
|
function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_upper')) {
|
||||||
|
function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); }
|
||||||
|
}
|
||||||
|
if (!function_exists('ctype_xdigit')) {
|
||||||
|
function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); }
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "symfony/polyfill-ctype",
|
||||||
|
"type": "library",
|
||||||
|
"description": "Symfony polyfill for ctype functions",
|
||||||
|
"keywords": ["polyfill", "compatibility", "portable", "ctype"],
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Gert de Pagter",
|
||||||
|
"email": "BackEndTea@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.2"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"ext-ctype": "*"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": { "Symfony\\Polyfill\\Ctype\\": "" },
|
||||||
|
"files": [ "bootstrap.php" ]
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-ctype": "For best performance"
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"extra": {
|
||||||
|
"thanks": {
|
||||||
|
"name": "symfony/polyfill",
|
||||||
|
"url": "https://github.com/symfony/polyfill"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+275
@@ -0,0 +1,275 @@
|
|||||||
|
CHANGELOG
|
||||||
|
=========
|
||||||
|
|
||||||
|
7.3
|
||||||
|
---
|
||||||
|
|
||||||
|
* Add compact nested mapping support by using the `Yaml::DUMP_COMPACT_NESTED_MAPPING` flag
|
||||||
|
* Add the `Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES` flag to enforce double quotes around string values
|
||||||
|
|
||||||
|
7.2
|
||||||
|
---
|
||||||
|
|
||||||
|
* Deprecate parsing duplicate mapping keys whose value is `null`
|
||||||
|
* Add support for dumping `null` as an empty value by using the `Yaml::DUMP_NULL_AS_EMPTY` flag
|
||||||
|
|
||||||
|
7.1
|
||||||
|
---
|
||||||
|
|
||||||
|
* Add support for getting all the enum cases with `!php/enum Foo`
|
||||||
|
|
||||||
|
7.0
|
||||||
|
---
|
||||||
|
|
||||||
|
* Remove the `!php/const:` tag, use `!php/const` instead (without the colon)
|
||||||
|
|
||||||
|
6.3
|
||||||
|
---
|
||||||
|
|
||||||
|
* Add support to dump int keys as strings by using the `Yaml::DUMP_NUMERIC_KEY_AS_STRING` flag
|
||||||
|
|
||||||
|
6.2
|
||||||
|
---
|
||||||
|
|
||||||
|
* Add support for `!php/enum` and `!php/enum *->value`
|
||||||
|
* Deprecate the `!php/const:` tag in key which will be replaced by the `!php/const` tag (without the colon) since 3.4
|
||||||
|
|
||||||
|
6.1
|
||||||
|
---
|
||||||
|
|
||||||
|
* In cases where it will likely improve readability, strings containing single quotes will be double-quoted
|
||||||
|
|
||||||
|
5.4
|
||||||
|
---
|
||||||
|
|
||||||
|
* Add new `lint:yaml dirname --exclude=/dirname/foo.yaml --exclude=/dirname/bar.yaml`
|
||||||
|
option to exclude one or more specific files from multiple file list
|
||||||
|
* Allow negatable for the parse tags option with `--no-parse-tags`
|
||||||
|
|
||||||
|
5.3
|
||||||
|
---
|
||||||
|
|
||||||
|
* Added `github` format support & autodetection to render errors as annotations
|
||||||
|
when running the YAML linter command in a Github Action environment.
|
||||||
|
|
||||||
|
5.1.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added support for parsing numbers prefixed with `0o` as octal numbers.
|
||||||
|
* Deprecated support for parsing numbers starting with `0` as octal numbers. They will be parsed as strings as of Symfony 6.0. Prefix numbers with `0o`
|
||||||
|
so that they are parsed as octal numbers.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
Yaml::parse('072');
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
Yaml::parse('0o72');
|
||||||
|
```
|
||||||
|
|
||||||
|
* Added `yaml-lint` binary.
|
||||||
|
* Deprecated using the `!php/object` and `!php/const` tags without a value.
|
||||||
|
|
||||||
|
5.0.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Removed support for mappings inside multi-line strings.
|
||||||
|
* removed support for implicit STDIN usage in the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.
|
||||||
|
|
||||||
|
4.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added support for parsing the inline notation spanning multiple lines.
|
||||||
|
* Added support to dump `null` as `~` by using the `Yaml::DUMP_NULL_AS_TILDE` flag.
|
||||||
|
* deprecated accepting STDIN implicitly when using the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.
|
||||||
|
|
||||||
|
4.3.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
|
||||||
|
|
||||||
|
4.2.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* added support for multiple files or directories in `LintCommand`
|
||||||
|
|
||||||
|
4.0.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* The behavior of the non-specific tag `!` is changed and now forces
|
||||||
|
non-evaluating your values.
|
||||||
|
* complex mappings will throw a `ParseException`
|
||||||
|
* support for the comma as a group separator for floats has been dropped, use
|
||||||
|
the underscore instead
|
||||||
|
* support for the `!!php/object` tag has been dropped, use the `!php/object`
|
||||||
|
tag instead
|
||||||
|
* duplicate mapping keys throw a `ParseException`
|
||||||
|
* non-string mapping keys throw a `ParseException`, use the `Yaml::PARSE_KEYS_AS_STRINGS`
|
||||||
|
flag to cast them to strings
|
||||||
|
* `%` at the beginning of an unquoted string throw a `ParseException`
|
||||||
|
* mappings with a colon (`:`) that is not followed by a whitespace throw a
|
||||||
|
`ParseException`
|
||||||
|
* the `Dumper::setIndentation()` method has been removed
|
||||||
|
* being able to pass boolean options to the `Yaml::parse()`, `Yaml::dump()`,
|
||||||
|
`Parser::parse()`, and `Dumper::dump()` methods to configure the behavior of
|
||||||
|
the parser and dumper is no longer supported, pass bitmask flags instead
|
||||||
|
* the constructor arguments of the `Parser` class have been removed
|
||||||
|
* the `Inline` class is internal and no longer part of the BC promise
|
||||||
|
* removed support for the `!str` tag, use the `!!str` tag instead
|
||||||
|
* added support for tagged scalars.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
Yaml::parse('!foo bar', Yaml::PARSE_CUSTOM_TAGS);
|
||||||
|
// returns TaggedValue('foo', 'bar');
|
||||||
|
```
|
||||||
|
|
||||||
|
3.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* added support for parsing YAML files using the `Yaml::parseFile()` or `Parser::parseFile()` method
|
||||||
|
|
||||||
|
* the `Dumper`, `Parser`, and `Yaml` classes are marked as final
|
||||||
|
|
||||||
|
* Deprecated the `!php/object:` tag which will be replaced by the
|
||||||
|
`!php/object` tag (without the colon) in 4.0.
|
||||||
|
|
||||||
|
* Deprecated the `!php/const:` tag which will be replaced by the
|
||||||
|
`!php/const` tag (without the colon) in 4.0.
|
||||||
|
|
||||||
|
* Support for the `!str` tag is deprecated, use the `!!str` tag instead.
|
||||||
|
|
||||||
|
* Deprecated using the non-specific tag `!` as its behavior will change in 4.0.
|
||||||
|
It will force non-evaluating your values in 4.0. Use plain integers or `!!float` instead.
|
||||||
|
|
||||||
|
3.3.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Starting an unquoted string with a question mark followed by a space is
|
||||||
|
deprecated and will throw a `ParseException` in Symfony 4.0.
|
||||||
|
|
||||||
|
* Deprecated support for implicitly parsing non-string mapping keys as strings.
|
||||||
|
Mapping keys that are no strings will lead to a `ParseException` in Symfony
|
||||||
|
4.0. Use quotes to opt-in for keys to be parsed as strings.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$yaml = <<<YAML
|
||||||
|
null: null key
|
||||||
|
true: boolean true
|
||||||
|
2.0: float key
|
||||||
|
YAML;
|
||||||
|
|
||||||
|
Yaml::parse($yaml);
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
|
||||||
|
$yaml = <<<YAML
|
||||||
|
"null": null key
|
||||||
|
"true": boolean true
|
||||||
|
"2.0": float key
|
||||||
|
YAML;
|
||||||
|
|
||||||
|
Yaml::parse($yaml);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Omitted mapping values will be parsed as `null`.
|
||||||
|
|
||||||
|
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.
|
||||||
|
|
||||||
|
* Added support for dumping empty PHP arrays as YAML sequences:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Yaml::dump([], 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
||||||
|
```
|
||||||
|
|
||||||
|
3.2.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Mappings with a colon (`:`) that is not followed by a whitespace are deprecated
|
||||||
|
when the mapping key is not quoted and will lead to a `ParseException` in
|
||||||
|
Symfony 4.0 (e.g. `foo:bar` must be `foo: bar`).
|
||||||
|
|
||||||
|
* Added support for parsing PHP constants:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Yaml::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_CONSTANT);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Support for silently ignoring duplicate mapping keys in YAML has been
|
||||||
|
deprecated and will lead to a `ParseException` in Symfony 4.0.
|
||||||
|
|
||||||
|
3.1.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added support to dump `stdClass` and `ArrayAccess` objects as YAML mappings
|
||||||
|
through the `Yaml::DUMP_OBJECT_AS_MAP` flag.
|
||||||
|
|
||||||
|
* Strings that are not UTF-8 encoded will be dumped as base64 encoded binary
|
||||||
|
data.
|
||||||
|
|
||||||
|
* Added support for dumping multi line strings as literal blocks.
|
||||||
|
|
||||||
|
* Added support for parsing base64 encoded binary data when they are tagged
|
||||||
|
with the `!!binary` tag.
|
||||||
|
|
||||||
|
* Added support for parsing timestamps as `\DateTime` objects:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Yaml::parse('2001-12-15 21:59:43.10 -5', Yaml::PARSE_DATETIME);
|
||||||
|
```
|
||||||
|
|
||||||
|
* `\DateTime` and `\DateTimeImmutable` objects are dumped as YAML timestamps.
|
||||||
|
|
||||||
|
* Deprecated usage of `%` at the beginning of an unquoted string.
|
||||||
|
|
||||||
|
* Added support for customizing the YAML parser behavior through an optional bit field:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Yaml::parse('{ "foo": "bar", "fiz": "cat" }', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE | Yaml::PARSE_OBJECT | Yaml::PARSE_OBJECT_FOR_MAP);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Added support for customizing the dumped YAML string through an optional bit field:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Yaml::dump(['foo' => new A(), 'bar' => 1], 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE | Yaml::DUMP_OBJECT);
|
||||||
|
```
|
||||||
|
|
||||||
|
3.0.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Yaml::parse() now throws an exception when a blackslash is not escaped
|
||||||
|
in double-quoted strings
|
||||||
|
|
||||||
|
2.8.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Deprecated usage of a colon in an unquoted mapping value
|
||||||
|
* Deprecated usage of @, \`, | and > at the beginning of an unquoted string
|
||||||
|
* When surrounding strings with double-quotes, you must now escape `\` characters. Not
|
||||||
|
escaping those characters (when surrounded by double-quotes) is deprecated.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
class: "Foo\Var"
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
class: "Foo\\Var"
|
||||||
|
```
|
||||||
|
|
||||||
|
2.1.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Yaml::parse() does not evaluate loaded files as PHP files by default
|
||||||
|
anymore (call Yaml::enablePhpParsing() to get back the old behavior)
|
||||||
+277
@@ -0,0 +1,277 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\CI\GithubActionReporter;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Completion\CompletionInput;
|
||||||
|
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
use Symfony\Component\Yaml\Parser;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates YAML files syntax and outputs encountered errors.
|
||||||
|
*
|
||||||
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||||
|
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||||
|
*/
|
||||||
|
#[AsCommand(name: 'lint:yaml', description: 'Lint a YAML file and outputs encountered errors')]
|
||||||
|
class LintCommand extends Command
|
||||||
|
{
|
||||||
|
private Parser $parser;
|
||||||
|
private ?string $format = null;
|
||||||
|
private bool $displayCorrectFiles;
|
||||||
|
private ?\Closure $directoryIteratorProvider;
|
||||||
|
private ?\Closure $isReadableProvider;
|
||||||
|
|
||||||
|
public function __construct(?string $name = null, ?callable $directoryIteratorProvider = null, ?callable $isReadableProvider = null)
|
||||||
|
{
|
||||||
|
parent::__construct($name);
|
||||||
|
|
||||||
|
$this->directoryIteratorProvider = null === $directoryIteratorProvider ? null : $directoryIteratorProvider(...);
|
||||||
|
$this->isReadableProvider = null === $isReadableProvider ? null : $isReadableProvider(...);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
|
||||||
|
->addOption('format', null, InputOption::VALUE_REQUIRED, \sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
|
||||||
|
->addOption('exclude', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to exclude')
|
||||||
|
->addOption('parse-tags', null, InputOption::VALUE_NEGATABLE, 'Parse custom tags', null)
|
||||||
|
->setHelp(<<<EOF
|
||||||
|
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
|
||||||
|
the first encountered syntax error.
|
||||||
|
|
||||||
|
You can validates YAML contents passed from STDIN:
|
||||||
|
|
||||||
|
<info>cat filename | php %command.full_name% -</info>
|
||||||
|
|
||||||
|
You can also validate the syntax of a file:
|
||||||
|
|
||||||
|
<info>php %command.full_name% filename</info>
|
||||||
|
|
||||||
|
Or of a whole directory:
|
||||||
|
|
||||||
|
<info>php %command.full_name% dirname</info>
|
||||||
|
|
||||||
|
The <info>--format</info> option specifies the format of the command output:
|
||||||
|
|
||||||
|
<info>php %command.full_name% dirname --format=json</info>
|
||||||
|
|
||||||
|
You can also exclude one or more specific files:
|
||||||
|
|
||||||
|
<info>php %command.full_name% dirname --exclude="dirname/foo.yaml" --exclude="dirname/bar.yaml"</info>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
$filenames = (array) $input->getArgument('filename');
|
||||||
|
$excludes = $input->getOption('exclude');
|
||||||
|
$this->format = $input->getOption('format');
|
||||||
|
$flags = $input->getOption('parse-tags');
|
||||||
|
|
||||||
|
if (null === $this->format) {
|
||||||
|
// Autodetect format according to CI environment
|
||||||
|
$this->format = class_exists(GithubActionReporter::class) && GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
$flags = $flags ? Yaml::PARSE_CUSTOM_TAGS : 0;
|
||||||
|
|
||||||
|
$this->displayCorrectFiles = $output->isVerbose();
|
||||||
|
|
||||||
|
if (['-'] === $filenames) {
|
||||||
|
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$filenames) {
|
||||||
|
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$filesInfo = [];
|
||||||
|
foreach ($filenames as $filename) {
|
||||||
|
if (!$this->isReadable($filename)) {
|
||||||
|
throw new RuntimeException(\sprintf('File or directory "%s" is not readable.', $filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->getFiles($filename) as $file) {
|
||||||
|
if (!\in_array($file->getPathname(), $excludes, true)) {
|
||||||
|
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->display($io, $filesInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(string $content, int $flags, ?string $file = null): array
|
||||||
|
{
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
|
||||||
|
if (\E_USER_DEPRECATED === $level) {
|
||||||
|
throw new ParseException($message, $this->getParser()->getRealCurrentLineNb() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT | $flags);
|
||||||
|
} catch (ParseException $e) {
|
||||||
|
return ['file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage()];
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['file' => $file, 'valid' => true];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function display(SymfonyStyle $io, array $files): int
|
||||||
|
{
|
||||||
|
return match ($this->format) {
|
||||||
|
'txt' => $this->displayTxt($io, $files),
|
||||||
|
'json' => $this->displayJson($io, $files),
|
||||||
|
'github' => $this->displayTxt($io, $files, true),
|
||||||
|
default => throw new InvalidArgumentException(\sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function displayTxt(SymfonyStyle $io, array $filesInfo, bool $errorAsGithubAnnotations = false): int
|
||||||
|
{
|
||||||
|
$countFiles = \count($filesInfo);
|
||||||
|
$erroredFiles = 0;
|
||||||
|
$suggestTagOption = false;
|
||||||
|
|
||||||
|
if ($errorAsGithubAnnotations) {
|
||||||
|
$githubReporter = new GithubActionReporter($io);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($filesInfo as $info) {
|
||||||
|
if ($info['valid'] && $this->displayCorrectFiles) {
|
||||||
|
$io->comment('<info>OK</info>'.($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
|
||||||
|
} elseif (!$info['valid']) {
|
||||||
|
++$erroredFiles;
|
||||||
|
$io->text('<error> ERROR </error>'.($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
|
||||||
|
$io->text(\sprintf('<error> >> %s</error>', $info['message']));
|
||||||
|
|
||||||
|
if (str_contains($info['message'], 'PARSE_CUSTOM_TAGS')) {
|
||||||
|
$suggestTagOption = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($errorAsGithubAnnotations) {
|
||||||
|
$githubReporter->error($info['message'], $info['file'] ?? 'php://stdin', $info['line']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === $erroredFiles) {
|
||||||
|
$io->success(\sprintf('All %d YAML files contain valid syntax.', $countFiles));
|
||||||
|
} else {
|
||||||
|
$io->warning(\sprintf('%d YAML files have valid syntax and %d contain errors.%s', $countFiles - $erroredFiles, $erroredFiles, $suggestTagOption ? ' Use the --parse-tags option if you want parse custom tags.' : ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
return min($erroredFiles, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function displayJson(SymfonyStyle $io, array $filesInfo): int
|
||||||
|
{
|
||||||
|
$errors = 0;
|
||||||
|
|
||||||
|
array_walk($filesInfo, function (&$v) use (&$errors) {
|
||||||
|
$v['file'] = (string) $v['file'];
|
||||||
|
if (!$v['valid']) {
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($v['message']) && str_contains($v['message'], 'PARSE_CUSTOM_TAGS')) {
|
||||||
|
$v['message'] .= ' Use the --parse-tags option if you want parse custom tags.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$io->writeln(json_encode($filesInfo, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
|
||||||
|
|
||||||
|
return min($errors, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFiles(string $fileOrDirectory): iterable
|
||||||
|
{
|
||||||
|
if (is_file($fileOrDirectory)) {
|
||||||
|
yield new \SplFileInfo($fileOrDirectory);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) {
|
||||||
|
if (!\in_array($file->getExtension(), ['yml', 'yaml'], true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getParser(): Parser
|
||||||
|
{
|
||||||
|
return $this->parser ??= new Parser();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDirectoryIterator(string $directory): iterable
|
||||||
|
{
|
||||||
|
$default = fn ($directory) => new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
|
||||||
|
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||||
|
);
|
||||||
|
|
||||||
|
if (null !== $this->directoryIteratorProvider) {
|
||||||
|
return ($this->directoryIteratorProvider)($directory, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $default($directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isReadable(string $fileOrDirectory): bool
|
||||||
|
{
|
||||||
|
$default = is_readable(...);
|
||||||
|
|
||||||
|
if (null !== $this->isReadableProvider) {
|
||||||
|
return ($this->isReadableProvider)($fileOrDirectory, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $default($fileOrDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||||
|
{
|
||||||
|
if ($input->mustSuggestOptionValuesFor('format')) {
|
||||||
|
$suggestions->suggestValues($this->getAvailableFormatOptions());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return string[] */
|
||||||
|
private function getAvailableFormatOptions(): array
|
||||||
|
{
|
||||||
|
return ['txt', 'json', 'github'];
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+184
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml;
|
||||||
|
|
||||||
|
use Symfony\Component\Yaml\Tag\TaggedValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumper dumps PHP variables to YAML strings.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
class Dumper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param int $indentation The amount of spaces to use for indentation of nested nodes
|
||||||
|
*/
|
||||||
|
public function __construct(private int $indentation = 4)
|
||||||
|
{
|
||||||
|
if ($indentation < 1) {
|
||||||
|
throw new \InvalidArgumentException('The indentation must be greater than zero.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps a PHP value to YAML.
|
||||||
|
*
|
||||||
|
* @param mixed $input The PHP value
|
||||||
|
* @param int $inline The level where you switch to inline YAML
|
||||||
|
* @param int $indent The level of indentation (used internally)
|
||||||
|
* @param int-mask-of<Yaml::DUMP_*> $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||||
|
*/
|
||||||
|
public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags = 0): string
|
||||||
|
{
|
||||||
|
if ($flags & Yaml::DUMP_NULL_AS_EMPTY && $flags & Yaml::DUMP_NULL_AS_TILDE) {
|
||||||
|
throw new \InvalidArgumentException('The Yaml::DUMP_NULL_AS_EMPTY and Yaml::DUMP_NULL_AS_TILDE flags cannot be used together.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->doDump($input, $inline, $indent, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doDump(mixed $input, int $inline = 0, int $indent = 0, int $flags = 0, int $nestingLevel = 0): string
|
||||||
|
{
|
||||||
|
$output = '';
|
||||||
|
$prefix = $indent ? str_repeat(' ', $indent) : '';
|
||||||
|
$dumpObjectAsInlineMap = true;
|
||||||
|
|
||||||
|
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($input instanceof \ArrayObject || $input instanceof \stdClass)) {
|
||||||
|
$dumpObjectAsInlineMap = !(array) $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($inline <= 0 || (!\is_array($input) && !$input instanceof TaggedValue && $dumpObjectAsInlineMap) || !$input) {
|
||||||
|
$output .= $prefix.Inline::dump($input, $flags, 0 === $nestingLevel);
|
||||||
|
} elseif ($input instanceof TaggedValue) {
|
||||||
|
$output .= $this->dumpTaggedValue($input, $inline, $indent, $flags, $prefix, $nestingLevel);
|
||||||
|
} else {
|
||||||
|
$dumpAsMap = Inline::isHash($input);
|
||||||
|
$compactNestedMapping = Yaml::DUMP_COMPACT_NESTED_MAPPING & $flags && !$dumpAsMap;
|
||||||
|
|
||||||
|
foreach ($input as $key => $value) {
|
||||||
|
if ('' !== $output && "\n" !== $output[-1]) {
|
||||||
|
$output .= "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\is_int($key) && Yaml::DUMP_NUMERIC_KEY_AS_STRING & $flags) {
|
||||||
|
$key = (string) $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && str_contains($value, "\n") && !str_contains($value, "\r")) {
|
||||||
|
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value);
|
||||||
|
|
||||||
|
if (isset($value[-2]) && "\n" === $value[-2] && "\n" === $value[-1]) {
|
||||||
|
$blockChompingIndicator = '+';
|
||||||
|
} elseif ("\n" === $value[-1]) {
|
||||||
|
$blockChompingIndicator = '';
|
||||||
|
} else {
|
||||||
|
$blockChompingIndicator = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= \sprintf('%s%s%s |%s%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator, $blockChompingIndicator);
|
||||||
|
|
||||||
|
foreach (explode("\n", $value) as $row) {
|
||||||
|
if ('' === $row) {
|
||||||
|
$output .= "\n";
|
||||||
|
} else {
|
||||||
|
$output .= \sprintf("\n%s%s%s", $prefix, str_repeat(' ', $this->indentation), $row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof TaggedValue) {
|
||||||
|
$output .= \sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
|
||||||
|
|
||||||
|
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
|
||||||
|
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
|
||||||
|
$output .= \sprintf(' |%s', $blockIndentationIndicator);
|
||||||
|
|
||||||
|
foreach (explode("\n", $value->getValue()) as $row) {
|
||||||
|
$output .= \sprintf("\n%s%s%s", $prefix, str_repeat(' ', $this->indentation), $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($inline - 1 <= 0 || null === $value->getValue() || \is_scalar($value->getValue())) {
|
||||||
|
$output .= ' '.$this->doDump($value->getValue(), $inline - 1, 0, $flags, $nestingLevel + 1)."\n";
|
||||||
|
} else {
|
||||||
|
$output .= "\n";
|
||||||
|
$output .= $this->doDump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags, $nestingLevel + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dumpObjectAsInlineMap = true;
|
||||||
|
|
||||||
|
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \ArrayObject || $value instanceof \stdClass)) {
|
||||||
|
$dumpObjectAsInlineMap = !(array) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$willBeInlined = $inline - 1 <= 0 || !\is_array($value) && $dumpObjectAsInlineMap || !$value;
|
||||||
|
|
||||||
|
$output .= \sprintf('%s%s%s%s',
|
||||||
|
$prefix,
|
||||||
|
$dumpAsMap ? Inline::dump($key, $flags).':' : '-',
|
||||||
|
$willBeInlined || ($compactNestedMapping && \is_array($value) && Inline::isHash($value)) ? ' ' : "\n",
|
||||||
|
$compactNestedMapping && \is_array($value) && Inline::isHash($value) ? substr($this->doDump($value, $inline - 1, $indent + 2, $flags, $nestingLevel + 1), $indent + 2) : $this->doDump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags, $nestingLevel + 1)
|
||||||
|
).($willBeInlined ? "\n" : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function dumpTaggedValue(TaggedValue $value, int $inline, int $indent, int $flags, string $prefix, int $nestingLevel): string
|
||||||
|
{
|
||||||
|
$output = \sprintf('%s!%s', $prefix ? $prefix.' ' : '', $value->getTag());
|
||||||
|
|
||||||
|
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
|
||||||
|
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
|
||||||
|
$output .= \sprintf(' |%s', $blockIndentationIndicator);
|
||||||
|
|
||||||
|
foreach (explode("\n", $value->getValue()) as $row) {
|
||||||
|
$output .= \sprintf("\n%s%s%s", $prefix, str_repeat(' ', $this->indentation), $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($inline - 1 <= 0 || null === $value->getValue() || \is_scalar($value->getValue())) {
|
||||||
|
return $output.' '.$this->doDump($value->getValue(), $inline - 1, 0, $flags, $nestingLevel + 1)."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output."\n".$this->doDump($value->getValue(), $inline - 1, $indent, $flags, $nestingLevel + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBlockIndentationIndicator(string $value): string
|
||||||
|
{
|
||||||
|
$lines = explode("\n", $value);
|
||||||
|
|
||||||
|
// If the first line (that is neither empty nor contains only spaces)
|
||||||
|
// starts with a space character, the spec requires a block indentation indicator
|
||||||
|
// http://www.yaml.org/spec/1.2/spec.html#id2793979
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
if ('' !== trim($line, ' ')) {
|
||||||
|
return str_starts_with($line, ' ') ? (string) $this->indentation : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+97
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escaper encapsulates escaping rules for single and double-quoted
|
||||||
|
* YAML strings.
|
||||||
|
*
|
||||||
|
* @author Matthew Lewinski <matthew@lewinski.org>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class Escaper
|
||||||
|
{
|
||||||
|
// Characters that would cause a dumped string to require double quoting.
|
||||||
|
public const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\x7f|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";
|
||||||
|
|
||||||
|
// Mapping arrays for escaping a double quoted string. The backslash is
|
||||||
|
// first to ensure proper escaping because str_replace operates iteratively
|
||||||
|
// on the input arrays. This ordering of the characters avoids the use of strtr,
|
||||||
|
// which performs more slowly.
|
||||||
|
private const ESCAPEES = [
|
||||||
|
'\\', '\\\\', '\\"', '"',
|
||||||
|
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
|
||||||
|
"\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
|
||||||
|
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
|
||||||
|
"\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
|
||||||
|
"\x7f",
|
||||||
|
"\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9",
|
||||||
|
];
|
||||||
|
private const ESCAPED = [
|
||||||
|
'\\\\', '\\"', '\\\\', '\\"',
|
||||||
|
'\\0', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\a',
|
||||||
|
'\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\x0e', '\\x0f',
|
||||||
|
'\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17',
|
||||||
|
'\\x18', '\\x19', '\\x1a', '\\e', '\\x1c', '\\x1d', '\\x1e', '\\x1f',
|
||||||
|
'\\x7f',
|
||||||
|
'\\N', '\\_', '\\L', '\\P',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a PHP value would require double quoting in YAML.
|
||||||
|
*
|
||||||
|
* @param string $value A PHP value
|
||||||
|
*/
|
||||||
|
public static function requiresDoubleQuoting(string $value): bool
|
||||||
|
{
|
||||||
|
return 0 < preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes and surrounds a PHP value with double quotes.
|
||||||
|
*
|
||||||
|
* @param string $value A PHP value
|
||||||
|
*/
|
||||||
|
public static function escapeWithDoubleQuotes(string $value): string
|
||||||
|
{
|
||||||
|
return \sprintf('"%s"', str_replace(self::ESCAPEES, self::ESCAPED, $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a PHP value would require single quoting in YAML.
|
||||||
|
*
|
||||||
|
* @param string $value A PHP value
|
||||||
|
*/
|
||||||
|
public static function requiresSingleQuoting(string $value): bool
|
||||||
|
{
|
||||||
|
// Determines if a PHP value is entirely composed of a value that would
|
||||||
|
// require single quoting in YAML.
|
||||||
|
if (\in_array(strtolower($value), ['null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'], true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determines if the PHP value contains any single characters that would
|
||||||
|
// cause it to require single quoting in YAML.
|
||||||
|
return 0 < preg_match('/[\s\'"\:\{\}\[\],&\*\#\?] | \A[\-?|<>=!%@`\p{Zs}]/xu', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes and surrounds a PHP value with single quotes.
|
||||||
|
*
|
||||||
|
* @param string $value A PHP value
|
||||||
|
*/
|
||||||
|
public static function escapeWithSingleQuotes(string $value): string
|
||||||
|
{
|
||||||
|
return \sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class thrown when an error occurs during dumping.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class DumpException extends RuntimeException
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception interface for all exceptions thrown by the component.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
interface ExceptionInterface extends \Throwable
|
||||||
|
{
|
||||||
|
}
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class thrown when an error occurs during parsing.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class ParseException extends RuntimeException
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $rawMessage The error message
|
||||||
|
* @param int $parsedLine The line where the error occurred
|
||||||
|
* @param string|null $snippet The snippet of code near the problem
|
||||||
|
* @param string|null $parsedFile The file name where the error occurred
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private string $rawMessage,
|
||||||
|
private int $parsedLine = -1,
|
||||||
|
private ?string $snippet = null,
|
||||||
|
private ?string $parsedFile = null,
|
||||||
|
?\Throwable $previous = null,
|
||||||
|
) {
|
||||||
|
$this->updateRepr();
|
||||||
|
|
||||||
|
parent::__construct($this->message, 0, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the snippet of code near the error.
|
||||||
|
*/
|
||||||
|
public function getSnippet(): string
|
||||||
|
{
|
||||||
|
return $this->snippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the snippet of code near the error.
|
||||||
|
*/
|
||||||
|
public function setSnippet(string $snippet): void
|
||||||
|
{
|
||||||
|
$this->snippet = $snippet;
|
||||||
|
|
||||||
|
$this->updateRepr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the filename where the error occurred.
|
||||||
|
*
|
||||||
|
* This method returns null if a string is parsed.
|
||||||
|
*/
|
||||||
|
public function getParsedFile(): string
|
||||||
|
{
|
||||||
|
return $this->parsedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the filename where the error occurred.
|
||||||
|
*/
|
||||||
|
public function setParsedFile(string $parsedFile): void
|
||||||
|
{
|
||||||
|
$this->parsedFile = $parsedFile;
|
||||||
|
|
||||||
|
$this->updateRepr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the line where the error occurred.
|
||||||
|
*/
|
||||||
|
public function getParsedLine(): int
|
||||||
|
{
|
||||||
|
return $this->parsedLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the line where the error occurred.
|
||||||
|
*/
|
||||||
|
public function setParsedLine(int $parsedLine): void
|
||||||
|
{
|
||||||
|
$this->parsedLine = $parsedLine;
|
||||||
|
|
||||||
|
$this->updateRepr();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateRepr(): void
|
||||||
|
{
|
||||||
|
$this->message = $this->rawMessage;
|
||||||
|
|
||||||
|
$dot = false;
|
||||||
|
if (str_ends_with($this->message, '.')) {
|
||||||
|
$this->message = substr($this->message, 0, -1);
|
||||||
|
$dot = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $this->parsedFile) {
|
||||||
|
$this->message .= \sprintf(' in %s', json_encode($this->parsedFile, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->parsedLine >= 0) {
|
||||||
|
$this->message .= \sprintf(' at line %d', $this->parsedLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->snippet) {
|
||||||
|
$this->message .= \sprintf(' (near "%s")', $this->snippet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dot) {
|
||||||
|
$this->message .= '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class thrown when an error occurs during parsing.
|
||||||
|
*
|
||||||
|
* @author Romain Neutron <imprec@gmail.com>
|
||||||
|
*/
|
||||||
|
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
||||||
Vendored
+880
@@ -0,0 +1,880 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml;
|
||||||
|
|
||||||
|
use Symfony\Component\Yaml\Exception\DumpException;
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
use Symfony\Component\Yaml\Tag\TaggedValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inline implements a YAML parser/dumper for the YAML inline syntax.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class Inline
|
||||||
|
{
|
||||||
|
public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';
|
||||||
|
|
||||||
|
public static int $parsedLineNumber = -1;
|
||||||
|
public static ?string $parsedFilename = null;
|
||||||
|
|
||||||
|
private static bool $exceptionOnInvalidType = false;
|
||||||
|
private static bool $objectSupport = false;
|
||||||
|
private static bool $objectForMap = false;
|
||||||
|
private static bool $constantSupport = false;
|
||||||
|
|
||||||
|
public static function initialize(int $flags, ?int $parsedLineNumber = null, ?string $parsedFilename = null): void
|
||||||
|
{
|
||||||
|
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
||||||
|
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
||||||
|
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
|
||||||
|
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
|
||||||
|
self::$parsedFilename = $parsedFilename;
|
||||||
|
|
||||||
|
if (null !== $parsedLineNumber) {
|
||||||
|
self::$parsedLineNumber = $parsedLineNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a YAML string to a PHP value.
|
||||||
|
*
|
||||||
|
* @param int $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
|
||||||
|
* @param array $references Mapping of variable names to values
|
||||||
|
*
|
||||||
|
* @throws ParseException
|
||||||
|
*/
|
||||||
|
public static function parse(string $value, int $flags = 0, array &$references = []): mixed
|
||||||
|
{
|
||||||
|
self::initialize($flags);
|
||||||
|
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
if ('' === $value) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
$tag = self::parseTag($value, $i, $flags);
|
||||||
|
switch ($value[$i]) {
|
||||||
|
case '[':
|
||||||
|
$result = self::parseSequence($value, $flags, $i, $references);
|
||||||
|
++$i;
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
$result = self::parseMapping($value, $flags, $i, $references);
|
||||||
|
++$i;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = self::parseScalar($value, $flags, null, $i, true, $references);
|
||||||
|
}
|
||||||
|
|
||||||
|
// some comments are allowed at the end
|
||||||
|
if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
|
||||||
|
throw new ParseException(\sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $tag && '' !== $tag) {
|
||||||
|
return new TaggedValue($tag, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps a given PHP variable to a YAML string.
|
||||||
|
*
|
||||||
|
* @param mixed $value The PHP variable to convert
|
||||||
|
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||||
|
*
|
||||||
|
* @throws DumpException When trying to dump PHP resource
|
||||||
|
*/
|
||||||
|
public static function dump(mixed $value, int $flags = 0, bool $rootLevel = false): string
|
||||||
|
{
|
||||||
|
switch (true) {
|
||||||
|
case \is_resource($value):
|
||||||
|
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
||||||
|
throw new DumpException(\sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::dumpNull($flags);
|
||||||
|
case $value instanceof \DateTimeInterface:
|
||||||
|
return $value->format(match (true) {
|
||||||
|
!$length = \strlen(rtrim($value->format('u'), '0')) => 'c',
|
||||||
|
$length < 4 => 'Y-m-d\TH:i:s.vP',
|
||||||
|
default => 'Y-m-d\TH:i:s.uP',
|
||||||
|
});
|
||||||
|
case $value instanceof \UnitEnum:
|
||||||
|
return \sprintf('!php/enum %s::%s', $value::class, $value->name);
|
||||||
|
case \is_object($value):
|
||||||
|
if ($value instanceof TaggedValue) {
|
||||||
|
return '!'.$value->getTag().' '.self::dump($value->getValue(), $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::DUMP_OBJECT & $flags) {
|
||||||
|
return '!php/object '.self::dump(serialize($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
|
||||||
|
return self::dumpHashArray($value, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
||||||
|
throw new DumpException('Object support when dumping a YAML file has been disabled.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::dumpNull($flags);
|
||||||
|
case \is_array($value):
|
||||||
|
return self::dumpArray($value, $flags);
|
||||||
|
case null === $value:
|
||||||
|
return self::dumpNull($flags, $rootLevel);
|
||||||
|
case true === $value:
|
||||||
|
return 'true';
|
||||||
|
case false === $value:
|
||||||
|
return 'false';
|
||||||
|
case \is_int($value):
|
||||||
|
return $value;
|
||||||
|
case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"):
|
||||||
|
$locale = setlocale(\LC_NUMERIC, 0);
|
||||||
|
if (false !== $locale) {
|
||||||
|
setlocale(\LC_NUMERIC, 'C');
|
||||||
|
}
|
||||||
|
if (\is_float($value)) {
|
||||||
|
$repr = (string) $value;
|
||||||
|
if (is_infinite($value)) {
|
||||||
|
$repr = str_ireplace('INF', '.Inf', $repr);
|
||||||
|
} elseif (floor($value) == $value && $repr == $value) {
|
||||||
|
// Preserve float data type since storing a whole number will result in integer value.
|
||||||
|
if (!str_contains($repr, 'E')) {
|
||||||
|
$repr .= '.0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$repr = \is_string($value) ? "'$value'" : (string) $value;
|
||||||
|
}
|
||||||
|
if (false !== $locale) {
|
||||||
|
setlocale(\LC_NUMERIC, $locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $repr;
|
||||||
|
case '' == $value:
|
||||||
|
return "''";
|
||||||
|
case self::isBinaryString($value):
|
||||||
|
return '!!binary '.base64_encode($value);
|
||||||
|
case Escaper::requiresDoubleQuoting($value):
|
||||||
|
case Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES & $flags:
|
||||||
|
return Escaper::escapeWithDoubleQuotes($value);
|
||||||
|
case Escaper::requiresSingleQuoting($value):
|
||||||
|
$singleQuoted = Escaper::escapeWithSingleQuotes($value);
|
||||||
|
if (!str_contains($value, "'")) {
|
||||||
|
return $singleQuoted;
|
||||||
|
}
|
||||||
|
// Attempt double-quoting the string instead to see if it's more efficient.
|
||||||
|
$doubleQuoted = Escaper::escapeWithDoubleQuotes($value);
|
||||||
|
|
||||||
|
return \strlen($doubleQuoted) < \strlen($singleQuoted) ? $doubleQuoted : $singleQuoted;
|
||||||
|
case Parser::preg_match('{^[0-9]+[_0-9]*$}', $value):
|
||||||
|
case Parser::preg_match(self::getHexRegex(), $value):
|
||||||
|
case Parser::preg_match(self::getTimestampRegex(), $value):
|
||||||
|
return Escaper::escapeWithSingleQuotes($value);
|
||||||
|
default:
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if given array is hash or just normal indexed array.
|
||||||
|
*/
|
||||||
|
public static function isHash(array|\ArrayObject|\stdClass $value): bool
|
||||||
|
{
|
||||||
|
if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectedKey = 0;
|
||||||
|
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
if ($key !== $expectedKey++) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps a PHP array to a YAML string.
|
||||||
|
*
|
||||||
|
* @param array $value The PHP array to dump
|
||||||
|
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||||
|
*/
|
||||||
|
private static function dumpArray(array $value, int $flags): string
|
||||||
|
{
|
||||||
|
// array
|
||||||
|
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
|
||||||
|
$output = [];
|
||||||
|
foreach ($value as $val) {
|
||||||
|
$output[] = self::dump($val, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \sprintf('[%s]', implode(', ', $output));
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::dumpHashArray($value, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps hash array to a YAML string.
|
||||||
|
*
|
||||||
|
* @param array|\ArrayObject|\stdClass $value The hash array to dump
|
||||||
|
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||||
|
*/
|
||||||
|
private static function dumpHashArray(array|\ArrayObject|\stdClass $value, int $flags): string
|
||||||
|
{
|
||||||
|
$output = [];
|
||||||
|
$keyFlags = $flags & ~Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES;
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
if (\is_int($key) && Yaml::DUMP_NUMERIC_KEY_AS_STRING & $flags) {
|
||||||
|
$key = (string) $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output[] = \sprintf('%s: %s', self::dump($key, $keyFlags), self::dump($val, $flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
return \sprintf('{ %s }', implode(', ', $output));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function dumpNull(int $flags, bool $rootLevel = false): string
|
||||||
|
{
|
||||||
|
if (Yaml::DUMP_NULL_AS_TILDE & $flags) {
|
||||||
|
return '~';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::DUMP_NULL_AS_EMPTY & $flags && !$rootLevel) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a YAML scalar.
|
||||||
|
*
|
||||||
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
|
*/
|
||||||
|
public static function parseScalar(string $scalar, int $flags = 0, ?array $delimiters = null, int &$i = 0, bool $evaluate = true, array &$references = [], ?bool &$isQuoted = null): mixed
|
||||||
|
{
|
||||||
|
if (\in_array($scalar[$i], ['"', "'"], true)) {
|
||||||
|
// quoted scalar
|
||||||
|
$isQuoted = true;
|
||||||
|
$output = self::parseQuotedScalar($scalar, $i);
|
||||||
|
|
||||||
|
if (null !== $delimiters) {
|
||||||
|
$tmp = ltrim(substr($scalar, $i), " \n");
|
||||||
|
if ('' === $tmp) {
|
||||||
|
throw new ParseException(\sprintf('Unexpected end of line, expected one of "%s".', implode('', $delimiters)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
if (!\in_array($tmp[0], $delimiters)) {
|
||||||
|
throw new ParseException(\sprintf('Unexpected characters (%s).', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// "normal" string
|
||||||
|
$isQuoted = false;
|
||||||
|
|
||||||
|
if (!$delimiters) {
|
||||||
|
$output = substr($scalar, $i);
|
||||||
|
$i += \strlen($output);
|
||||||
|
|
||||||
|
// remove comments
|
||||||
|
if (Parser::preg_match('/[ \t]+#/', $output, $match, \PREG_OFFSET_CAPTURE)) {
|
||||||
|
$output = substr($output, 0, $match[0][1]);
|
||||||
|
}
|
||||||
|
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
|
||||||
|
$output = $match[1];
|
||||||
|
$i += \strlen($output);
|
||||||
|
$output = trim($output);
|
||||||
|
} else {
|
||||||
|
throw new ParseException(\sprintf('Malformed inline YAML string: "%s".', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
|
||||||
|
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0] || '%' === $output[0])) {
|
||||||
|
throw new ParseException(\sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]), self::$parsedLineNumber + 1, $output, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($evaluate) {
|
||||||
|
$output = self::evaluateScalar($output, $flags, $references, $isQuoted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a YAML quoted scalar.
|
||||||
|
*
|
||||||
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
|
*/
|
||||||
|
private static function parseQuotedScalar(string $scalar, int &$i = 0): string
|
||||||
|
{
|
||||||
|
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
||||||
|
throw new ParseException(\sprintf('Malformed inline YAML string: "%s".', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = substr($match[0], 1, -1);
|
||||||
|
|
||||||
|
$unescaper = new Unescaper();
|
||||||
|
if ('"' == $scalar[$i]) {
|
||||||
|
$output = $unescaper->unescapeDoubleQuotedString($output);
|
||||||
|
} else {
|
||||||
|
$output = $unescaper->unescapeSingleQuotedString($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
$i += \strlen($match[0]);
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a YAML sequence.
|
||||||
|
*
|
||||||
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
|
*/
|
||||||
|
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array &$references = []): array
|
||||||
|
{
|
||||||
|
$output = [];
|
||||||
|
$len = \strlen($sequence);
|
||||||
|
++$i;
|
||||||
|
|
||||||
|
// [foo, bar, ...]
|
||||||
|
$lastToken = null;
|
||||||
|
while ($i < $len) {
|
||||||
|
if (']' === $sequence[$i]) {
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
if (',' === $sequence[$i] || ' ' === $sequence[$i]) {
|
||||||
|
if (',' === $sequence[$i] && (null === $lastToken || 'separator' === $lastToken)) {
|
||||||
|
$output[] = null;
|
||||||
|
} elseif (',' === $sequence[$i]) {
|
||||||
|
$lastToken = 'separator';
|
||||||
|
}
|
||||||
|
|
||||||
|
++$i;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = self::parseTag($sequence, $i, $flags);
|
||||||
|
switch ($sequence[$i]) {
|
||||||
|
case '[':
|
||||||
|
// nested sequence
|
||||||
|
$value = self::parseSequence($sequence, $flags, $i, $references);
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
// nested mapping
|
||||||
|
$value = self::parseMapping($sequence, $flags, $i, $references);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references, $isQuoted);
|
||||||
|
|
||||||
|
// the value can be an array if a reference has been resolved to an array var
|
||||||
|
if (\is_string($value) && !$isQuoted && str_contains($value, ': ')) {
|
||||||
|
// embedded mapping?
|
||||||
|
$j = $i;
|
||||||
|
$mappingValue = $value;
|
||||||
|
$mappingException = null;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
$pos = 0;
|
||||||
|
$value = self::parseMapping('{'.$mappingValue.'}', $flags, $pos, $references);
|
||||||
|
$i = $j;
|
||||||
|
$mappingException = null;
|
||||||
|
break;
|
||||||
|
} catch (ParseException $exception) {
|
||||||
|
$mappingException = $exception;
|
||||||
|
if ($j >= $len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mappingValue .= $sequence[$j++];
|
||||||
|
if ($j >= $len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mappingValue .= self::parseScalar($sequence, $flags, [',', ']'], $j, null === $tag, $references);
|
||||||
|
}
|
||||||
|
} while ($j < $len);
|
||||||
|
|
||||||
|
if ($mappingException) {
|
||||||
|
throw $mappingException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
|
||||||
|
$references[$matches['ref']] = $matches['value'];
|
||||||
|
$value = $matches['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
--$i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $tag && '' !== $tag) {
|
||||||
|
$value = new TaggedValue($tag, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output[] = $value;
|
||||||
|
|
||||||
|
$lastToken = 'value';
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParseException(\sprintf('Malformed inline YAML string: "%s".', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a YAML mapping.
|
||||||
|
*
|
||||||
|
* @throws ParseException When malformed inline YAML string is parsed
|
||||||
|
*/
|
||||||
|
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array &$references = []): array|\stdClass
|
||||||
|
{
|
||||||
|
$output = [];
|
||||||
|
$len = \strlen($mapping);
|
||||||
|
++$i;
|
||||||
|
$allowOverwrite = false;
|
||||||
|
|
||||||
|
// {foo: bar, bar:foo, ...}
|
||||||
|
while ($i < $len) {
|
||||||
|
switch ($mapping[$i]) {
|
||||||
|
case ' ':
|
||||||
|
case ',':
|
||||||
|
case "\n":
|
||||||
|
++$i;
|
||||||
|
continue 2;
|
||||||
|
case '}':
|
||||||
|
if (self::$objectForMap) {
|
||||||
|
return (object) $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// key
|
||||||
|
$offsetBeforeKeyParsing = $i;
|
||||||
|
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
|
||||||
|
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false);
|
||||||
|
|
||||||
|
if ($offsetBeforeKeyParsing === $i) {
|
||||||
|
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('!php/const' === $key || '!php/enum' === $key) {
|
||||||
|
$key .= ' '.self::parseScalar($mapping, $flags, ['(?<!:):(?!:)'], $i, false);
|
||||||
|
$key = self::evaluateScalar($key, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $i = strpos($mapping, ':', $i)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$isKeyQuoted) {
|
||||||
|
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
|
||||||
|
|
||||||
|
if ('' !== $key && $evaluatedKey !== $key && !\is_string($evaluatedKey) && !\is_int($evaluatedKey)) {
|
||||||
|
throw new ParseException('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead.', self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], [' ', ',', '[', ']', '{', '}', "\n"], true))) {
|
||||||
|
throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('<<' === $key) {
|
||||||
|
$allowOverwrite = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($i < $len) {
|
||||||
|
if (':' === $mapping[$i] || ' ' === $mapping[$i] || "\n" === $mapping[$i]) {
|
||||||
|
++$i;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = self::parseTag($mapping, $i, $flags);
|
||||||
|
switch ($mapping[$i]) {
|
||||||
|
case '[':
|
||||||
|
// nested sequence
|
||||||
|
$value = self::parseSequence($mapping, $flags, $i, $references);
|
||||||
|
// Spec: Keys MUST be unique; first one wins.
|
||||||
|
// Parser cannot abort this mapping earlier, since lines
|
||||||
|
// are processed sequentially.
|
||||||
|
// But overwriting is allowed when a merge node is used in current block.
|
||||||
|
if ('<<' === $key) {
|
||||||
|
foreach ($value as $parsedValue) {
|
||||||
|
$output += $parsedValue;
|
||||||
|
}
|
||||||
|
} elseif ($allowOverwrite || !isset($output[$key])) {
|
||||||
|
if (null !== $tag) {
|
||||||
|
$output[$key] = new TaggedValue($tag, $value);
|
||||||
|
} else {
|
||||||
|
$output[$key] = $value;
|
||||||
|
}
|
||||||
|
} elseif (isset($output[$key])) {
|
||||||
|
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
// nested mapping
|
||||||
|
$value = self::parseMapping($mapping, $flags, $i, $references);
|
||||||
|
// Spec: Keys MUST be unique; first one wins.
|
||||||
|
// Parser cannot abort this mapping earlier, since lines
|
||||||
|
// are processed sequentially.
|
||||||
|
// But overwriting is allowed when a merge node is used in current block.
|
||||||
|
if ('<<' === $key) {
|
||||||
|
$output += $value;
|
||||||
|
} elseif ($allowOverwrite || !isset($output[$key])) {
|
||||||
|
if (null !== $tag) {
|
||||||
|
$output[$key] = new TaggedValue($tag, $value);
|
||||||
|
} else {
|
||||||
|
$output[$key] = $value;
|
||||||
|
}
|
||||||
|
} elseif (isset($output[$key])) {
|
||||||
|
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references, $isValueQuoted);
|
||||||
|
// Spec: Keys MUST be unique; first one wins.
|
||||||
|
// Parser cannot abort this mapping earlier, since lines
|
||||||
|
// are processed sequentially.
|
||||||
|
// But overwriting is allowed when a merge node is used in current block.
|
||||||
|
if ('<<' === $key) {
|
||||||
|
$output += $value;
|
||||||
|
} elseif ($allowOverwrite || !isset($output[$key])) {
|
||||||
|
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && !self::isBinaryString($value) && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
|
||||||
|
$references[$matches['ref']] = $matches['value'];
|
||||||
|
$value = $matches['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $tag) {
|
||||||
|
$output[$key] = new TaggedValue($tag, $value);
|
||||||
|
} else {
|
||||||
|
$output[$key] = $value;
|
||||||
|
}
|
||||||
|
} elseif (isset($output[$key])) {
|
||||||
|
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
|
||||||
|
}
|
||||||
|
--$i;
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParseException(\sprintf('Malformed inline YAML string: "%s".', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluates scalars and replaces magic values.
|
||||||
|
*
|
||||||
|
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
|
||||||
|
*/
|
||||||
|
private static function evaluateScalar(string $scalar, int $flags, array &$references = [], ?bool &$isQuotedString = null): mixed
|
||||||
|
{
|
||||||
|
$isQuotedString = false;
|
||||||
|
$scalar = trim($scalar);
|
||||||
|
|
||||||
|
if (str_starts_with($scalar, '*')) {
|
||||||
|
if (false !== $pos = strpos($scalar, '#')) {
|
||||||
|
$value = substr($scalar, 1, $pos - 2);
|
||||||
|
} else {
|
||||||
|
$value = substr($scalar, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// an unquoted *
|
||||||
|
if ('' === $value) {
|
||||||
|
throw new ParseException('A reference must contain at least one character.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!\array_key_exists($value, $references)) {
|
||||||
|
throw new ParseException(\sprintf('Reference "%s" does not exist.', $value), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $references[$value];
|
||||||
|
}
|
||||||
|
|
||||||
|
$scalarLower = strtolower($scalar);
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case 'null' === $scalarLower:
|
||||||
|
case '' === $scalar:
|
||||||
|
case '~' === $scalar:
|
||||||
|
return null;
|
||||||
|
case 'true' === $scalarLower:
|
||||||
|
return true;
|
||||||
|
case 'false' === $scalarLower:
|
||||||
|
return false;
|
||||||
|
case '!' === $scalar[0]:
|
||||||
|
switch (true) {
|
||||||
|
case str_starts_with($scalar, '!!str '):
|
||||||
|
$s = substr($scalar, 6);
|
||||||
|
|
||||||
|
if (\in_array($s[0] ?? '', ['"', "'"], true)) {
|
||||||
|
$isQuotedString = true;
|
||||||
|
$s = self::parseQuotedScalar($s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $s;
|
||||||
|
case str_starts_with($scalar, '! '):
|
||||||
|
return substr($scalar, 2);
|
||||||
|
case str_starts_with($scalar, '!php/object'):
|
||||||
|
if (self::$objectSupport) {
|
||||||
|
if (!isset($scalar[12])) {
|
||||||
|
throw new ParseException('Missing value for tag "!php/object".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return unserialize(self::parseScalar(substr($scalar, 12)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$exceptionOnInvalidType) {
|
||||||
|
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
case str_starts_with($scalar, '!php/const'):
|
||||||
|
if (self::$constantSupport) {
|
||||||
|
if (!isset($scalar[11])) {
|
||||||
|
throw new ParseException('Missing value for tag "!php/const".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
|
||||||
|
return \constant($const);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParseException(\sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
if (self::$exceptionOnInvalidType) {
|
||||||
|
throw new ParseException(\sprintf('The string "%s" could not be parsed as a constant. Did you forget to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
case str_starts_with($scalar, '!php/enum'):
|
||||||
|
if (self::$constantSupport) {
|
||||||
|
if (!isset($scalar[11])) {
|
||||||
|
throw new ParseException('Missing value for tag "!php/enum".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
$enumName = self::parseScalar(substr($scalar, 10), 0, null, $i, false);
|
||||||
|
$useName = str_contains($enumName, '::');
|
||||||
|
$enum = $useName ? strstr($enumName, '::', true) : $enumName;
|
||||||
|
|
||||||
|
if (!enum_exists($enum)) {
|
||||||
|
throw new ParseException(\sprintf('The enum "%s" is not defined.', $enum), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
if (!$useName) {
|
||||||
|
return $enum::cases();
|
||||||
|
}
|
||||||
|
if ($useValue = str_ends_with($enumName, '->value')) {
|
||||||
|
$enumName = substr($enumName, 0, -7);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!\defined($enumName)) {
|
||||||
|
throw new ParseException(\sprintf('The string "%s" is not the name of a valid enum.', $enumName), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = \constant($enumName);
|
||||||
|
|
||||||
|
if (!$useValue) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
if (!$value instanceof \BackedEnum) {
|
||||||
|
throw new ParseException(\sprintf('The enum "%s" defines no value next to its name.', $enumName), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value->value;
|
||||||
|
}
|
||||||
|
if (self::$exceptionOnInvalidType) {
|
||||||
|
throw new ParseException(\sprintf('The string "%s" could not be parsed as an enum. Did you forget to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
case str_starts_with($scalar, '!!float '):
|
||||||
|
return (float) substr($scalar, 8);
|
||||||
|
case str_starts_with($scalar, '!!binary '):
|
||||||
|
return self::evaluateBinaryScalar(substr($scalar, 9));
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParseException(\sprintf('The string "%s" could not be parsed as it uses an unsupported built-in tag.', $scalar), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
||||||
|
case preg_match('/^(?:\+|-)?0o(?P<value>[0-7_]++)$/', $scalar, $matches):
|
||||||
|
$value = str_replace('_', '', $matches['value']);
|
||||||
|
|
||||||
|
if ('-' === $scalar[0]) {
|
||||||
|
return -octdec($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return octdec($value);
|
||||||
|
case \in_array($scalar[0], ['+', '-', '.'], true) || is_numeric($scalar[0]):
|
||||||
|
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
|
||||||
|
$scalar = str_replace('_', '', $scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case ctype_digit($scalar):
|
||||||
|
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
|
||||||
|
if ($scalar < \PHP_INT_MIN || \PHP_INT_MAX < $scalar) {
|
||||||
|
return $scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cast = (int) $scalar;
|
||||||
|
|
||||||
|
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||||
|
case is_numeric($scalar):
|
||||||
|
case Parser::preg_match(self::getHexRegex(), $scalar):
|
||||||
|
$scalar = str_replace('_', '', $scalar);
|
||||||
|
|
||||||
|
return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar;
|
||||||
|
case '.inf' === $scalarLower:
|
||||||
|
case '.nan' === $scalarLower:
|
||||||
|
return -log(0);
|
||||||
|
case '-.inf' === $scalarLower:
|
||||||
|
return log(0);
|
||||||
|
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
|
||||||
|
return (float) str_replace('_', '', $scalar);
|
||||||
|
case Parser::preg_match(self::getTimestampRegex(), $scalar):
|
||||||
|
try {
|
||||||
|
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
|
||||||
|
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Some dates accepted by the regex are not valid dates.
|
||||||
|
throw new ParseException(\sprintf('The date "%s" could not be parsed as it is an invalid date.', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yaml::PARSE_DATETIME & $flags) {
|
||||||
|
return $time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' !== rtrim($time->format('u'), '0')) {
|
||||||
|
return (float) $time->format('U.u');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (false !== $scalar = $time->getTimestamp()) {
|
||||||
|
return $scalar;
|
||||||
|
}
|
||||||
|
} catch (\DateRangeError|\ValueError) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
return $time->format('U');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function parseTag(string $value, int &$i, int $flags): ?string
|
||||||
|
{
|
||||||
|
if ('!' !== $value[$i]) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagLength = strcspn($value, " \t\n[]{},", $i + 1);
|
||||||
|
$tag = substr($value, $i + 1, $tagLength);
|
||||||
|
|
||||||
|
$nextOffset = $i + $tagLength + 1;
|
||||||
|
$nextOffset += strspn($value, ' ', $nextOffset);
|
||||||
|
|
||||||
|
if ('' === $tag && (!isset($value[$nextOffset]) || \in_array($value[$nextOffset], [']', '}', ','], true))) {
|
||||||
|
throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is followed by a scalar and is a built-in tag
|
||||||
|
if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || \in_array($tag, ['str', 'php/const', 'php/enum', 'php/object'], true))) {
|
||||||
|
// Manage in {@link self::evaluateScalar()}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = $nextOffset;
|
||||||
|
|
||||||
|
// Built-in tags
|
||||||
|
if ('' !== $tag && '!' === $tag[0]) {
|
||||||
|
throw new ParseException(\sprintf('The built-in tag "!%s" is not implemented.', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' !== $tag && !isset($value[$i])) {
|
||||||
|
throw new ParseException(\sprintf('Missing value for tag "%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' === $tag || Yaml::PARSE_CUSTOM_TAGS & $flags) {
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParseException(\sprintf('Tags support is not enabled. Enable the "Yaml::PARSE_CUSTOM_TAGS" flag to use "!%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function evaluateBinaryScalar(string $scalar): string
|
||||||
|
{
|
||||||
|
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
||||||
|
|
||||||
|
if (0 !== (\strlen($parsedBinaryData) % 4)) {
|
||||||
|
throw new ParseException(\sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', \strlen($parsedBinaryData)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Parser::preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) {
|
||||||
|
throw new ParseException(\sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64_decode($parsedBinaryData, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function isBinaryString(string $value): bool
|
||||||
|
{
|
||||||
|
return !preg_match('//u', $value) || preg_match('/[^\x00\x07-\x0d\x1B\x20-\xff]/', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a regex that matches a YAML date.
|
||||||
|
*
|
||||||
|
* @see http://www.yaml.org/spec/1.2/spec.html#id2761573
|
||||||
|
*/
|
||||||
|
private static function getTimestampRegex(): string
|
||||||
|
{
|
||||||
|
return <<<EOF
|
||||||
|
~^
|
||||||
|
(?P<year>[0-9][0-9][0-9][0-9])
|
||||||
|
-(?P<month>[0-9][0-9]?)
|
||||||
|
-(?P<day>[0-9][0-9]?)
|
||||||
|
(?:(?:[Tt]|[ \t]+)
|
||||||
|
(?P<hour>[0-9][0-9]?)
|
||||||
|
:(?P<minute>[0-9][0-9])
|
||||||
|
:(?P<second>[0-9][0-9])
|
||||||
|
(?:\.(?P<fraction>[0-9]*))?
|
||||||
|
(?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
|
||||||
|
(?::(?P<tz_minute>[0-9][0-9]))?))?)?
|
||||||
|
$~x
|
||||||
|
EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a regex that matches a YAML number in hexadecimal notation.
|
||||||
|
*/
|
||||||
|
private static function getHexRegex(): string
|
||||||
|
{
|
||||||
|
return '~^0x[0-9a-f_]++$~i';
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2004-present Fabien Potencier
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
Vendored
+1279
File diff suppressed because it is too large
Load Diff
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
Yaml Component
|
||||||
|
==============
|
||||||
|
|
||||||
|
The Yaml component loads and dumps YAML files.
|
||||||
|
|
||||||
|
Resources
|
||||||
|
---------
|
||||||
|
|
||||||
|
* [Documentation](https://symfony.com/doc/current/components/yaml.html)
|
||||||
|
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||||
|
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||||
|
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||||
|
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ('cli' !== \PHP_SAPI) {
|
||||||
|
throw new Exception('This script must be run from the command line.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the Yaml lint command.
|
||||||
|
*
|
||||||
|
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Yaml\Command\LintCommand;
|
||||||
|
|
||||||
|
function includeIfExists(string $file): bool
|
||||||
|
{
|
||||||
|
return file_exists($file) && include $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!includeIfExists(__DIR__ . '/../../../../autoload.php') &&
|
||||||
|
!includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
|
||||||
|
!includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
|
||||||
|
) {
|
||||||
|
fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists(Application::class)) {
|
||||||
|
fwrite(STDERR, 'You need the "symfony/console" component in order to run the Yaml linter.'.PHP_EOL);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$command = new LintCommand();
|
||||||
|
if (method_exists($app = new Application(), 'addCommand')) {
|
||||||
|
$app->addCommand($command);
|
||||||
|
} else {
|
||||||
|
$app->add($command);
|
||||||
|
}
|
||||||
|
$app
|
||||||
|
->setDefaultCommand($command->getName(), true)
|
||||||
|
->run()
|
||||||
|
;
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
* @author Guilhem N. <egetick@gmail.com>
|
||||||
|
*/
|
||||||
|
final class TaggedValue
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $tag,
|
||||||
|
private mixed $value,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTag(): string
|
||||||
|
{
|
||||||
|
return $this->tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue(): mixed
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+108
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml;
|
||||||
|
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescaper encapsulates unescaping rules for single and double-quoted
|
||||||
|
* YAML strings.
|
||||||
|
*
|
||||||
|
* @author Matthew Lewinski <matthew@lewinski.org>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class Unescaper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Regex fragment that matches an escaped character in a double quoted string.
|
||||||
|
*/
|
||||||
|
public const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescapes a single quoted string.
|
||||||
|
*
|
||||||
|
* @param string $value A single quoted string
|
||||||
|
*/
|
||||||
|
public function unescapeSingleQuotedString(string $value): string
|
||||||
|
{
|
||||||
|
return str_replace('\'\'', '\'', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescapes a double quoted string.
|
||||||
|
*
|
||||||
|
* @param string $value A double quoted string
|
||||||
|
*/
|
||||||
|
public function unescapeDoubleQuotedString(string $value): string
|
||||||
|
{
|
||||||
|
$callback = fn ($match) => $this->unescapeCharacter($match[0]);
|
||||||
|
|
||||||
|
// evaluate the string
|
||||||
|
return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescapes a character that was found in a double-quoted string.
|
||||||
|
*
|
||||||
|
* @param string $value An escaped character
|
||||||
|
*/
|
||||||
|
private function unescapeCharacter(string $value): string
|
||||||
|
{
|
||||||
|
return match ($value[1]) {
|
||||||
|
'0' => "\x0",
|
||||||
|
'a' => "\x7",
|
||||||
|
'b' => "\x8",
|
||||||
|
't' => "\t",
|
||||||
|
"\t" => "\t",
|
||||||
|
'n' => "\n",
|
||||||
|
'v' => "\xB",
|
||||||
|
'f' => "\xC",
|
||||||
|
'r' => "\r",
|
||||||
|
'e' => "\x1B",
|
||||||
|
' ' => ' ',
|
||||||
|
'"' => '"',
|
||||||
|
'/' => '/',
|
||||||
|
'\\' => '\\',
|
||||||
|
// U+0085 NEXT LINE
|
||||||
|
'N' => "\xC2\x85",
|
||||||
|
// U+00A0 NO-BREAK SPACE
|
||||||
|
'_' => "\xC2\xA0",
|
||||||
|
// U+2028 LINE SEPARATOR
|
||||||
|
'L' => "\xE2\x80\xA8",
|
||||||
|
// U+2029 PARAGRAPH SEPARATOR
|
||||||
|
'P' => "\xE2\x80\xA9",
|
||||||
|
'x' => self::utf8chr(hexdec(substr($value, 2, 2))),
|
||||||
|
'u' => self::utf8chr(hexdec(substr($value, 2, 4))),
|
||||||
|
'U' => self::utf8chr(hexdec(substr($value, 2, 8))),
|
||||||
|
default => throw new ParseException(\sprintf('Found unknown escape character "%s".', $value)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UTF-8 character for the given code point.
|
||||||
|
*/
|
||||||
|
private static function utf8chr(int $c): string
|
||||||
|
{
|
||||||
|
if (0x80 > $c %= 0x200000) {
|
||||||
|
return \chr($c);
|
||||||
|
}
|
||||||
|
if (0x800 > $c) {
|
||||||
|
return \chr(0xC0 | $c >> 6).\chr(0x80 | $c & 0x3F);
|
||||||
|
}
|
||||||
|
if (0x10000 > $c) {
|
||||||
|
return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \chr(0xF0 | $c >> 18).\chr(0x80 | $c >> 12 & 0x3F).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+100
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Yaml;
|
||||||
|
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yaml offers convenience methods to load and dump YAML.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
class Yaml
|
||||||
|
{
|
||||||
|
public const DUMP_OBJECT = 1;
|
||||||
|
public const PARSE_EXCEPTION_ON_INVALID_TYPE = 2;
|
||||||
|
public const PARSE_OBJECT = 4;
|
||||||
|
public const PARSE_OBJECT_FOR_MAP = 8;
|
||||||
|
public const DUMP_EXCEPTION_ON_INVALID_TYPE = 16;
|
||||||
|
public const PARSE_DATETIME = 32;
|
||||||
|
public const DUMP_OBJECT_AS_MAP = 64;
|
||||||
|
public const DUMP_MULTI_LINE_LITERAL_BLOCK = 128;
|
||||||
|
public const PARSE_CONSTANT = 256;
|
||||||
|
public const PARSE_CUSTOM_TAGS = 512;
|
||||||
|
public const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024;
|
||||||
|
public const DUMP_NULL_AS_TILDE = 2048;
|
||||||
|
public const DUMP_NUMERIC_KEY_AS_STRING = 4096;
|
||||||
|
public const DUMP_NULL_AS_EMPTY = 8192;
|
||||||
|
public const DUMP_COMPACT_NESTED_MAPPING = 16384;
|
||||||
|
public const DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES = 32768;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a YAML file into a PHP value.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* $array = Yaml::parseFile('config.yml');
|
||||||
|
* print_r($array);
|
||||||
|
*
|
||||||
|
* @param string $filename The path to the YAML file to be parsed
|
||||||
|
* @param int-mask-of<self::PARSE_*> $flags A bit field of PARSE_* constants to customize the YAML parser behavior
|
||||||
|
*
|
||||||
|
* @throws ParseException If the file could not be read or the YAML is not valid
|
||||||
|
*/
|
||||||
|
public static function parseFile(string $filename, int $flags = 0): mixed
|
||||||
|
{
|
||||||
|
$yaml = new Parser();
|
||||||
|
|
||||||
|
return $yaml->parseFile($filename, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses YAML into a PHP value.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* <code>
|
||||||
|
* $array = Yaml::parse(file_get_contents('config.yml'));
|
||||||
|
* print_r($array);
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param string $input A string containing YAML
|
||||||
|
* @param int-mask-of<self::PARSE_*> $flags A bit field of PARSE_* constants to customize the YAML parser behavior
|
||||||
|
*
|
||||||
|
* @throws ParseException If the YAML is not valid
|
||||||
|
*/
|
||||||
|
public static function parse(string $input, int $flags = 0): mixed
|
||||||
|
{
|
||||||
|
$yaml = new Parser();
|
||||||
|
|
||||||
|
return $yaml->parse($input, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps a PHP value to a YAML string.
|
||||||
|
*
|
||||||
|
* The dump method, when supplied with an array, will do its best
|
||||||
|
* to convert the array into friendly YAML.
|
||||||
|
*
|
||||||
|
* @param mixed $input The PHP value
|
||||||
|
* @param int $inline The level where you switch to inline YAML
|
||||||
|
* @param int $indent The amount of spaces to use for indentation of nested nodes
|
||||||
|
* @param int-mask-of<self::DUMP_*> $flags A bit field of DUMP_* constants to customize the dumped YAML string
|
||||||
|
*/
|
||||||
|
public static function dump(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string
|
||||||
|
{
|
||||||
|
$yaml = new Dumper($indent);
|
||||||
|
|
||||||
|
return $yaml->dump($input, $inline, 0, $flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+39
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "symfony/yaml",
|
||||||
|
"type": "library",
|
||||||
|
"description": "Loads and dumps YAML files",
|
||||||
|
"keywords": [],
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
|
"symfony/deprecation-contracts": "^2.5|^3",
|
||||||
|
"symfony/polyfill-ctype": "^1.8"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/console": "^6.4|^7.0|^8.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/console": "<6.4"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": { "Symfony\\Component\\Yaml\\": "" },
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"Resources/bin/yaml-lint"
|
||||||
|
],
|
||||||
|
"minimum-stability": "dev"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user