Skip to content

Commit 95a43d5

Browse files
committed
adjust sync logic to only sync packages which require a cakephp package + add a requirements page
1 parent 697da9e commit 95a43d5

File tree

8 files changed

+177
-5
lines changed

8 files changed

+177
-5
lines changed

config/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* to use (in this case, templates/Pages/home.php)...
5757
*/
5858
$builder->connect('/', ['controller' => 'Packages', 'action' => 'index']);
59+
$builder->connect('/requirements', ['controller' => 'Pages', 'action' => 'display', 'requirements']);
5960

6061
/*
6162
* ...and connect the rest of 'Pages' controller's URLs.

src/Command/SyncPackagesCommand.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ public function execute(Arguments $args, ConsoleIo $io)
100100
foreach ($data as $package) {
101101
$data = $this->getDataForPackage($package);
102102

103-
if ($data['is_abandoned'] || !$data['latest_stable_version'] || $data['downloads'] < 10) {
103+
if (
104+
$data['is_abandoned'] ||
105+
!$data['latest_stable_version'] ||
106+
$data['downloads'] < 10 ||
107+
!$this->hasExplicitCakePhpDependency($data['tag_list'])
108+
) {
104109
continue;
105110
}
106111

@@ -196,6 +201,21 @@ private function getDataForPackage(string $packageName): array
196201
];
197202
}
198203

204+
/**
205+
* @param list<string> $tags
206+
* @return bool
207+
*/
208+
private function hasExplicitCakePhpDependency(array $tags): bool
209+
{
210+
foreach ($tags as $tag) {
211+
if (str_starts_with($tag, 'CakePHP')) {
212+
return true;
213+
}
214+
}
215+
216+
return false;
217+
}
218+
199219
/**
200220
* @param array $meta The meta array to adjust
201221
* @param string $packageConstraint The meta array which contains the current version strings

src/Controller/PagesController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
*/
3232
class PagesController extends AppController
3333
{
34+
/**
35+
* @return void
36+
*/
37+
public function initialize(): void
38+
{
39+
parent::initialize();
40+
41+
$this->Authentication->allowUnauthenticated(['display']);
42+
}
43+
3444
/**
3545
* Displays a view
3646
*

templates/Pages/requirements.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @var \App\View\AppView $this
4+
*/
5+
$this->assign('title', 'Listing Requirements');
6+
?>
7+
<section class="px-4 py-10 sm:px-6 lg:px-8">
8+
<div class="mx-auto max-w-4xl space-y-8">
9+
<header class="space-y-3">
10+
<p class="text-sm font-medium uppercase tracking-[0.2em] text-cake-red">Plugin Directory</p>
11+
<h1 class="text-4xl font-semibold text-base-content">Minimum requirements for being listed</h1>
12+
<p class="max-w-3xl text-base leading-7 text-base-content/70">
13+
Packages are only listed when they are actual CakePHP plugins with an explicit Composer dependency on the CakePHP framework package or one of the official split packages.
14+
</p>
15+
</header>
16+
17+
<div class="grid gap-6 md:grid-cols-2">
18+
<article class="rounded-3xl border border-base-300 bg-base-100 p-6 shadow-sm">
19+
<h2 class="text-xl font-semibold text-base-content">Required</h2>
20+
<ul class="mt-4 space-y-3 text-sm leading-6 text-base-content/75">
21+
<li>
22+
The package must be published on Packagist as a
23+
<?= $this->element('code_chip', ['text' => 'cakephp-plugin', 'variant' => 'accent']) ?>.
24+
</li>
25+
<li>The package must not be abandoned.</li>
26+
<li>The package must have at least 10 downloads on packagist.org.</li>
27+
<li>
28+
Its
29+
<?= $this->element('code_chip', ['text' => 'require']) ?>
30+
section must explicitly contain either
31+
<?= $this->element('code_chip', ['text' => 'cakephp/cakephp', 'variant' => 'accent']) ?>
32+
or one of the official CakePHP split packages.
33+
</li>
34+
</ul>
35+
</article>
36+
37+
<article class="rounded-3xl border border-base-300 bg-base-100 p-6 shadow-sm">
38+
<h2 class="text-xl font-semibold text-base-content">Not enough on its own</h2>
39+
<ul class="mt-4 space-y-3 text-sm leading-6 text-base-content/75">
40+
<li>Depending only on PSR interfaces or generic libraries does not qualify a package for listing.</li>
41+
<li>Suggesting CakePHP support in the README without a Composer dependency does not qualify.</li>
42+
<li>
43+
Only
44+
<?= $this->element('code_chip', ['text' => 'require']) ?>
45+
dependencies are considered for framework compatibility tags.
46+
</li>
47+
</ul>
48+
</article>
49+
</div>
50+
51+
<article class="rounded-3xl border border-cake-red/20 bg-cake-red/5 p-6">
52+
<h2 class="text-xl font-semibold text-base-content">Accepted Composer examples</h2>
53+
<div class="mt-4 grid gap-4 lg:grid-cols-2">
54+
<div>
55+
<p class="mb-2 text-sm font-medium text-base-content/70">Framework package</p>
56+
<pre class="overflow-x-auto rounded-2xl bg-base-200 p-4 text-sm"><code>{
57+
"name": "myusername/my-package-name",
58+
"type": "cakephp-plugin",
59+
"require": {
60+
"cakephp/cakephp": "^5.0"
61+
}
62+
}</code></pre>
63+
</div>
64+
<div>
65+
<p class="mb-2 text-sm font-medium text-base-content/70">Split package</p>
66+
<pre class="overflow-x-auto rounded-2xl bg-base-200 p-4 text-sm"><code>{
67+
"name": "myusername/my-package-name",
68+
"type": "cakephp-plugin",
69+
"require": {
70+
"cakephp/orm": "^5.0"
71+
}
72+
}</code></pre>
73+
</div>
74+
</div>
75+
</article>
76+
</div>
77+
</section>

templates/element/code_chip.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* @var \App\View\AppView $this
4+
* @var string $text
5+
* @var string|null $variant
6+
*/
7+
$variant = $variant ?? 'default';
8+
$classes = 'inline-flex items-center rounded-full border px-2 py-0.5 text-[0.8rem] font-semibold';
9+
10+
if ($variant === 'accent') {
11+
$classes .= ' border-cake-red/25 bg-cake-red/10 text-cake-red';
12+
} else {
13+
$classes .= ' border-base-300 bg-base-200 text-base-content';
14+
}
15+
?>
16+
<code class="<?= h($classes) ?>"><?= h($text) ?></code>

templates/layout/default.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,22 @@
4646
<div class="sticky top-0 z-40 border-b border-cake-red/70 bg-cake-red backdrop-blur-md">
4747
<div class="navbar container mx-auto px-4 sm:px-6 lg:px-8 gap-5">
4848
<div class="navbar-start">
49-
<a class="text-xl" href="<?= $this->Url->build('/') ?>">
50-
<img src="/img/cake-logo.png" class="w-28" alt="CakePHP Logo"/>
51-
</a>
49+
<div class="flex items-center gap-6">
50+
<a class="text-xl" href="<?= $this->Url->build('/') ?>">
51+
<img src="/img/cake-logo.png" class="w-28" alt="CakePHP Logo"/>
52+
</a>
53+
<div class="hidden lg:block">
54+
<?= $this->Html->link('Requirements', '/requirements', [
55+
'class' => 'text-sm font-medium text-white/85 transition hover:text-white',
56+
]) ?>
57+
</div>
58+
</div>
5259
</div>
5360
<?php
5461
$searchFormOptions = [
5562
'type' => 'get',
5663
'url' => ['controller' => 'Packages', 'action' => 'index'],
57-
'class' => 'w-full',
64+
'class' => 'w-full max-w-xl',
5865
'valueSources' => 'query', // Read existing values from query string
5966
];
6067
if ($isPackagesIndex) {
@@ -138,6 +145,7 @@
138145
</svg>
139146
</label>
140147
<ul tabindex="0" class="menu menu-sm dropdown-content z-50 mt-3 w-40 rounded-box border border-base-200 bg-base-100 p-2 shadow-lg text-base-content">
148+
<li><?= $this->Html->link('Requirements', '/requirements') ?></li>
141149
<li><?= $this->Html->link('Docs', 'https://book.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
142150
<li><?= $this->Html->link('Api', 'https://api.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
143151
<li>

tests/TestCase/Command/SyncPackagesCommandTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
namespace App\Test\TestCase\Command;
55

6+
use App\Command\SyncPackagesCommand;
67
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
78
use Cake\TestSuite\TestCase;
9+
use ReflectionMethod;
810

911
/**
1012
* App\Command\SyncPackagesCommand Test Case
@@ -15,6 +17,19 @@ class SyncPackagesCommandTest extends TestCase
1517
{
1618
use ConsoleIntegrationTestTrait;
1719

20+
/**
21+
* @return void
22+
*/
23+
public function testHasExplicitCakePhpDependency(): void
24+
{
25+
$command = new SyncPackagesCommand();
26+
$method = new ReflectionMethod($command, 'hasExplicitCakePhpDependency');
27+
$method->setAccessible(true);
28+
29+
$this->assertTrue($method->invoke($command, ['PHP: 8.2', 'CakePHP: 5.0']));
30+
$this->assertFalse($method->invoke($command, ['PHP: 8.2']));
31+
}
32+
1833
/**
1934
* Test defaultName method
2035
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Test\TestCase\Controller;
5+
6+
use Cake\TestSuite\IntegrationTestTrait;
7+
use Cake\TestSuite\TestCase;
8+
9+
class PagesControllerTest extends TestCase
10+
{
11+
use IntegrationTestTrait;
12+
13+
/**
14+
* @return void
15+
*/
16+
public function testRequirementsPage(): void
17+
{
18+
$this->get('/requirements');
19+
20+
$this->assertResponseOk();
21+
$this->assertResponseContains('Minimum requirements for being listed');
22+
$this->assertResponseContains('cakephp/cakephp');
23+
$this->assertResponseContains('cakephp/orm');
24+
}
25+
}

0 commit comments

Comments
 (0)