Browse Source

Code formatting

main
Cédric Belin 5 months ago
parent
commit
e0febde4e6
23 changed files with 300 additions and 293 deletions
  1. +6
    -3
      .editorconfig
  2. +5
    -5
      .vscode/settings.json
  3. +2
    -2
      bin/open_cli
  4. +50
    -50
      composer.json
  5. +1
    -1
      doc/index.md
  6. +5
    -5
      doc/installation.md
  7. +24
    -24
      doc/usage/api.md
  8. +18
    -18
      doc/usage/cli.md
  9. +9
    -5
      etc/mkdocs.yaml
  10. +22
    -22
      etc/phpdoc.xml
  11. +3
    -3
      etc/phpstan.neon
  12. +13
    -13
      etc/phpunit.xml
  13. +12
    -12
      example/main.php
  14. +30
    -30
      src/Cli/Command.php
  15. +1
    -1
      src/Cli/version.g.php
  16. +20
    -20
      src/Wsl.php
  17. +38
    -38
      src/open.php
  18. +23
    -23
      test/OpenTest.php
  19. +3
    -3
      tool/build.ps1
  20. +3
    -3
      tool/clean.ps1
  21. +1
    -1
      tool/doc.ps1
  22. +1
    -1
      tool/upgrade.ps1
  23. +10
    -10
      tool/watch.ps1

+ 6
- 3
.editorconfig View File

@@ -3,11 +3,14 @@ root = true

[*]
charset = utf-8
indent_size = 2
indent_style = space
indent_style = tab
insert_final_newline = true
tab_width = 2
trim_trailing_whitespace = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
indent_style = space

+ 5
- 5
.vscode/settings.json View File

@@ -1,7 +1,7 @@
{
"editor.insertSpaces": true,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
"editor.insertSpaces": false,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}

+ 2
- 2
bin/open_cli View File

@@ -5,12 +5,12 @@ use Open\Cli\{Command};
use Symfony\Component\Console\{Application};

// Load the dependencies.
$autoloader = new SplFileInfo(__DIR__.'/../../../autoload.php');
$autoloader = new SplFileInfo(__DIR__."/../../../autoload.php");
$rootPath = (new SplFileInfo(__DIR__))->getPath();
require_once $autoloader->isFile() ? $autoloader->getPathname() : "$rootPath/vendor/autoload.php";

// Start the application.
$application = new Application('Open.php', require "$rootPath/src/Cli/version.g.php");
$application = new Application("Open.php", require "$rootPath/src/Cli/version.g.php");
$command = (new Command)->setProcessTitle($application->getName());
$application->add($command);
$application->setDefaultCommand($command->getName(), true)->run();

+ 50
- 50
composer.json View File

@@ -1,52 +1,52 @@
{
"description": "Open whatever you want, such as URLs, files or executables, regardless of the platform you use.",
"homepage": "https://docs.belin.io/open.php",
"license": "MIT",
"name": "cedx/open",
"type": "library",
"version": "2.3.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"files": ["src/open.php"],
"psr-4": {"Open\\": "src/"}
},
"autoload-dev": {
"psr-4": {"Open\\": "test/"}
},
"bin": [
"bin/open_cli"
],
"config": {
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"executable",
"file",
"launcher",
"open",
"start",
"url"
],
"require": {
"php": ">=7.4.0",
"ext-mbstring": "*",
"symfony/console": "^5.0.8",
"symfony/process": "^5.0.8"
},
"require-dev": {
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/open.php",
"issues": "https://git.belin.io/cedx/open.php/issues"
}
"description": "Open whatever you want, such as URLs, files or executables, regardless of the platform you use.",
"homepage": "https://docs.belin.io/open.php",
"license": "MIT",
"name": "cedx/open",
"type": "library",
"version": "2.3.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"files": ["src/open.php"],
"psr-4": {"Open\\": "src/"}
},
"autoload-dev": {
"psr-4": {"Open\\": "test/"}
},
"bin": [
"bin/open_cli"
],
"config": {
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"executable",
"file",
"launcher",
"open",
"start",
"url"
],
"require": {
"php": ">=7.4.0",
"ext-mbstring": "*",
"symfony/console": "^5.0.8",
"symfony/process": "^5.0.8"
},
"require-dev": {
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/open.php",
"issues": "https://git.belin.io/cedx/open.php/issues"
}
}

