@vituum/vite-plugin-latte 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/index.js +2 -2
  2. package/latte/PlaceholderFunction.php +2 -2
  3. package/package.json +10 -11
  4. package/vendor/autoload.php +18 -0
  5. package/vendor/bin/latte-lint +16 -4
  6. package/vendor/composer/ClassLoader.php +72 -65
  7. package/vendor/composer/InstalledVersions.php +21 -12
  8. package/vendor/composer/autoload_classmap.php +14 -8
  9. package/vendor/composer/autoload_namespaces.php +1 -1
  10. package/vendor/composer/autoload_psr4.php +1 -1
  11. package/vendor/composer/autoload_real.php +3 -22
  12. package/vendor/composer/autoload_static.php +13 -7
  13. package/vendor/composer/installed.json +8 -8
  14. package/vendor/composer/installed.php +10 -10
  15. package/vendor/latte/latte/bin/latte-lint +8 -2
  16. package/vendor/latte/latte/composer.json +1 -1
  17. package/vendor/latte/latte/readme.md +6 -6
  18. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +1 -0
  19. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +3 -2
  20. package/vendor/latte/latte/src/Latte/Compiler/Block.php +0 -3
  21. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +113 -89
  22. package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +2 -1
  23. package/vendor/latte/latte/src/Latte/Compiler/Node.php +0 -4
  24. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +0 -4
  25. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +0 -4
  26. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +11 -3
  27. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +10 -0
  28. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +22 -4
  29. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +35 -12
  30. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +6 -0
  31. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +12 -0
  32. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +4 -31
  33. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +15 -1
  34. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +11 -0
  35. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +42 -0
  36. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +2 -2
  37. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +1 -1
  38. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +8 -0
  39. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +15 -1
  40. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +11 -0
  41. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +11 -0
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/{StaticCallNode.php → StaticMethodCallNode.php} +11 -1
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/{StaticCallableNode.php → StaticMethodCallableNode.php} +11 -1
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +38 -0
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +24 -0
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +1 -1
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +48 -0
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +56 -0
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +5 -5
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +11 -21
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +1 -8
  52. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +30 -0
  53. package/vendor/latte/latte/src/Latte/Compiler/Position.php +4 -8
  54. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +15 -8
  55. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +13 -14
  56. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +5 -9
  57. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +52 -3
  58. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +353 -326
  59. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +6 -5
  60. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +105 -178
  61. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +40 -33
  62. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +186 -126
  63. package/vendor/latte/latte/src/Latte/Compiler/Token.php +5 -9
  64. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +6 -22
  65. package/vendor/latte/latte/src/Latte/Engine.php +136 -95
  66. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +46 -0
  67. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +42 -27
  68. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +0 -4
  69. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +81 -66
  70. package/vendor/latte/latte/src/Latte/Essential/Filters.php +103 -43
  71. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +1 -2
  72. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +2 -13
  73. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +8 -1
  74. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +1 -2
  75. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +1 -1
  76. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +0 -3
  77. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +1 -1
  78. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +1 -1
  79. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +40 -13
  80. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +1 -1
  81. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +4 -1
  82. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +5 -3
  83. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +5 -2
  84. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -4
  85. package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +26 -23
  86. package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +88 -0
  87. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +20 -28
  88. package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +7 -12
  89. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +1 -1
  90. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +1 -1
  91. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +1 -1
  92. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +25 -3
  93. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +1 -1
  94. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +3 -4
  95. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +9 -2
  96. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +1 -1
  97. package/vendor/latte/latte/src/Latte/Essential/Passes.php +16 -58
  98. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +0 -2
  99. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +6 -1
  100. package/vendor/latte/latte/src/Latte/Helpers.php +3 -1
  101. package/vendor/latte/latte/src/Latte/Loader.php +1 -0
  102. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +1 -4
  103. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +0 -2
  104. package/vendor/latte/latte/src/Latte/PositionAwareException.php +1 -1
  105. package/vendor/latte/latte/src/Latte/Runtime/Block.php +0 -4
  106. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +43 -51
  107. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +0 -2
  108. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +64 -33
  109. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +68 -0
  110. package/vendor/latte/latte/src/Latte/Runtime/Html.php +0 -4
  111. package/vendor/latte/latte/src/Latte/Runtime/Template.php +3 -5
  112. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +2 -1
  113. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +1 -1
  114. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +3 -3
  115. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/{StaticCallNode.php → StaticMethodCallNode.php} +3 -3
  116. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/{StaticCallableNode.php → StaticMethodCallableNode.php} +2 -2
  117. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +0 -2
  118. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +11 -9
  119. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +0 -2
  120. package/vendor/latte/latte/src/Latte/exceptions.php +2 -11
  121. package/vendor/latte/latte/src/Tools/Linter.php +13 -37
  122. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +0 -53
  123. package/vendor/latte/latte/src/Latte/Strict.php +0 -101
