Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@
- uses: ramsey/composer-install@v3

- run: vendor/bin/phpstan analyse --error-format=github

box:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- uses: shivammathur/setup-php@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Lint' step
Uses Step
uses 'shivammathur/setup-php' with ref 'v2', not a pinned commit hash
with:
php-version: '8.4'
coverage: none
tools: box:4

- run: box validate
30 changes: 14 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,29 @@ jobs:
files: coverage-unit.xml
flags: unit

bin:
runs-on: ubuntu-latest
env:
GOFLAGS: '-mod=mod'
phar:
runs-on: ubuntu-24.04
outputs:
php-version: ${{ steps.setup-php.outputs.php-version }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- uses: shivammathur/setup-php@v2
id: setup-php
with:
php-version: '8.4'
coverage: none
tools: box:4
- uses: ramsey/composer-install@v3
with:
composer-options: '--no-dev --prefer-dist'
composer-options: --no-dev --prefer-dist

- name: Add bin into PATH
run: echo "${WORKSPACE}/bin" >> "$GITHUB_PATH"
env:
WORKSPACE: ${{ github.workspace }}
- run: box compile

- uses: actions/setup-go@v6
- uses: actions/upload-artifact@v4
with:
go-version-file: 'go.mod'

- name: Print php-matrix binary path
run: go test -count=1 -v ./internal

- run: go test -count=1 ./...
name: php-matrix.phar
path: phar/php-matrix
if-no-files-found: error
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Composer
/vendor/

# Pest
/coverage*.xml

# Box
/phar/
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ vendor:

bin: vendor

phar: vendor
box compile
box verify phar/php-matrix
box info phar/php-matrix
php phar/php-matrix --version

test-%: %
PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \
go test -count=1 ./...
Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,7 @@ Available sources:

## Installation

### Composer Global

```bash
composer global require typisttech/php-matrix
php-matrix --help
```

### Composer Project

```bash
composer create-project typisttech/php-matrix
cd php-matrix
./bin/php-matrix --help
```
TODO!

## Credits

Expand Down
18 changes: 14 additions & 4 deletions bin/php-matrix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

declare(strict_types=1);

use TypistTech\PhpMatrix\Console\Application;
namespace TypistTech\PhpMatrix;

include $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';
use TypistTech\PhpMatrix\Console\Runner;
use function in_array;
use const PHP_EOL;
use const PHP_SAPI;

Application::make()
->run();
// Taken from https://box-project.github.io/box/faq/#what-is-the-canonical-way-to-write-a-cli-entry-file
if (!in_array(PHP_SAPI, ['micro', 'cli', 'phpdbg', 'embed'], true)) {
echo PHP_EOL . 'This app may only be invoked from a command line, got "' . PHP_SAPI . '"' . PHP_EOL;
exit(1);
}

include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';

Runner::run();
10 changes: 10 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"output": "phar/php-matrix",
"check-requirements": false,
"files-bin": [
"data/all-versions.json"
],
"datetime": "datetime",
"datetime-format": "Y-m-d",
"git-tag": "git-tag"
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
},
"scripts": {
"lint": [
"box validate",
"pint --test",
"phpstan analyse"
],
Expand Down
108 changes: 95 additions & 13 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,107 @@

namespace TypistTech\PhpMatrix\Console;

use Composer\InstalledVersions;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Application as SymfonyConsoleApplication;
use Symfony\Component\Console\Helper\FormatterHelper;

class Application
class Application extends SymfonyConsoleApplication
{
private const string NAME = 'php-matrix';
private const BANNER = <<<BANNER
____ _ _ ____ __ __ _ _
| _ \| | | | _ \ | \/ | __ _| |_ _ __(_)_ __
| |_) | |_| | |_) | | |\/| |/ _` | __| '__| \ \/ /
| __/| _ | __/ | | | | (_| | |_| | | |> <
|_| |_| |_|_| |_| |_|\__,_|\__|_| |_/_/\_\
BANNER;

public static function make(): ConsoleApplication
public const BUILD_TIMESTAMP = '@datetime@';

public function getLongVersion(): string
{
$app = new ConsoleApplication(
self::NAME,
InstalledVersions::getPrettyVersion('typisttech/php-matrix') ?? 'unknown',
$longVersion = self::BANNER;
$longVersion .= PHP_EOL.PHP_EOL;

$app = sprintf(
'%-15s <info>%s</info> %s',
$this->getName(),
$this->getVersion(),
self::BUILD_TIMESTAMP,
);
$longVersion .= $app;

$githubUrl = sprintf(
'<href=https://github.com/typisttech/php-matrix/releases/tag/%1$s>https://github.com/typisttech/php-matrix/releases/tag/%1$s</>',
$this->getVersion(),
);
// https://github.com/box-project/box/blob/b0123f358f2a32488c92e09bf56f16d185e4e3cb/src/Configuration/Configuration.php#L2116
if ((bool) preg_match('/^(?<tag>.+)-\d+-g(?<hash>[a-f0-9]{7})$/', $this->getVersion(), $matches)) {
// Not on a tag.
$githubUrl = sprintf(
'<href=https://github.com/typisttech/php-matrix/compare/%1$s...%2$s>https://github.com/typisttech/php-matrix/compare/%1$s...%2$s</>',
$matches['tag'],
$matches['hash'],
);
}
$longVersion .= PHP_EOL.$githubUrl;

$longVersion .= PHP_EOL.PHP_EOL.'<comment>PHP:</>';

$phpVersion = sprintf(
'%-15s %s',
'Version',
PHP_VERSION,
);
$longVersion .= PHP_EOL.$phpVersion;

$phpSapi = sprintf(
'%-15s %s',
'SAPI',
PHP_SAPI,
);
$longVersion .= PHP_EOL.$phpSapi;

$longVersion .= PHP_EOL.PHP_EOL.'<comment>Support Composer SemVer:</>';

$supportBlock = (new FormatterHelper)
->formatBlock(
[
'If you find this tool useful, please consider supporting its development.',
'Every contribution counts, regardless how big or small.',
'I am eternally grateful to all sponsors who fund my open source journey.',
],
'question',
true,
);
$longVersion .= PHP_EOL.$supportBlock;

$sponsorUrl = sprintf(
'%1$-15s <href=%2$s>%2$s</>',
'GitHub Sponsor',
'https://github.com/sponsors/tangrufus',
);
$longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl;

$longVersion .= PHP_EOL.PHP_EOL.'<comment>Hire Tang Rufus:</>';

$app->addCommands([
new ComposerCommand,
new ConstraintCommand,
]);
$hireBlock = (new FormatterHelper)
->formatBlock(
[
'I am looking for my next role, freelance or full-time.',
'If you find this tool useful, I can build you more weird stuffs like this.',
"Let's talk if you are hiring PHP / Ruby / Go developers.",
],
'error',
true,
);
$longVersion .= PHP_EOL.$hireBlock;

$sponsorUrl = sprintf(
'%1$-15s <href=%2$s>%2$s</>',
'Contact',
'https://typist.tech/contact/',
);
$longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl;

return $app;
return $longVersion;
}
}
24 changes: 24 additions & 0 deletions src/Console/Runner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TypistTech\PhpMatrix\Console;

class Runner
{
private const string NAME = 'PHP Matrix';

private const string GIT_TAG = '@git-tag@';

public static function run(): int
{
$app = new Application(self::NAME, self::GIT_TAG);

$app->addCommands([
new ComposerCommand,
new ConstraintCommand,
]);

return $app->run();
}
}
Loading