+ 1
- 1
doc/index.md View File

@@ -6,7 +6,7 @@ Open whatever you want in [PHP](https://www.php.net), such as URLs, files or exe
## Quick start
Install the latest version of **Open.php** with [Composer](https://getcomposer.org):

```shell
``` shell
composer require cedx/open
```



+ 5
- 5
doc/installation.md View File

@@ -6,7 +6,7 @@ and [Composer](https://getcomposer.org), the PHP package manager, up and running

You can verify if you're already good to go with the following commands:

```shell
``` shell
php --version
# PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:19) ( NTS Visual C++ 2017 x64 )

@@ -15,22 +15,22 @@ composer --version
```

!!! info
If you plan to play with the package sources, you will also need the latest versions of
[PowerShell](https://docs.microsoft.com/en-us/powershell) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material).
If you plan to play with the package sources, you will also need the latest versions of
[PowerShell](https://docs.microsoft.com/en-us/powershell) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material).

## Installing with Composer package manager

### 1. Install it
From a command prompt, run:

```shell
``` shell
composer require cedx/open
```

### 2. Import it
Now in your [PHP](https://www.php.net) code, you can use:

```php
``` php
<?php
use function Open\{open};
```


+ 24
- 24
doc/usage/api.md View File

@@ -6,26 +6,26 @@ source: src/open.php
# Application programming interface
This package provides a single function, `Open\open()`, allowing to open a document or URL:

```php
``` php
<?php
use function Open\{open};

function main(): void {
// Open a URL in the default browser.
open('https://belin.io');
// Open a URL in the default browser.
open("https://belin.io");

// Open a URL in the given browser.
open('https://belin.io', ['application' => 'firefox']);
// Open a URL in the given browser.
open("https://belin.io", ["application" => "firefox"]);

// Open a URL in the given browser, using the specified arguments.
open('https://belin.io', [
'application' => 'chrome',
'arguments' => ['--incognito']
]);
// Open a URL in the given browser, using the specified arguments.
open("https://belin.io", [
"application" => "chrome",
"arguments" => ["--incognito"]
]);

// Open an image in the default viewer
// and wait for the opened application to quit.
open('funny.gif', ['wait' => true]);
// Open an image in the default viewer
// and wait for the opened application to quit.
open("funny.gif", ["wait" => true]);
}
```

@@ -33,8 +33,8 @@ The function returns the spawned child process, an instance of the [`\Symfony\Co
You would normally not need to use this for anything, but it can be useful if you'd like to perform operations directly on the spawned process.

!!! info
The function uses the command `start` on Windows, `open` on macOS
and `xdg-open` on other platforms.
The function uses the command `start` on Windows, `open` on macOS
and `xdg-open` on other platforms.

## Options
The behavior of the `Open\open()` function can be customized using the following options.
@@ -46,34 +46,34 @@ The application name is platform dependent. For example, Goole Chrome is `chrome

You may also pass in the application's full path. For example on Windows Subsystem for Linux, this can be `"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"`.

```php
``` php
<?php
open('https://belin.io', ['application' => 'firefox']);
open("https://belin.io", ["application" => "firefox"]);
```

### array **arguments**
Specify the arguments to pass when using a custom `application` option.

```php
``` php
<?php
open('https://belin.io', ['application' => 'chrome', 'arguments' => ['--incognito']]);
open("https://belin.io", ["application" => "chrome", "arguments" => ["--incognito"]]);
```

### bool **background**
Do not bring the application to the foreground (macOS only).

```php
``` php
<?php
open('spreadsheet.xlsx', ['background' => true]);
open("spreadsheet.xlsx", ["background" => true]);
```

### bool **wait**
Wait for the opened application to exit before proceeding to the next statement. If `false`, immediately goes to the next statement after opening the application.

```php
``` php
<?php
open('funny.gif', ['wait' => true]);
open("funny.gif", ["wait" => true]);
```

!!! tip
On Windows, you have to explicitly specify the `application` option for it to be able to wait.
On Windows, you have to explicitly specify the `application` option for it to be able to wait.

+ 18
- 18
doc/usage/cli.md View File

@@ -6,44 +6,44 @@ source: bin/open_cli
# Command line interface
From a command prompt, install the `open_cli` executable:

```shell
``` shell
composer global require cedx/open
```

!!! tip
Consider adding the [`composer global`](https://getcomposer.org/doc/03-cli.md#global) executables directory to your system path.
Consider adding the [`composer global`](https://getcomposer.org/doc/03-cli.md#global) executables directory to your system path.

Then use it to open a document or URL:

```shell
``` shell
$ open_cli --help

Description:
Open whatever you want, such as URLs, files or executables, regardless of the platform you use.
Open whatever you want, such as URLs, files or executables, regardless of the platform you use.

Usage:
open [options] [--] <target> [<arguments>...]
open [options] [--] <target> [<arguments>...]

Arguments:
target The target to open
arguments The arguments of the application to open the target with
target The target to open
arguments The arguments of the application to open the target with

Options:
-a, --application=APPLICATION The application to open the target with
-b, --background Do not bring the application to the foreground (macOS only)
-w, --wait Wait for the opened application to exit
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
-a, --application=APPLICATION The application to open the target with
-b, --background Do not bring the application to the foreground (macOS only)
-w, --wait Wait for the opened application to exit
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
```

For example:

```shell
``` shell
# Open a URL in the default browser.
open_cli https://belin.io



+ 9
- 5
etc/mkdocs.yaml View File

@@ -8,19 +8,23 @@ site_dir: ../www

repo_name: git.belin.io
repo_url: https://git.belin.io/cedx/open.php
edit_uri: ''
edit_uri: ""

copyright: Copyright &copy; 2019 - 2020 Cédric Belin
extra:
social:
- icon: fontawesome/solid/globe
link: 'https://belin.io'
link: "https://belin.io"
name: Belin.io
- icon: fontawesome/brands/github
link: 'https://github.com/cedx'
link: "https://github.com/cedx"
name: GitHub
- icon: fontawesome/brands/twitter
link: 'https://twitter.com/cedxbelin'
link: "https://twitter.com/cedxbelin"
name: Twitter
- icon: fontawesome/brands/linkedin
link: 'https://linkedin.com/in/cedxbelin'
link: "https://linkedin.com/in/cedxbelin"
name: LinkedIn

markdown_extensions:
- admonition


+ 22
- 22
etc/phpdoc.xml View File

@@ -1,25 +1,25 @@
<?xml version="1.0"?>
<phpdocumentor
configVersion="3"
xmlns="http://www.phpdoc.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://docs.phpdoc.org/latest/phpdoc.xsd">
<title>Open.php</title>
<paths>
<cache>../var/phpdoc</cache>
<output>../doc/api</output>
</paths>
<version number="2.3.0">
<api>
<markers>
<marker>TODO</marker>
</markers>
<source dsn="..">
<path>src</path>
</source>
<visibility>protected</visibility>
<visibility>public</visibility>
</api>
</version>
configVersion="3"
xmlns="http://www.phpdoc.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://docs.phpdoc.org/latest/phpdoc.xsd">
<title>Open.php</title>
<paths>
<cache>../var/phpdoc</cache>
<output>../doc/api</output>
</paths>
<version number="2.3.0">
<api>
<markers>
<marker>TODO</marker>
</markers>
<source dsn="..">
<path>src</path>
</source>
<visibility>protected</visibility>
<visibility>public</visibility>
</api>
</version>
</phpdocumentor>

+ 3
- 3
etc/phpstan.neon View File

@@ -1,4 +1,4 @@
parameters:
checkMissingIterableValueType: false
level: max
paths: [../src, ../test]
checkMissingIterableValueType: false
level: max
paths: [../src, ../test]

+ 13
- 13
etc/phpunit.xml View File

@@ -1,18 +1,18 @@
<?xml version="1.0"?>
<phpunit bootstrap="../vendor/autoload.php" cacheResult="false" testdox="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
</filter>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="../var/coverage.xml"/>
</logging>
<logging>
<log type="coverage-clover" target="../var/coverage.xml"/>
</logging>

<testsuites>
<testsuite name="all">
<directory suffix="Test.php">../test</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">../test</directory>
</testsuite>
</testsuites>
</phpunit>

+ 12
- 12
example/main.php View File

@@ -3,19 +3,19 @@ use function Open\{open};

/** Demonstrates the usage of the `open()` function. */
function main(): void {
// Open a URL in the default browser.
open('https://belin.io');
// Open a URL in the default browser.
open("https://belin.io");

// Open a URL in the given browser.
open('https://belin.io', ['application' => 'firefox']);
// Open a URL in the given browser.
open("https://belin.io", ["application" => "firefox"]);

// Open a URL in the given browser, using the specified arguments.
open('https://belin.io', [
'application' => 'chrome',
'arguments' => ['--incognito']
]);
// Open a URL in the given browser, using the specified arguments.
open("https://belin.io", [
"application" => "chrome",
"arguments" => ["--incognito"]
]);

// Open an image in the default viewer
// and wait for the opened application to quit.
open('funny.gif', ['wait' => true]);
// Open an image in the default viewer
// and wait for the opened application to quit.
open("funny.gif", ["wait" => true]);
}

+ 30
- 30
src/Cli/Command.php View File

@@ -7,37 +7,37 @@ use function Open\{open};

/** The console command. */
class Command extends \Symfony\Component\Console\Command\Command {
/** @var string The command name. */
protected static $defaultName = 'open';
/** @var string The command name. */
protected static $defaultName = "open";

/** Configures the current command. */
protected function configure(): void {
$this
->setDescription('Open whatever you want, such as URLs, files or executables, regardless of the platform you use.')
->addArgument('target', InputArgument::REQUIRED, 'The target to open')
->addArgument('arguments', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The arguments of the application to open the target with')
->addOption('application', 'a', InputOption::VALUE_REQUIRED, 'The application to open the target with')
->addOption('background', 'b', InputOption::VALUE_NONE, 'Do not bring the application to the foreground (macOS only)')
->addOption('wait', 'w', InputOption::VALUE_NONE, 'Wait for the opened application to exit');
}
/** Configures the current command. */
protected function configure(): void {
$this
->setDescription("Open whatever you want, such as URLs, files or executables, regardless of the platform you use.")
->addArgument("target", InputArgument::REQUIRED, "The target to open")
->addArgument("arguments", InputArgument::OPTIONAL | InputArgument::IS_ARRAY, "The arguments of the application to open the target with")
->addOption("application", "a", InputOption::VALUE_REQUIRED, "The application to open the target with")
->addOption("background", "b", InputOption::VALUE_NONE, "Do not bring the application to the foreground (macOS only)")
->addOption("wait", "w", InputOption::VALUE_NONE, "Wait for the opened application to exit");
}

/**
* Executes the current command.
* @param InputInterface $input The input arguments and options.
* @param OutputInterface $output The console output.
* @return int The exit code.
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
/** @var string $target */
$target = $input->getArgument('target');
open($target, [
'application' => $input->getOption('application') ?? '',
'arguments' => $input->getArgument('arguments'),
'background' => $input->getOption('background'),
'wait' => $input->getOption('wait')
]);
/**
* Executes the current command.
* @param InputInterface $input The input arguments and options.
* @param OutputInterface $output The console output.
* @return int The exit code.
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
/** @var string $target */
$target = $input->getArgument("target");
open($target, [
"application" => $input->getOption("application") ?? "",
"arguments" => $input->getArgument("arguments"),
"background" => $input->getOption("background"),
"wait" => $input->getOption("wait")
]);

return 0;
}
return 0;
}
}

+ 1
- 1
src/Cli/version.g.php View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);

// The version number of the package.
return $packageVersion = '2.3.0';
return $packageVersion = "2.3.0";

+ 20
- 20
src/Wsl.php View File

@@ -4,26 +4,26 @@ namespace Open;
/** Provides helper methods for the Windows Subsystem for Linux. */
abstract class Wsl {

/**
* Gets a value indicating whether the process is running inside Windows Subsystem for Linux.
* @return bool `true` if the process is running inside Windows Subsystem for Linux, otherwise `false`.
*/
static function isWsl(): bool {
if (PHP_OS_FAMILY != 'Linux') return false;
if (mb_stripos(php_uname(), 'microsoft')) return true;
/**
* Gets a value indicating whether the process is running inside Windows Subsystem for Linux.
* @return bool `true` if the process is running inside Windows Subsystem for Linux, otherwise `false`.
*/
static function isWsl(): bool {
if (PHP_OS_FAMILY != "Linux") return false;
if (mb_stripos(php_uname(), "microsoft")) return true;

$procFile = new \SplFileObject('/proc/version');
return (bool) mb_stripos((string) $procFile->fread($procFile->getSize()), 'microsoft');
}
$procFile = new \SplFileObject("/proc/version");
return (bool) mb_stripos((string) $procFile->fread($procFile->getSize()), "microsoft");
}

/**
* Resolves the specified WSL path to a Windows path.
* @param string $path A WSL path.
* @return string The Windows path corresponding to the specified WSL path.
*/
static function resolvePath(string $path): string {
assert(mb_strlen($path) > 0);
$escapedPath = escapeshellarg($path);
return trim(`wslpath -w $escapedPath`);
}
/**
* Resolves the specified WSL path to a Windows path.
* @param string $path A WSL path.
* @return string The Windows path corresponding to the specified WSL path.
*/
static function resolvePath(string $path): string {
assert(mb_strlen($path) > 0);
$escapedPath = escapeshellarg($path);
return trim(`wslpath -w $escapedPath`);
}
}

+ 38
- 38
src/open.php View File

@@ -10,47 +10,47 @@ use Symfony\Component\Process\{Process};
* @return Process The spawned child process.
*/
function open(string $target, array $options = []): Process {
assert(mb_strlen($target) > 0);
assert(mb_strlen($target) > 0);

$application = $options['application'] ?? '';
$arguments = $options['arguments'] ?? [];
$background = $options['background'] ?? false;
$wait = $options['wait'] ?? false;
$application = $options["application"] ?? "";
$arguments = $options["arguments"] ?? [];
$background = $options["background"] ?? false;
$wait = $options["wait"] ?? false;

$command = [];
$isWsl = Wsl::isWsl();
$isWindows = PHP_OS_FAMILY == 'Windows' || $isWsl;
$outputDisabled = false;
$command = [];
$isWsl = Wsl::isWsl();
$isWindows = PHP_OS_FAMILY == "Windows" || $isWsl;
$outputDisabled = false;

if (PHP_OS_FAMILY == 'Darwin') {
$command[] = 'open';
if ($wait) $command[] = '--wait-apps';
if ($background) $command[] = '--background';
if ($application) array_push($command, '-a', $application);
$command[] = $target;
if ($arguments) array_push($command, '--args', ...$arguments);
}
else if ($isWindows) {
$command[] = 'cmd.exe';
array_push($command, '/c', 'start', '""', '/b');
if ($wait) $command[] = '/wait';
if ($application) $command[] = escapeshellarg($isWsl && mb_substr($application, 0, 5) == '/mnt/' ? Wsl::resolvePath($application) : $application);
if ($arguments) array_push($command, ...array_map('escapeshellarg', $arguments));
$command[] = str_replace('&', '^&', escapeshellarg($target));
}
else {
$localXdgOpen = new \SplFileInfo(__DIR__.'/../bin/xdg-open');
$command[] = $application ?: ($localXdgOpen->isExecutable() ? $localXdgOpen->getRealPath() : 'xdg-open');
if ($arguments) array_push($command, ...$arguments);
if (!$wait) $outputDisabled = true;
$command[] = $target;
}
if (PHP_OS_FAMILY == "Darwin") {
$command[] = "open";
if ($wait) $command[] = "--wait-apps";
if ($background) $command[] = "--background";
if ($application) array_push($command, "-a", $application);
$command[] = $target;
if ($arguments) array_push($command, "--args", ...$arguments);
}
else if ($isWindows) {
$command[] = "cmd.exe";
array_push($command, "/c", "start", '""', "/b");
if ($wait) $command[] = "/wait";
if ($application) $command[] = escapeshellarg($isWsl && mb_substr($application, 0, 5) == "/mnt/" ? Wsl::resolvePath($application) : $application);
if ($arguments) array_push($command, ...array_map("escapeshellarg", $arguments));
$command[] = str_replace("&", "^&", escapeshellarg($target));
}
else {
$localXdgOpen = new \SplFileInfo(__DIR__."/../bin/xdg-open");
$command[] = $application ?: ($localXdgOpen->isExecutable() ? $localXdgOpen->getRealPath() : "xdg-open");
if ($arguments) array_push($command, ...$arguments);
if (!$wait) $outputDisabled = true;
$command[] = $target;
}

$process = $isWindows ? Process::fromShellCommandline(implode(' ', $command)) : new Process($command);
if ($outputDisabled) $process->disableOutput();
$process->setTimeout(null);
$process = $isWindows ? Process::fromShellCommandline(implode(" ", $command)) : new Process($command);
if ($outputDisabled) $process->disableOutput();
$process->setTimeout(null);

if ($wait) $process->mustRun();
else $process->run();
return $process;
if ($wait) $process->mustRun();
else $process->run();
return $process;
}

+ 23
- 23
test/OpenTest.php View File

@@ -7,36 +7,36 @@ use function PHPUnit\Framework\{assertThat, isNull};
/** @testdox Open\open */
class OpenTest extends TestCase {

/** @testdox open() */
function testOpen(): void {
$googleChrome = PHP_OS_FAMILY == 'Darwin' ? 'google chrome' : (PHP_OS_FAMILY == 'Windows' ? 'chrome' : 'google-chrome');
/** @testdox open() */
function testOpen(): void {
$googleChrome = PHP_OS_FAMILY == "Darwin" ? "google chrome" : (PHP_OS_FAMILY == "Windows" ? "chrome" : "google-chrome");

// It should open files in the default application.
open(__FILE__);
// It should open files in the default application.
open(__FILE__);

// It should open URLs in the default application.
open('https://belin.io');
// It should open URLs in the default application.
open("https://belin.io");

// It should open URLs in the given application.
open('https://belin.io', ['application' => 'firefox']);
// It should open URLs in the given application.
open("https://belin.io", ["application" => "firefox"]);

// It should open URLs in the given application with arguments.
open('https://belin.io', ['application' => $googleChrome, 'arguments' => ['--incognito']]);
// It should open URLs in the given application with arguments.
open("https://belin.io", ["application" => $googleChrome, "arguments" => ["--incognito"]]);

// It should wait for the application to close.
open('https://belin.io', ['application' => $googleChrome, 'wait' => true]);
// It should wait for the application to close.
open("https://belin.io", ["application" => $googleChrome, "wait" => true]);

if (Wsl::isWsl()) {
$googleChromeWsl = '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe';
if (Wsl::isWsl()) {
$googleChromeWsl = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe";

// It should open URLs in the specified application by using a given WSL path.
open('https://belin.io', ['application' => $googleChromeWsl]);
// It should open URLs in the specified application by using a given WSL path.
open("https://belin.io", ["application" => $googleChromeWsl]);

// It should open URLs in the specified application with arguments by using a given WSL path.
open('https://belin.io', ['application' => $googleChromeWsl, 'arguments' => ['--incognito']]);
}
// It should open URLs in the specified application with arguments by using a given WSL path.
open("https://belin.io", ["application" => $googleChromeWsl, "arguments" => ["--incognito"]]);
}

// Mark this test as not risky.
assertThat(null, isNull());
}
// Mark this test as not risky.
assertThat(null, isNull());
}
}

+ 3
- 3
tool/build.ps1 View File

@@ -4,9 +4,9 @@ Set-Location (Split-Path $PSScriptRoot)

$version = (Get-Content composer.json | ConvertFrom-Json).version
$lines = @(
'<?php declare(strict_types=1);', '',
'// The version number of the package.',
"return `$packageVersion = '$version';"
"<?php declare(strict_types=1);", "",
"// The version number of the package.",
"return `$packageVersion = ""$version"";"
)

Set-Content src/Cli/version.g.php ($lines -join [Environment]::NewLine)

+ 3
- 3
tool/clean.ps1 View File

@@ -2,10 +2,10 @@
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

foreach ($item in 'build', 'doc/api', 'www') {
if (Test-Path $item) { Remove-Item $item -Recurse }
foreach ($item in "build", "doc/api", "www") {
if (Test-Path $item) { Remove-Item $item -Recurse }
}

foreach ($item in Get-ChildItem var -Exclude .gitkeep) {
Remove-Item $item -Recurse
Remove-Item $item -Recurse
}

+ 1
- 1
tool/doc.ps1 View File

@@ -2,7 +2,7 @@
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

$phpdoc = $IsWindows ? 'php "C:/Program Files/PHP/share/phpDocumentor.phar"' : 'phpdoc';
$phpdoc = $IsWindows ? 'php "C:/Program Files/PHP/share/phpDocumentor.phar"' : "phpdoc";
Invoke-Expression "$phpdoc --config=etc/phpdoc.xml"

if (-not (Test-Path doc/api/images)) { New-Item doc/api/images -ItemType Directory | Out-Null }


+ 1
- 1
tool/upgrade.ps1 View File

@@ -6,5 +6,5 @@ git reset --hard
git fetch --all --prune
git pull --rebase

$composer = $IsWindows ? 'php "C:/Program Files/PHP/share/composer.phar"' : 'composer'
$composer = $IsWindows ? 'php "C:/Program Files/PHP/share/composer.phar"' : "composer"
Invoke-Expression "$composer update --no-interaction"

+ 10
- 10
tool/watch.ps1 View File

@@ -4,26 +4,26 @@ Set-Location (Split-Path $PSScriptRoot)
[Console]::TreatControlCAsInput = $true

$action = {
if ($EventArgs.Name -notlike '*.g.php') {
$changeType = [String] $EventArgs.ChangeType
Write-Host "'$($EventArgs.Name)' was $($changeType.ToLower()): starting a new build..."
$timeSpan = Measure-Command { tool/build.ps1 }
Write-Host "> Finished the build after $($timeSpan.TotalSeconds) seconds."
}
if ($EventArgs.Name -notlike "*.g.php") {
$changeType = [String] $EventArgs.ChangeType
Write-Host "'$($EventArgs.Name)' was $($changeType.ToLower()): starting a new build..."
$timeSpan = Measure-Command { tool/build.ps1 }
Write-Host "> Finished the build after $($timeSpan.TotalSeconds) seconds."
}
}

$watcher = New-Object System.IO.FileSystemWatcher (Resolve-Path src).Path
$watcher.EnableRaisingEvents = $true
$watcher.IncludeSubdirectories = $true

foreach ($event in 'Changed', 'Created', 'Deleted', 'Renamed') {
Register-ObjectEvent $watcher $event -Action $action | Out-Null
foreach ($event in "Changed", "Created", "Deleted", "Renamed") {
Register-ObjectEvent $watcher $event -Action $action | Out-Null
}

$console = $Host.UI.RawUI;
while ($true) {
if ($console.KeyAvailable -and ($console.ReadKey('AllowCtrlC,IncludeKeyUp,NoEcho').Character -eq 3)) { break }
Start-Sleep -Milliseconds 200
if ($console.KeyAvailable -and ($console.ReadKey("AllowCtrlC,IncludeKeyUp,NoEcho").Character -eq 3)) { break }
Start-Sleep -Milliseconds 200
}

Get-EventSubscriber | Unregister-Event

Loading…
Cancel
Save