Repository: symfony/thanks
Branch: main
Commit: f455cc9ba4e0
Files: 8
Total size: 21.6 KB
Directory structure:
gitextract_mjqcaiah/
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
└── src/
├── Command/
│ ├── FundCommand.php
│ └── ThanksCommand.php
├── GitHubClient.php
└── Thanks.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/vendor/
composer.lock
================================================
FILE: LICENSE
================================================
Copyright (c) 2017-2019 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.
================================================
FILE: README.md
================================================
<p align="center"><a href="https://symfony.com" target="_blank">
<img src="https://symfony.com/logos/symfony_black_02.svg">
</a></p>
Give thanks (in the form of a [GitHub ★ ](https://help.github.com/articles/about-stars/)) to your fellow PHP package maintainers (not limited to Symfony components)!
Install
-------
Install this as any other (dev) Composer package:
```sh
composer require --dev symfony/thanks
```
You can also install it once for all your local projects:
```sh
composer global require symfony/thanks
```
Usage
-----
```sh
composer thanks
```
This will find all of your Composer dependencies, find their github.com repository, and star their GitHub repositories. This was inspired by `cargo thanks`, which was inspired in part by Medium's clapping button as a way to show thanks for someone else's work you've found enjoyment in.
If you're wondering why did some dependencies get thanked and not others, the answer is that this plugin only supports github.com at the moment. Pull requests are welcome to add support for thanking packages hosted on other services.
Original idea by Doug Tangren (softprops) 2017 for Rust (thanks!)
Implemented by Nicolas Grekas (SensioLabs & Blackfire.io) 2017 for PHP.
Forwarding stars
----------------
Package authors can *send* a star to another package that they would like to thank.
If you are a package author and want to thank another repository, you can add a `thanks` entry in the `extra` section of your `composer.json` file.
For example, `symfony/webpack-encore-pack` sends a star to `symfony/webpack-encore`:
```json
{
"extra": {
"thanks": {
"name": "symfony/webpack-encore",
"url": "https://github.com/symfony/webpack-encore"
}
}
}
```
================================================
FILE: composer.json
================================================
{
"name": "symfony/thanks",
"description": "Encourages sending ⭐ and 💵 to fellow PHP package maintainers (not limited to Symfony components)!",
"type": "composer-plugin",
"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
}
],
"require": {
"php": ">=8.1",
"composer-plugin-api": "^1.0|^2.0"
},
"autoload": {
"psr-4": {
"Symfony\\Thanks\\": "src"
}
},
"extra": {
"branch-alias": {
"dev-main": "1.4-dev"
},
"class": "Symfony\\Thanks\\Thanks"
}
}
================================================
FILE: src/Command/FundCommand.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.
*/
namespace Symfony\Thanks\Command;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Thanks\GitHubClient;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class FundCommand extends BaseCommand
{
private $star = '★ ';
private $love = '💖 ';
private $cash = '💵 ';
protected function configure(): void
{
if ('Hyper' === getenv('TERM_PROGRAM')) {
$this->star = '⭐ ';
} elseif ('\\' === \DIRECTORY_SEPARATOR) {
$this->star = '*';
$this->love = '<3';
$this->cash = '$$$';
}
$this->setName('fund')
->setDescription(sprintf('Discover the funding links that fellow PHP package maintainers publish %s.', $this->cash))
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$composer = $this->getComposer();
$gitHub = new GitHubClient($composer, $this->getIO());
$repos = $gitHub->getRepositories($failures, true);
$fundings = [];
$notStarred = 0;
foreach ($repos as $alias => $repo) {
$notStarred += (int) !$repo['viewerHasStarred'];
foreach ($repo['fundingLinks'] as $link) {
list($owner, $package) = explode('/', $repo['package'], 2);
$fundings[$owner][$link['url']][] = $package;
}
}
if ($fundings) {
$prev = null;
$output->writeln('The following packages were found in your dependencies and publish sponsoring links on their GitHub page:');
foreach ($fundings as $owner => $links) {
$output->writeln(sprintf("\n<comment>%s</comment>", $owner));
foreach ($links as $url => $packages) {
$line = sprintf(' <info>%s/%s</>', $owner, implode(', ', $packages));
if ($prev !== $line) {
$output->writeln($line);
$prev = $line;
}
$output->writeln(sprintf(' %s %s', $this->cash, $url));
}
}
$output->writeln("\nPlease consider following these links and sponsoring the work of package authors!");
$output->writeln(sprintf("\nThank you! %s", $this->love));
} else {
$output->writeln("No funding links were found in your package dependencies. This doesn't mean they don't need your support!");
}
if ($notStarred) {
$output->writeln(sprintf("\nRun <comment>composer thanks</> to send a %s to <comment>%d</comment> GitHub repositor%s of your fellow package maintainers.", $this->star, $notStarred, 1 < $notStarred ? 'ies' : 'y'));
}
return 0;
}
}
================================================
FILE: src/Command/ThanksCommand.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.
*/
namespace Symfony\Thanks\Command;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Thanks\GitHubClient;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class ThanksCommand extends BaseCommand
{
private $star = '★ ';
private $love = '💖 ';
private $cash = '💵 ';
protected function configure(): void
{
if ('Hyper' === getenv('TERM_PROGRAM')) {
$this->star = '⭐ ';
} elseif ('\\' === \DIRECTORY_SEPARATOR) {
$this->star = '*';
$this->love = '<3';
$this->cash = '$$$';
}
$this->setName('thanks')
->setDescription(sprintf('Give thanks (in the form of a GitHub %s) to your fellow PHP package maintainers.', $this->star))
->setDefinition([
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Don\'t actually send the stars'),
])
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$composer = $this->getComposer();
$gitHub = new GitHubClient($composer, $this->getIO());
$repos = $gitHub->getRepositories($failures);
$template = '%1$s: addStar(input:{clientMutationId:"%s",starrableId:"%s"}){clientMutationId}'."\n";
$graphql = '';
$notStarred = [];
foreach ($repos as $alias => $repo) {
if (!$repo['viewerHasStarred']) {
$graphql .= sprintf($template, $alias, $repo['id']);
$notStarred[$alias] = $repo;
}
}
if (!$notStarred) {
$output->writeln('You already starred all your GitHub dependencies.');
} else {
if (!$input->getOption('dry-run')) {
$notStarred = $gitHub->call(sprintf("mutation{\n%s}", $graphql));
}
$output->writeln('Stars <comment>sent</> to:');
foreach ($repos as $alias => $repo) {
$output->writeln(sprintf(' %s %s - %s', $this->star, sprintf(isset($notStarred[$alias]) ? '<comment>%s</>' : '%s', $repo['package']), $repo['url']));
}
}
if ($failures) {
$output->writeln('');
$output->writeln('Some repositories could not be starred, please run <info>composer update</info> and try again:');
foreach ($failures as $alias => $failure) {
foreach ((array) $failure['messages'] as $message) {
$output->writeln(sprintf(' * %s - %s', $failure['url'], $message));
}
}
}
$output->writeln("\nPlease consider contributing back in any way if you can!");
$output->writeln(sprintf("\nRun <comment>composer fund</> to discover how you can sponsor your fellow PHP package maintainers %s", $this->cash));
$output->writeln(sprintf("\nThank you! %s", $this->love));
return 0;
}
}
================================================
FILE: src/GitHubClient.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.
*/
namespace Symfony\Thanks;
use Composer\Composer;
use Composer\Downloader\TransportException;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Util\HttpDownloader;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class GitHubClient
{
// This is a list of projects that should get a star on their main repository
// (when there is one) whenever you use any of their other repositories.
// When a project's main repo is also a dependency of their other repos (like amphp/amp),
// there is no need to list it here, as starring will transitively happen anyway.
private static $mainRepositories = [
'api-platform' => [
'name' => 'api-platform/api-platform',
'url' => 'https://github.com/api-platform/api-platform',
],
'cakephp' => [
'name' => 'cakephp/cakephp',
'url' => 'https://github.com/cakephp/cakephp',
],
'drupal' => [
'name' => 'drupal/drupal',
'url' => 'https://github.com/drupal/drupal',
],
'laravel' => [
'name' => 'laravel/laravel',
'url' => 'https://github.com/laravel/laravel',
],
'illuminate' => [
'name' => 'laravel/laravel',
'url' => 'https://github.com/laravel/laravel',
],
'nette' => [
'name' => 'nette/nette',
'url' => 'https://github.com/nette/nette',
],
'phpDocumentor' => [
'name' => 'phpDocumentor/phpDocumentor2',
'url' => 'https://github.com/phpDocumentor/phpDocumentor2',
],
'matomo' => [
'name' => 'piwik/piwik',
'url' => 'https://github.com/matomo-org/matomo',
],
'reactphp' => [
'name' => 'reactphp/react',
'url' => 'https://github.com/reactphp/react',
],
'sebastianbergmann' => [
'name' => 'phpunit/phpunit',
'url' => 'https://github.com/sebastianbergmann/phpunit',
],
'slimphp' => [
'name' => 'slimphp/Slim',
'url' => 'https://github.com/slimphp/Slim',
],
'Sylius' => [
'name' => 'Sylius/Sylius',
'url' => 'https://github.com/Sylius/Sylius',
],
'symfony' => [
'name' => 'symfony/symfony',
'url' => 'https://github.com/symfony/symfony',
],
'yiisoft' => [
'name' => 'yiisoft/yii2',
'url' => 'https://github.com/yiisoft/yii2',
],
'zendframework' => [
'name' => 'zendframework/zendframework',
'url' => 'https://github.com/zendframework/zendframework',
],
];
private $composer;
private $io;
private $rfs;
public function __construct(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->io = $io;
if (class_exists(HttpDownloader::class)) {
$this->rfs = new HttpDownloader($io, $composer->getConfig());
} else {
$this->rfs = Factory::createRemoteFilesystem($io, $composer->getConfig());
}
}
public function getRepositories(?array &$failures = null, bool $withFundingLinks = false): array
{
$repo = $this->composer->getRepositoryManager()->getLocalRepository();
$urls = [
'composer/composer' => 'https://github.com/composer/composer',
'php/php-src' => 'https://github.com/php/php-src',
'symfony/thanks' => 'https://github.com/symfony/thanks',
];
$directPackages = $this->getDirectlyRequiredPackageNames();
// symfony/thanks shouldn't trigger thanking symfony/symfony
unset($directPackages['symfony/thanks']);
foreach ($repo->getPackages() as $package) {
$extra = $package->getExtra();
if (isset($extra['thanks']['name'], $extra['thanks']['url'])) {
$urls += [$extra['thanks']['name'] => $extra['thanks']['url']];
}
if (!$url = $package->getSourceUrl()) {
continue;
}
$urls[$package->getName()] = $url;
if (!preg_match('#^https://github.com/([^/]++)#', $url, $url)) {
continue;
}
$owner = $url[1];
// star the main repository, but only if this package is directly
// being required by the user's composer.json
if (isset(self::$mainRepositories[$owner], $directPackages[$package->getName()])) {
$urls[self::$mainRepositories[$owner]['name']] = self::$mainRepositories[$owner]['url'];
}
}
ksort($urls);
$chunks = array_chunk($urls, 150, true);
$repos = [];
foreach ($chunks as $chunk) {
$repos += $this->processChunks($chunk, $withFundingLinks, $failures);
}
return $repos;
}
public function call($graphql, array &$failures = []): mixed
{
$options = [
'http' => [
'method' => 'POST',
'content' => json_encode(['query' => $graphql]),
'header' => ['Content-Type: application/json'],
],
];
if ($this->rfs instanceof HttpDownloader) {
$result = $this->rfs->get('https://api.github.com/graphql', $options)->getBody();
} else {
$result = $this->rfs->getContents('github.com', 'https://api.github.com/graphql', false, $options);
}
$result = json_decode($result, true);
if (isset($result['errors'][0]['message'])) {
if (!isset($result['data'])) {
throw new TransportException($result['errors'][0]['message']);
}
foreach ($result['errors'] as $error) {
if (!isset($error['path'])) {
$failures[isset($error['type']) ? $error['type'] : $error['message']] = $error['message'];
continue;
}
foreach ($error['path'] as $path) {
$failures += [$path => $error['message']];
unset($result['data'][$path]);
}
}
}
return isset($result['data']) ? $result['data'] : [];
}
private function getDirectlyRequiredPackageNames(): array
{
$file = new JsonFile(Factory::getComposerFile(), null, $this->io);
if (!$file->exists()) {
throw new \Exception('Could not find your composer.json file!');
}
$data = $file->read() + ['require' => [], 'require-dev' => []];
$data = array_keys($data['require'] + $data['require-dev']);
return array_combine($data, $data);
}
private function processChunks(array $urls, bool $withFundingLinks, ?array &$failures = null): array
{
$i = 0;
$template = $withFundingLinks
? '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred,fundingLinks{platform,url}}'."\n"
: '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred}'."\n";
$graphql = '';
$aliases = [];
foreach ($urls as $package => $url) {
if (preg_match('#^https://github.com/([^/]++)/(.*?)(?:\.git)?$#i', $url, $url)) {
$graphql .= sprintf($template, ++$i, $url[1], $url[2]);
$aliases['_'.$i] = [$package, sprintf('https://github.com/%s/%s', $url[1], $url[2])];
}
}
$failures = [];
$repos = [];
foreach ($this->call(sprintf("query{\n%s}", $graphql), $failures) as $alias => $repo) {
$repo['package'] = $aliases[$alias][0];
$repo['url'] = $aliases[$alias][1];
$repos[$alias] = $repo;
}
foreach ($failures as $alias => $messages) {
$failures[$alias] = [
'messages' => $messages,
'package' => $aliases[$alias][0],
'url' => $aliases[$alias][1],
];
}
return $repos;
}
}
================================================
FILE: src/Thanks.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.
*/
namespace Symfony\Thanks;
use Composer\Composer;
use Composer\Console\Application;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event as ScriptEvent;
use Composer\Script\ScriptEvents;
use Symfony\Component\Console\Input\ArgvInput;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class Thanks implements EventSubscriberInterface, PluginInterface
{
private $io;
private $displayReminder = 0;
public function activate(Composer $composer, IOInterface $io): void
{
$this->io = $io;
$addCommand = 'add'.(method_exists(Application::class, 'addCommand') ? 'Command' : '');
foreach (debug_backtrace() as $trace) {
if (!isset($trace['object']) || !isset($trace['args'][0])) {
continue;
}
if (!$trace['object'] instanceof Application || !$trace['args'][0] instanceof ArgvInput) {
continue;
}
$input = $trace['args'][0];
$app = $trace['object'];
try {
$command = $input->getFirstArgument();
$command = $command ? $app->find($command)->getName() : null;
} catch (\InvalidArgumentException $e) {
}
if ('update' === $command) {
$this->displayReminder = 1;
}
$app->$addCommand(new Command\ThanksCommand());
if (!$app->has('fund')) {
$app->$addCommand(new Command\FundCommand());
}
break;
}
}
public function enableReminder(): void
{
if (1 === $this->displayReminder) {
$this->displayReminder = version_compare('1.1.0', PluginInterface::PLUGIN_API_VERSION, '<=') ? 2 : 0;
}
}
public function displayReminder(ScriptEvent $event): void
{
if (2 !== $this->displayReminder) {
return;
}
$gitHub = new GitHubClient($event->getComposer(), $event->getIO());
$notStarred = 0;
foreach ($gitHub->getRepositories() as $repo) {
$notStarred += (int) !$repo['viewerHasStarred'];
}
if (!$notStarred) {
return;
}
$love = '💖 ';
$star = '★ ';
$cash = '💵 ';
if ('Hyper' === getenv('TERM_PROGRAM')) {
$star = '⭐ ';
} elseif ('\\' === \DIRECTORY_SEPARATOR) {
$love = 'love';
$star = 'star';
$cash = 'cash.';
}
$this->io->writeError('');
$this->io->writeError('What about running <comment>composer thanks</> now?</>');
$this->io->writeError(sprintf('This will spread some %s by sending a %s to <comment>%d</comment> GitHub repositor%s of your fellow package maintainers.', $love, $star, $notStarred, 1 < $notStarred ? 'ies' : 'y'));
$this->io->writeError(sprintf('You can also run <comment>composer fund</> to discover how you can sponsor their work with some %s</>', $cash));
$this->io->writeError('');
}
public static function getSubscribedEvents(): array
{
return [
PackageEvents::POST_PACKAGE_UPDATE => 'enableReminder',
ScriptEvents::POST_UPDATE_CMD => 'displayReminder',
];
}
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io): void
{
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io): void
{
}
}
gitextract_mjqcaiah/
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
└── src/
├── Command/
│ ├── FundCommand.php
│ └── ThanksCommand.php
├── GitHubClient.php
└── Thanks.php
SYMBOL INDEX (19 symbols across 4 files)
FILE: src/Command/FundCommand.php
class FundCommand (line 23) | class FundCommand extends BaseCommand
method configure (line 29) | protected function configure(): void
method execute (line 44) | protected function execute(InputInterface $input, OutputInterface $out...
FILE: src/Command/ThanksCommand.php
class ThanksCommand (line 23) | class ThanksCommand extends BaseCommand
method configure (line 29) | protected function configure(): void
method execute (line 47) | protected function execute(InputInterface $input, OutputInterface $out...
FILE: src/GitHubClient.php
class GitHubClient (line 24) | class GitHubClient
method __construct (line 97) | public function __construct(Composer $composer, IOInterface $io)
method getRepositories (line 109) | public function getRepositories(?array &$failures = null, bool $withFu...
method call (line 160) | public function call($graphql, array &$failures = []): mixed
method getDirectlyRequiredPackageNames (line 199) | private function getDirectlyRequiredPackageNames(): array
method processChunks (line 213) | private function processChunks(array $urls, bool $withFundingLinks, ?a...
FILE: src/Thanks.php
class Thanks (line 27) | class Thanks implements EventSubscriberInterface, PluginInterface
method activate (line 32) | public function activate(Composer $composer, IOInterface $io): void
method enableReminder (line 69) | public function enableReminder(): void
method displayReminder (line 76) | public function displayReminder(ScriptEvent $event): void
method getSubscribedEvents (line 112) | public static function getSubscribedEvents(): array
method deactivate (line 123) | public function deactivate(Composer $composer, IOInterface $io): void
method uninstall (line 130) | public function uninstall(Composer $composer, IOInterface $io): void
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (23K chars).
[
{
"path": ".gitignore",
"chars": 23,
"preview": "/vendor/\ncomposer.lock\n"
},
{
"path": "LICENSE",
"chars": 1065,
"preview": "Copyright (c) 2017-2019 Fabien Potencier\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\no"
},
{
"path": "README.md",
"chars": 1763,
"preview": "<p align=\"center\"><a href=\"https://symfony.com\" target=\"_blank\">\n <img src=\"https://symfony.com/logos/symfony_black_0"
},
{
"path": "composer.json",
"chars": 645,
"preview": "{\n \"name\": \"symfony/thanks\",\n \"description\": \"Encourages sending ⭐ and 💵 to fellow PHP package maintainers (not li"
},
{
"path": "src/Command/FundCommand.php",
"chars": 3143,
"preview": "<?php\n\n/*\n * This file is part of the Symfony package.\n *\n * (c) Fabien Potencier <fabien@symfony.com>\n *\n * For the ful"
},
{
"path": "src/Command/ThanksCommand.php",
"chars": 3288,
"preview": "<?php\n\n/*\n * This file is part of the Symfony package.\n *\n * (c) Fabien Potencier <fabien@symfony.com>\n *\n * For the ful"
},
{
"path": "src/GitHubClient.php",
"chars": 8353,
"preview": "<?php\n\n/*\n * This file is part of the Symfony package.\n *\n * (c) Fabien Potencier <fabien@symfony.com>\n *\n * For the ful"
},
{
"path": "src/Thanks.php",
"chars": 3853,
"preview": "<?php\n\n/*\n * This file is part of the Symfony package.\n *\n * (c) Fabien Potencier <fabien@symfony.com>\n *\n * For the ful"
}
]
About this extraction
This page contains the full source code of the symfony/thanks GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (21.6 KB), approximately 5.6k tokens, and a symbol index with 19 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.