Skip to content

Commit ccc62bf

Browse files
authored
Merge pull request #271 from ThomasTr/extend-options
Make Options extendable
2 parents f1cf998 + a76ecb6 commit ccc62bf

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/Options.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use function in_array;
1212
use function str_contains;
1313

14+
/** @phpstan-consistent-constructor */
1415
class Options
1516
{
1617
// @deprecated
@@ -250,7 +251,7 @@ class Options
250251
*/
251252
private array $url = [];
252253

253-
private function __construct()
254+
public function __construct()
254255
{
255256
}
256257

tests/Fixtures/OptionsExtended.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace YoutubeDl\Tests\Fixtures;
6+
7+
final class OptionsExtended extends \YoutubeDl\Options
8+
{
9+
// Preset Aliases
10+
private ?string $presetAlias = null;
11+
12+
public function presetAlias(?string $presetAlias): self
13+
{
14+
$new = clone $this;
15+
$new->presetAlias = $presetAlias;
16+
17+
return $new;
18+
}
19+
20+
public function toArray(): array
21+
{
22+
$array = parent::toArray();
23+
24+
$array['preset-alias'] = $this->presetAlias;
25+
26+
return $array;
27+
}
28+
}

tests/OptionsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,11 @@ public function testOutputThrowsWithDirectorySeparator(): void
7272

7373
Options::create()->output('/var/downloads');
7474
}
75+
76+
public function testExtendOutput(): void
77+
{
78+
$options = (new Fixtures\OptionsExtended())->toArray();
79+
80+
self::assertArrayHasKey('preset-alias', $options);
81+
}
7582
}

0 commit comments

Comments
 (0)