package/index.js CHANGED
@@ -139,8 +139,8 @@ const plugin = (options = {}) => {
139
139
  await renameBuildEnd(resolvedConfig.build.rollupOptions.input, options.formats)
140
140
  },
141
141
  transformIndexHtml: {
142
- enforce: 'pre',
143
- async transform (content, { path, filename, server }) {
142
+ order: 'pre',
143
+ async handler (content, { path, filename, server }) {
144
144
  if (options.ignoredPaths.find(ignoredPath => minimatch(path.replace('.html', ''), ignoredPath) === true)) {
145
145
  return content
146
146
  }
@@ -5,7 +5,7 @@ namespace App\Latte;
5
5
  class PlaceholderFunction {
6
6
 
7
7
  public static function execute($width, $height): string {
8
- $colors = ["333", "444", "666", "222", "777", "888", "111"];
9
- return 'https://via.placeholder.com/' . $width . 'x' . $height . '/' . $colors[array_rand($colors)];
8
+ $colors = ["333333", "444444", "666666", "222222", "777777", "888888", "111111"];
9
+ return 'https://placehold.co/' . $width . 'x' . $height . '/' . $colors[array_rand($colors)] . '/' . 'webp';
10
10
  }
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vituum/vite-plugin-latte",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -12,17 +12,17 @@
12
12
  "preview": "vite preview"
13
13
  },
14
14
  "dependencies": {
15
- "vituum": "^1.0.0",
16
- "fast-glob": "^3.2.12",
17
- "lodash": "^4.17.21",
18
- "minimatch": "^9.0.2"
15
+ "vituum": "^1.1",
16
+ "fast-glob": "^3.3",
17
+ "lodash": "^4.17",
18
+ "minimatch": "^9.0"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/node": "^20.3.2",
22
- "vite": "^4.3.9",
23
- "eslint": "^8.43.0",
21
+ "@types/node": "^20.9.1",
22
+ "vite": "^5.0.0",
23
+ "eslint": "^8.53.0",
24
24
  "eslint-config-standard": "^17.1.0",
25
- "typescript": "^5.1.3"
25
+ "typescript": "^5.2.2"
26
26
  },
27
27
  "files": [
28
28
  "index.js",
@@ -38,8 +38,7 @@
38
38
  "./types": "./types/*"
39
39
  },
40
40
  "engines": {
41
- "node": ">=16.0.0",
42
- "npm": ">=8.0.0"
41
+ "node": "^18.0.0 || >=20.0.0"
43
42
  },
44
43
  "repository": {
45
44
  "type": "git",
@@ -2,6 +2,24 @@
2
2
 
3
3
  // autoload.php @generated by Composer
4
4
 
5
+ if (PHP_VERSION_ID < 50600) {
6
+ if (!headers_sent()) {
7
+ header('HTTP/1.1 500 Internal Server Error');
8
+ }
9
+ $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;
10
+ if (!ini_get('display_errors')) {
11
+ if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12
+ fwrite(STDERR, $err);
13
+ } elseif (!headers_sent()) {
14
+ echo $err;
15
+ }
16
+ }
17
+ trigger_error(
18
+ $err,
19
+ E_USER_ERROR
20
+ );
21
+ }
22
+
5
23
  require_once __DIR__ . '/composer/autoload_real.php';
6
24
 
7
25
  return ComposerAutoloaderInit19cfb30b66a778b432af39bbd1e78bca::getLoader();
@@ -66,6 +66,16 @@ if (PHP_VERSION_ID < 80000) {
66
66
  return $operation ? flock($this->handle, $operation) : true;
67
67
  }
68
68
 
69
+ public function stream_seek($offset, $whence)
70
+ {
71
+ if (0 === fseek($this->handle, $offset, $whence)) {
72
+ $this->position = ftell($this->handle);
73
+ return true;
74
+ }
75
+
76
+ return false;
77
+ }
78
+
69
79
  public function stream_tell()
70
80
  {
71
81
  return $this->position;
@@ -98,10 +108,12 @@ if (PHP_VERSION_ID < 80000) {
98
108
  }
99
109
  }
100
110
 
101
- if (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) {
102
- include("phpvfscomposer://" . __DIR__ . '/..'.'/latte/latte/bin/latte-lint');
103
- exit(0);
111
+ if (
112
+ (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
113
+ || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
114
+ ) {
115
+ return include("phpvfscomposer://" . __DIR__ . '/..'.'/latte/latte/bin/latte-lint');
104
116
  }
105
117
  }
106
118
 
107
- include __DIR__ . '/..'.'/latte/latte/bin/latte-lint';
119
+ return include __DIR__ . '/..'.'/latte/latte/bin/latte-lint';
@@ -42,35 +42,37 @@ namespace Composer\Autoload;
42
42
  */
43
43
  class ClassLoader
44
44
  {
45
- /** @var ?string */
45
+ /** @var \Closure(string):void */
46
+ private static $includeFile;
47
+
48
+ /** @var string|null */
46
49
  private $vendorDir;
47
50
 
48
51
  // PSR-4
49
52
  /**
50
- * @var array[]
51
- * @psalm-var array<string, array<string, int>>
53
+ * @var array<string, array<string, int>>
52
54
  */
53
55
  private $prefixLengthsPsr4 = array();
54
56
  /**
55
- * @var array[]
56
- * @psalm-var array<string, array<int, string>>
57
+ * @var array<string, list<string>>
57
58
  */
58
59
  private $prefixDirsPsr4 = array();
59
60
  /**
60
- * @var array[]
61
- * @psalm-var array<string, string>
61
+ * @var list<string>
62
62
  */
63
63
  private $fallbackDirsPsr4 = array();
64
64
 
65
65
  // PSR-0
66
66
  /**
67
- * @var array[]
68
- * @psalm-var array<string, array<string, string[]>>
67
+ * List of PSR-0 prefixes
68
+ *
69
+ * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
70
+ *
71
+ * @var array<string, array<string, list<string>>>
69
72
  */
70
73
  private $prefixesPsr0 = array();
71
74
  /**
72
- * @var array[]
73
- * @psalm-var array<string, string>
75
+ * @var list<string>
74
76
  */
75
77
  private $fallbackDirsPsr0 = array();
76
78
 
@@ -78,8 +80,7 @@ class ClassLoader
78
80
  private $useIncludePath = false;
79
81
 
80
82
  /**
81
- * @var string[]
82
- * @psalm-var array<string, string>
83
+ * @var array<string, string>
83
84
  */
84
85
  private $classMap = array();
85
86
 
@@ -87,29 +88,29 @@ class ClassLoader
87
88
  private $classMapAuthoritative = false;
88
89
 
89
90
  /**
90
- * @var bool[]
91
- * @psalm-var array<string, bool>
91
+ * @var array<string, bool>
92
92
  */
93
93
  private $missingClasses = array();
94
94
 
95
- /** @var ?string */
95
+ /** @var string|null */
96
96
  private $apcuPrefix;
97
97
 
98
98
  /**
99
- * @var self[]
99
+ * @var array<string, self>
100
100
  */
101
101
  private static $registeredLoaders = array();
102
102
 
103
103
  /**
104
- * @param ?string $vendorDir
104
+ * @param string|null $vendorDir
105
105
  */
106
106
  public function __construct($vendorDir = null)
107
107
  {
108
108
  $this->vendorDir = $vendorDir;
109
+ self::initializeIncludeClosure();
109
110
  }
110
111
 
111
112
  /**
112
- * @return string[]
113
+ * @return array<string, list<string>>
113
114
  */
114
115
  public function getPrefixes()
115
116
  {
@@ -121,8 +122,7 @@ class ClassLoader
121
122
  }
122
123
 
123
124
  /**
124
- * @return array[]
125
- * @psalm-return array<string, array<int, string>>
125
+ * @return array<string, list<string>>
126
126
  */
127
127
  public function getPrefixesPsr4()
128
128
  {
@@ -130,8 +130,7 @@ class ClassLoader
130
130
  }
131
131
 
132
132
  /**
133
- * @return array[]
134
- * @psalm-return array<string, string>
133
+ * @return list<string>
135
134
  */
136
135
  public function getFallbackDirs()
137
136
  {
@@ -139,8 +138,7 @@ class ClassLoader
139
138
  }
140
139
 
141
140
  /**
142
- * @return array[]
143
- * @psalm-return array<string, string>
141
+ * @return list<string>
144
142
  */
145
143
  public function getFallbackDirsPsr4()
146
144
  {
@@ -148,8 +146,7 @@ class ClassLoader
148
146
  }
149
147
 
150
148
  /**
151
- * @return string[] Array of classname => path
152
- * @psalm-return array<string, string>
149
+ * @return array<string, string> Array of classname => path
153
150
  */
154
151
  public function getClassMap()
155
152
  {
@@ -157,8 +154,7 @@ class ClassLoader
157
154
  }
158
155
 
159
156
  /**
160
- * @param string[] $classMap Class to filename map
161
- * @psalm-param array<string, string> $classMap
157
+ * @param array<string, string> $classMap Class to filename map
162
158
  *
163
159
  * @return void
164
160
  */
@@ -175,24 +171,25 @@ class ClassLoader
175
171
  * Registers a set of PSR-0 directories for a given prefix, either
176
172
  * appending or prepending to the ones previously set for this prefix.
177
173
  *
178
- * @param string $prefix The prefix
179
- * @param string[]|string $paths The PSR-0 root directories
180
- * @param bool $prepend Whether to prepend the directories
174
+ * @param string $prefix The prefix
175
+ * @param list<string>|string $paths The PSR-0 root directories
176
+ * @param bool $prepend Whether to prepend the directories
181
177
  *
182
178
  * @return void
183
179
  */
184
180
  public function add($prefix, $paths, $prepend = false)
185
181
  {
182
+ $paths = (array) $paths;
186
183
  if (!$prefix) {
187
184
  if ($prepend) {
188
185
  $this->fallbackDirsPsr0 = array_merge(
189
- (array) $paths,
186
+ $paths,
190
187
  $this->fallbackDirsPsr0
191
188
  );
192
189
  } else {
193
190
  $this->fallbackDirsPsr0 = array_merge(
194
191
  $this->fallbackDirsPsr0,
195
- (array) $paths
192
+ $paths
196
193
  );
197
194
  }
198
195
 
@@ -201,19 +198,19 @@ class ClassLoader
201
198
 
202
199
  $first = $prefix[0];
203
200
  if (!isset($this->prefixesPsr0[$first][$prefix])) {
204
- $this->prefixesPsr0[$first][$prefix] = (array) $paths;
201
+ $this->prefixesPsr0[$first][$prefix] = $paths;
205
202
 
206
203
  return;
207
204
  }
208
205
  if ($prepend) {
209
206
  $this->prefixesPsr0[$first][$prefix] = array_merge(
210
- (array) $paths,
207
+ $paths,
211
208
  $this->prefixesPsr0[$first][$prefix]
212
209
  );
213
210
  } else {
214
211
  $this->prefixesPsr0[$first][$prefix] = array_merge(
215
212
  $this->prefixesPsr0[$first][$prefix],
216
- (array) $paths
213
+ $paths
217
214
  );
218
215
  }
219
216
  }
@@ -222,9 +219,9 @@ class ClassLoader
222
219
  * Registers a set of PSR-4 directories for a given namespace, either
223
220
  * appending or prepending to the ones previously set for this namespace.
224
221
  *
225
- * @param string $prefix The prefix/namespace, with trailing '\\'
226
- * @param string[]|string $paths The PSR-4 base directories
227
- * @param bool $prepend Whether to prepend the directories
222
+ * @param string $prefix The prefix/namespace, with trailing '\\'
223
+ * @param list<string>|string $paths The PSR-4 base directories
224
+ * @param bool $prepend Whether to prepend the directories
228
225
  *
229
226
  * @throws \InvalidArgumentException
230
227
  *
@@ -232,17 +229,18 @@ class ClassLoader
232
229
  */
233
230
  public function addPsr4($prefix, $paths, $prepend = false)
234
231
  {
232
+ $paths = (array) $paths;
235
233
  if (!$prefix) {
236
234
  // Register directories for the root namespace.
237
235
  if ($prepend) {
238
236
  $this->fallbackDirsPsr4 = array_merge(
239
- (array) $paths,
237
+ $paths,
240
238
  $this->fallbackDirsPsr4
241
239
  );
242
240
  } else {
243
241
  $this->fallbackDirsPsr4 = array_merge(
244
242
  $this->fallbackDirsPsr4,
245
- (array) $paths
243
+ $paths
246
244
  );
247
245
  }
248
246
  } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
@@ -252,18 +250,18 @@ class ClassLoader
252
250
  throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
253
251
  }
254
252
  $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
255
- $this->prefixDirsPsr4[$prefix] = (array) $paths;
253
+ $this->prefixDirsPsr4[$prefix] = $paths;
256
254
  } elseif ($prepend) {
257
255
  // Prepend directories for an already registered namespace.
258
256
  $this->prefixDirsPsr4[$prefix] = array_merge(
259
- (array) $paths,
257
+ $paths,
260
258
  $this->prefixDirsPsr4[$prefix]
261
259
  );
262
260
  } else {
263
261
  // Append directories for an already registered namespace.
264
262
  $this->prefixDirsPsr4[$prefix] = array_merge(
265
263
  $this->prefixDirsPsr4[$prefix],
266
- (array) $paths
264
+ $paths
267
265
  );
268
266
  }
269
267
  }
@@ -272,8 +270,8 @@ class ClassLoader
272
270
  * Registers a set of PSR-0 directories for a given prefix,
273
271
  * replacing any others previously set for this prefix.
274
272
  *
275
- * @param string $prefix The prefix
276
- * @param string[]|string $paths The PSR-0 base directories
273
+ * @param string $prefix The prefix
274
+ * @param list<string>|string $paths The PSR-0 base directories
277
275
  *
278
276
  * @return void
279
277
  */
@@ -290,8 +288,8 @@ class ClassLoader
290
288
  * Registers a set of PSR-4 directories for a given namespace,
291
289
  * replacing any others previously set for this namespace.
292
290
  *
293
- * @param string $prefix The prefix/namespace, with trailing '\\'
294
- * @param string[]|string $paths The PSR-4 base directories
291
+ * @param string $prefix The prefix/namespace, with trailing '\\'
292
+ * @param list<string>|string $paths The PSR-4 base directories
295
293
  *
296
294
  * @throws \InvalidArgumentException
297
295
  *
@@ -425,7 +423,8 @@ class ClassLoader
425
423
  public function loadClass($class)
426
424
  {
427
425
  if ($file = $this->findFile($class)) {
428
- includeFile($file);
426
+ $includeFile = self::$includeFile;
427
+ $includeFile($file);
429
428
 
430
429
  return true;
431
430
  }
@@ -476,9 +475,9 @@ class ClassLoader
476
475
  }
477
476
 
478
477
  /**
479
- * Returns the currently registered loaders indexed by their corresponding vendor directories.
478
+ * Returns the currently registered loaders keyed by their corresponding vendor directories.
480
479
  *
481
- * @return self[]
480
+ * @return array<string, self>
482
481
  */
483
482
  public static function getRegisteredLoaders()
484
483
  {
@@ -555,18 +554,26 @@ class ClassLoader
555
554
 
556
555
  return false;
557
556
  }
558
- }
559
557
 
560
- /**
561
- * Scope isolated include.
562
- *
563
- * Prevents access to $this/self from included files.
564
- *
565
- * @param string $file
566
- * @return void
567
- * @private
568
- */
569
- function includeFile($file)
570
- {
571
- include $file;
558
+ /**
559
+ * @return void
560
+ */
561
+ private static function initializeIncludeClosure()
562
+ {
563
+ if (self::$includeFile !== null) {
564
+ return;
565
+ }
566
+
567
+ /**
568
+ * Scope isolated include.
569
+ *
570
+ * Prevents access to $this/self from included files.
571
+ *
572
+ * @param string $file
573
+ * @return void
574
+ */
575
+ self::$includeFile = \Closure::bind(static function($file) {
576
+ include $file;
577
+ }, null, null);
578
+ }
572
579
  }
@@ -21,12 +21,14 @@ use Composer\Semver\VersionParser;
21
21
  * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
22
22
  *
23
23
  * To require its presence, you can require `composer-runtime-api ^2.0`
24
+ *
25
+ * @final
24
26
  */
25
27
  class InstalledVersions
26
28
  {
27
29
  /**
28
30
  * @var mixed[]|null
29
- * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
31
+ * @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
30
32
  */
31
33
  private static $installed;
32
34
 
@@ -37,7 +39,7 @@ class InstalledVersions
37
39
 
38
40
  /**
39
41
  * @var array[]
40
- * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
42
+ * @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[]}>}>
41
43
  */
42
44
  private static $installedByVendor = array();
43
45
 
@@ -96,7 +98,7 @@ class InstalledVersions
96
98
  {
97
99
  foreach (self::getInstalled() as $installed) {
98
100
  if (isset($installed['versions'][$packageName])) {
99
- return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
101
+ return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
100
102
  }
101
103
  }
102
104
 
@@ -117,7 +119,7 @@ class InstalledVersions
117
119
  */
118
120
  public static function satisfies(VersionParser $parser, $packageName, $constraint)
119
121
  {
120
- $constraint = $parser->parseConstraints($constraint);
122
+ $constraint = $parser->parseConstraints((string) $constraint);
121
123
  $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
122
124
 
123
125
  return $provided->matches($constraint);
@@ -241,7 +243,7 @@ class InstalledVersions
241
243
 
242
244
  /**
243
245
  * @return array
244
- * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
246
+ * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
245
247
  */
246
248
  public static function getRootPackage()
247
249
  {
@@ -255,7 +257,7 @@ class InstalledVersions
255
257
  *
256
258
  * @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.
257
259
  * @return array[]
258
- * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
260
+ * @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[]}>}
259
261
  */
260
262
  public static function getRawData()
261
263
  {
@@ -278,7 +280,7 @@ class InstalledVersions
278
280
  * Returns the raw data of all installed.php which are currently loaded for custom implementations
279
281
  *
280
282
  * @return array[]
281
- * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
283
+ * @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[]}>}>
282
284
  */
283
285
  public static function getAllRawData()
284
286
  {
@@ -301,7 +303,7 @@ class InstalledVersions
301
303
  * @param array[] $data A vendor/composer/installed.php data set
302
304
  * @return void
303
305
  *
304
- * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
306
+ * @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
305
307
  */
306
308
  public static function reload($data)
307
309
  {
@@ -311,7 +313,7 @@ class InstalledVersions
311
313
 
312
314
  /**
313
315
  * @return array[]
314
- * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
316
+ * @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[]}>}>
315
317
  */
316
318
  private static function getInstalled()
317
319
  {
@@ -326,7 +328,9 @@ class InstalledVersions
326
328
  if (isset(self::$installedByVendor[$vendorDir])) {
327
329
  $installed[] = self::$installedByVendor[$vendorDir];
328
330
  } elseif (is_file($vendorDir.'/composer/installed.php')) {
329
- $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
331
+ /** @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 */
332
+ $required = require $vendorDir.'/composer/installed.php';
333
+ $installed[] = self::$installedByVendor[$vendorDir] = $required;
330
334
  if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
331
335
  self::$installed = $installed[count($installed) - 1];
332
336
  }
@@ -338,12 +342,17 @@ class InstalledVersions
338
342
  // only require the installed.php file if this file is loaded from its dumped location,
339
343
  // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
340
344
  if (substr(__DIR__, -8, 1) !== 'C') {
341
- self::$installed = require __DIR__ . '/installed.php';
345
+ /** @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 */
346
+ $required = require __DIR__ . '/installed.php';
347
+ self::$installed = $required;
342
348
  } else {
343
349
  self::$installed = array();
344
350
  }
345
351
  }
346
- $installed[] = self::$installed;
352
+
353
+ if (self::$installed !== array()) {
354
+ $installed[] = self::$installed;
355
+ }
347
356
 
348
357
  return $installed;
349
358
  }