Skip to content

Commit 0051671

Browse files
committed
more styling adjustments + add PHP Filter
1 parent 04483ee commit 0051671

File tree

7 files changed

+203
-150
lines changed

7 files changed

+203
-150
lines changed

resources/css/style.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
--color-base-300: hsl(210 20% 94%);
2020
--color-base-content: hsl(220 13% 18%);
2121

22-
--color-primary: hsl(214 84% 46%);
22+
--color-primary: var(--color-cake-red);
2323
--color-primary-content: hsl(0 0% 100%);
24-
--color-secondary: hsl(262 80% 50%);
24+
--color-secondary: var(--color-cake-blue);
2525
--color-secondary-content: hsl(0 0% 100%);
2626
--color-accent: hsl(199 89% 48%);
2727
--color-accent-content: hsl(0 0% 100%);
@@ -48,6 +48,7 @@
4848
@theme {
4949
--font-raleway: "Raleway", sans-serif;
5050
--color-cake-red: #d33c44;
51+
--color-cake-blue: #2F85AE;
5152
}
5253

5354
/* Styling for default app homepage */
@@ -79,7 +80,7 @@
7980
}
8081

8182
[data-is-php-filter] + .ss-main {
82-
--ss-primary-color: var(--color-blue-500);
83+
--ss-primary-color: var(--color-cake-blue);
8384
}
8485

8586
.htmx-indicator {

src/Command/SyncPackagesCommand.php

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Cake\Console\ConsoleIo;
1010
use Cake\Log\Log;
1111
use Composer\Semver\Intervals;
12-
use Composer\Semver\Semver;
1312
use Composer\Semver\VersionParser;
1413
use Packagist\Api\Client;
1514
use UnexpectedValueException;
@@ -19,6 +18,33 @@
1918
*/
2019
class SyncPackagesCommand extends Command
2120
{
21+
private const CAKEPHP_SUBPACKAGES = [
22+
'cakephp/cache',
23+
'cakephp/collection',
24+
'cakephp/console',
25+
'cakephp/database',
26+
'cakephp/datasource',
27+
'cakephp/event',
28+
'cakephp/form',
29+
'cakephp/http',
30+
'cakephp/i18n',
31+
'cakephp/log',
32+
'cakephp/orm',
33+
'cakephp/utility',
34+
'cakephp/validation',
35+
];
36+
37+
private const PHP_VERSIONS = [
38+
'7' => [0, 1, 2, 3, 4],
39+
'8' => [0, 1, 2, 3, 4, 5],
40+
];
41+
42+
private const CAKEPHP_VERSIONS = [
43+
'3' => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
44+
'4' => [0, 1, 2, 3, 4, 5, 6],
45+
'5' => [0, 1, 2, 3],
46+
];
47+
2248
private Client $client;
2349

2450
/**
@@ -121,34 +147,18 @@ private function getDataForPackage(string $packageName): array
121147
foreach ($versions as $versionMeta) {
122148
$phpRequire = $versionMeta->getRequire()['php'] ?? null;
123149
if ($phpRequire) {
124-
$meta = $this->checkPHPVersion($meta, $phpRequire);
150+
$meta = $this->appendVersionTags($meta, $phpRequire, 'PHP', self::PHP_VERSIONS);
125151
}
126152

127153
$cakephpRequire = $versionMeta->getRequire()['cakephp/cakephp'] ?? null;
128154
if ($cakephpRequire) {
129-
$meta = $this->checkCakeVersion($meta, $cakephpRequire);
155+
$meta = $this->appendVersionTags($meta, $cakephpRequire, 'CakePHP', self::CAKEPHP_VERSIONS);
130156
} else {
131157
// Cake has standalone sub-packages
132-
$subpackages = [
133-
'cakephp/cache',
134-
'cakephp/collection',
135-
'cakephp/console',
136-
'cakephp/database',
137-
'cakephp/datasource',
138-
'cakephp/event',
139-
'cakephp/form',
140-
'cakephp/http',
141-
'cakephp/i18n',
142-
'cakephp/log',
143-
'cakephp/orm',
144-
'cakephp/utility',
145-
'cakephp/validation',
146-
];
147-
148-
foreach ($subpackages as $subpackage) {
158+
foreach (self::CAKEPHP_SUBPACKAGES as $subpackage) {
149159
$cakephpRequire = $versionMeta->getRequire()[$subpackage] ?? null;
150160
if ($cakephpRequire) {
151-
$meta = $this->checkCakeVersion($meta, $cakephpRequire);
161+
$meta = $this->appendVersionTags($meta, $cakephpRequire, 'CakePHP', self::CAKEPHP_VERSIONS);
152162
}
153163
}
154164
}
@@ -160,7 +170,7 @@ private function getDataForPackage(string $packageName): array
160170
});
161171
$latestStable = end($stableVersions);
162172

163-
$data = [
173+
return [
164174
'package' => $packageName,
165175
'description' => $metaDetails->getDescription(),
166176
'repo_url' => $metaDetails->getRepository(),
@@ -170,57 +180,25 @@ private function getDataForPackage(string $packageName): array
170180
'latest_stable_version' => $latestStable ? $latestStable->getVersion() : null,
171181
'is_abandoned' => $metaDetails->isAbandoned(),
172182
];
173-
174-
return $data;
175-
}
176-
177-
/**
178-
* @param array $meta
179-
* @param string $packageConstraint
180-
* @return array
181-
*/
182-
private function checkPHPVersion(array $meta, string $packageConstraint): array
183-
{
184-
$phpVersions = [
185-
'8.5.0' => 'PHP: 8.5',
186-
'8.4.0' => 'PHP: 8.4',
187-
'8.3.0' => 'PHP: 8.3',
188-
'8.2.0' => 'PHP: 8.2',
189-
'8.1.0' => 'PHP: 8.1',
190-
'8.0.0' => 'PHP: 8.0',
191-
'7.4.0' => 'PHP: 7.4',
192-
'7.3.0' => 'PHP: 7.3',
193-
'7.2.0' => 'PHP: 7.2',
194-
'7.1.0' => 'PHP: 7.1',
195-
'7.0.0' => 'PHP: 7.0',
196-
];
197-
198-
foreach ($phpVersions as $version => $label) {
199-
if (Semver::satisfies($version, $packageConstraint) && !in_array($label, $meta)) {
200-
$meta[] = $label;
201-
}
202-
}
203-
204-
return $meta;
205183
}
206184

207185
/**
208-
* @param array $meta
209-
* @param string $packageConstraint
186+
* @param array $meta The meta array to adjust
187+
* @param string $packageConstraint The meta array which contains the current version strings
188+
* @param string $tagPrefix The prefix which should be used for the tag
189+
* @param array<string, array<int>> $versions The versions to check
210190
* @return array
211191
*/
212-
private function checkCakeVersion(array $meta, string $packageConstraint): array
213-
{
214-
$versions = [
215-
'3' => [0,1,2,3,4,5,6,7,8,9,10],
216-
'4' => [0,1,2,3,4,5,6],
217-
'5' => [0,1,2,3],
218-
];
219-
192+
private function appendVersionTags(
193+
array $meta,
194+
string $packageConstraint,
195+
string $tagPrefix,
196+
array $versions,
197+
): array {
220198
foreach ($versions as $majorVersionNr => $minorVersions) {
221199
foreach ($minorVersions as $minorVersionNr) {
222200
$minorVersion = sprintf('%s.%s', $majorVersionNr, $minorVersionNr);
223-
$tagLabel = sprintf('CakePHP: %s.%s', $majorVersionNr, $minorVersionNr);
201+
$tagLabel = sprintf('%s: %s', $tagPrefix, $minorVersion);
224202
if (
225203
$this->constraintsIntersect($packageConstraint, $minorVersion) &&
226204
!in_array($tagLabel, $meta, true)

src/Controller/PackagesController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public function index()
7979
$cakephpTags = $this->Packages->Tags->find('list', keyField: 'slug')
8080
->where(['slug LIKE' => 'cakephp-%'])
8181
->toArray();
82-
$cakephpTags = $this->sortCakePhpTags($cakephpTags);
82+
$cakephpTags = $this->sortVersionTags($cakephpTags, 'CakePHP');
8383
$phpTags = $this->Packages->Tags->find('list', keyField: 'slug')
8484
->where(['slug LIKE' => 'php-%'])
85-
->orderByAsc('label')
8685
->toArray();
86+
$phpTags = $this->sortVersionTags($phpTags, 'PHP');
8787

8888
$this->set(compact('featuredPackages', 'packages', 'cakephpTags', 'phpTags'));
8989
}
@@ -119,11 +119,12 @@ protected function hasActiveFilterValue(mixed $value): bool
119119
* @param array<string, string> $tags
120120
* @return array<string, string>
121121
*/
122-
protected function sortCakePhpTags(array $tags): array
122+
protected function sortVersionTags(array $tags, string $prefix): array
123123
{
124-
uasort($tags, function (string $left, string $right): int {
125-
$leftVersion = preg_replace('/^CakePHP:\s*/', '', $left) ?: $left;
126-
$rightVersion = preg_replace('/^CakePHP:\s*/', '', $right) ?: $right;
124+
$pattern = '/^' . preg_quote($prefix, '/') . ':\s*/';
125+
uasort($tags, static function (string $left, string $right) use ($pattern): int {
126+
$leftVersion = preg_replace($pattern, '', $left) ?: $left;
127+
$rightVersion = preg_replace($pattern, '', $right) ?: $right;
127128

128129
return version_compare($rightVersion, $leftVersion);
129130
});

src/Model/Entity/Package.php

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @property \Tags\Model\Entity\Tag[] $cake_php_tags
2222
* @property array<int, array<\Tags\Model\Entity\Tag>> $cake_php_tag_groups
2323
* @property \Tags\Model\Entity\Tag[] $php_tags
24+
* @property array<int, array<\Tags\Model\Entity\Tag>> $php_tag_groups
2425
*/
2526
class Package extends Entity
2627
{
@@ -43,20 +44,56 @@ class Package extends Entity
4344
*/
4445
protected function _getCakePhpTags(): array
4546
{
46-
return array_filter($this->tags, function ($tag) {
47-
return str_starts_with($tag->label, 'CakePHP');
48-
});
47+
return $this->extractVersionTags('CakePHP');
4948
}
5049

5150
/**
5251
* @return array<int, array<\Tags\Model\Entity\Tag>>
5352
*/
5453
protected function _getCakePhpTagGroups(): array
54+
{
55+
return $this->groupVersionTags($this->cake_php_tags, 'CakePHP');
56+
}
57+
58+
/**
59+
* @return array<\Tags\Model\Entity\Tag>
60+
*/
61+
protected function _getPhpTags(): array
62+
{
63+
return $this->extractVersionTags('PHP');
64+
}
65+
66+
/**
67+
* @return array<int, array<\Tags\Model\Entity\Tag>>
68+
*/
69+
protected function _getPhpTagGroups(): array
70+
{
71+
return $this->groupVersionTags($this->php_tags, 'PHP');
72+
}
73+
74+
/**
75+
* @param string $prefix
76+
* @return array<\Tags\Model\Entity\Tag>
77+
*/
78+
protected function extractVersionTags(string $prefix): array
79+
{
80+
return array_filter($this->tags, static function ($tag) use ($prefix) {
81+
return str_starts_with($tag->label, $prefix . ':');
82+
});
83+
}
84+
85+
/**
86+
* @param array<\Tags\Model\Entity\Tag> $tags
87+
* @param string $prefix
88+
* @return array<int, array<\Tags\Model\Entity\Tag>>
89+
*/
90+
protected function groupVersionTags(array $tags, string $prefix): array
5591
{
5692
$groups = [];
93+
$quotedPrefix = preg_quote($prefix, '/');
5794

58-
foreach ($this->cake_php_tags as $tag) {
59-
if (!preg_match('/^CakePHP:\s*(\d+)(?:\.\d+)?$/', $tag->label, $matches)) {
95+
foreach ($tags as $tag) {
96+
if (!preg_match('/^' . $quotedPrefix . ':\s*(\d+)(?:\.\d+)?$/', $tag->label, $matches)) {
6097
continue;
6198
}
6299

@@ -68,26 +105,16 @@ protected function _getCakePhpTagGroups(): array
68105
return version_compare($right, $left);
69106
});
70107

71-
foreach ($groups as &$tags) {
72-
usort($tags, static function ($left, $right): int {
73-
$leftVersion = str_replace('CakePHP: ', '', $left->label);
74-
$rightVersion = str_replace('CakePHP: ', '', $right->label);
108+
foreach ($groups as &$groupedTags) {
109+
usort($groupedTags, static function ($left, $right) use ($prefix): int {
110+
$leftVersion = preg_replace('/^' . preg_quote($prefix, '/') . ':\s*/', '', $left->label) ?: $left->label;
111+
$rightVersion = preg_replace('/^' . preg_quote($prefix, '/') . ':\s*/', '', $right->label) ?: $right->label;
75112

76113
return version_compare($rightVersion, $leftVersion);
77114
});
78115
}
79-
unset($tags);
116+
unset($groupedTags);
80117

81118
return $groups;
82119
}
83-
84-
/**
85-
* @return array<\Tags\Model\Entity\Tag>
86-
*/
87-
protected function _getPhpTags(): array
88-
{
89-
return array_filter($this->tags, function ($tag) {
90-
return str_starts_with($tag->label, 'PHP');
91-
});
92-
}
93120
}

src/Model/Filter/PackagesCollection.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ public function initialize(): void
2121
'wildcardAny' => '*',
2222
'wildcardOne' => '?',
2323
'fields' => ['package', 'description'],
24-
])
25-
->callback('cakephp_slugs', [
26-
'callback' => function (SelectQuery $query, array $args, $manager): void {
27-
// Here you would have to remap $args if key isn't the expected "tag"
28-
$args['slug'] = $args['cakephp_slugs'];
29-
unset($args['cakephp_slugs']);
30-
$query->find('tagged', ...$args);
31-
},
32-
])
33-
->callback('php_slugs', [
34-
'callback' => function (SelectQuery $query, array $args, $manager): void {
35-
// Here you would have to remap $args if key isn't the expected "tag"
36-
$args['slug'] = $args['php_slugs'];
37-
unset($args['php_slugs']);
38-
$query->find('tagged', ...$args);
39-
},
40-
]);
24+
]);
25+
26+
$this->addTaggedSlugFilter('cakephp_slugs');
27+
$this->addTaggedSlugFilter('php_slugs');
28+
}
29+
30+
/**
31+
* @param string $filterName
32+
* @return void
33+
*/
34+
protected function addTaggedSlugFilter(string $filterName): void
35+
{
36+
$this->callback($filterName, [
37+
'callback' => function (SelectQuery $query, array $args) use ($filterName): void {
38+
$args['slug'] = $args[$filterName];
39+
unset($args[$filterName]);
40+
$query->find('tagged', ...$args);
41+
},
42+
]);
4143
}
4244
}

templates/Packages/index.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ class="packages index content"
9090
'data-placeholder' => __('CakePHP Version'),
9191
'class' => 'select select-bordered join-item'
9292
]);
93-
// echo $this->Form->control('php_slugs', [
94-
// 'label' => false,
95-
// 'options' => $phpTags,
96-
// 'empty' => __('No Filter'),
97-
// 'multiple' => true,
98-
// 'data-placeholder' => __('PHP Version'),
99-
// 'data-is-php-filter' => true,
100-
// 'class' => 'select select-bordered join-item'
101-
// ]);
93+
echo $this->Form->control('php_slugs', [
94+
'label' => false,
95+
'options' => $phpTags,
96+
'multiple' => true,
97+
'data-placeholder' => __('PHP Version'),
98+
'data-is-php-filter' => true,
99+
'class' => 'select select-bordered join-item'
100+
]);
102101
echo $this->Form->button(__('Apply'), [
103102
'type' => 'submit',
104103
]);

0 commit comments

Comments
 (0)