Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit 407caf5

Browse files
committed
Updated for pthreads 5.0
1 parent d5ff1b5 commit 407caf5

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ jobs:
1818
- uses: actions/checkout@v3
1919

2020
- name: Setup PHP
21-
uses: pmmp/setup-php-action@87cc7c2f65e10e0e64be54a3e41a62a4c61bd1a9
21+
uses: pmmp/setup-php-action@6dd74c145250109942b08fc63cd5118edd2fd256
2222
with:
2323
php-version: ${{ matrix.php }}
2424
install-path: "./bin"
25+
pm-version-major: "5"
2526

2627
- name: Cache Composer packages
2728
id: composer-cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "LGPL-3.0",
66
"require": {
77
"php": "^8.0",
8-
"ext-pthreads": "~3.2.0 || ^4.0",
8+
"ext-pthreads": "^5.0",
99
"ext-reflection": "*"
1010
},
1111
"require-dev": {

src/BaseClassLoader.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@
1717

1818
declare(strict_types=1);
1919

20-
class BaseClassLoader extends \Threaded implements DynamicClassLoader{
20+
class BaseClassLoader extends \ThreadedBase implements DynamicClassLoader{
2121

22-
/** @var \Threaded|string[] */
22+
/**
23+
* @var \ThreadedArray|string[]
24+
* @phpstan-var \ThreadedArray<int, string>
25+
*/
2326
private $fallbackLookup;
24-
/** @var \Threaded|string[][] */
27+
/**
28+
* @var \ThreadedArray|string[][]
29+
* @phpstan-var \ThreadedArray<string, \ThreadedArray<int, string>>
30+
*/
2531
private $psr4Lookup;
2632

2733
public function __construct(){
28-
$this->fallbackLookup = new \Threaded;
29-
$this->psr4Lookup = new \Threaded;
34+
$this->fallbackLookup = new \ThreadedArray();
35+
$this->psr4Lookup = new \ThreadedArray();
3036
}
3137

3238
protected function normalizePath(string $path) : string{
@@ -46,17 +52,19 @@ public function addPath(string $namespacePrefix, string $path, bool $prepend = f
4652
}else{
4753
$namespacePrefix = trim($namespacePrefix, '\\') . '\\';
4854
$this->psr4Lookup->synchronized(function() use ($namespacePrefix, $path, $prepend) : void{
49-
/** @var \Threaded|null $list */
5055
$list = $this->psr4Lookup[$namespacePrefix] ?? null;
5156
if($list === null){
52-
$list = $this->psr4Lookup[$namespacePrefix] = new \Threaded;
57+
$list = $this->psr4Lookup[$namespacePrefix] = new \ThreadedArray();
5358
}
5459
$this->appendOrPrependLookupEntry($list, $path, $prepend);
5560
});
5661
}
5762
}
5863

59-
protected function appendOrPrependLookupEntry(\Threaded $list, string $entry, bool $prepend) : void{
64+
/**
65+
* @phpstan-param \ThreadedArray<int, string> $list
66+
*/
67+
protected function appendOrPrependLookupEntry(\ThreadedArray $list, string $entry, bool $prepend) : void{
6068
if($prepend){
6169
$entries = $this->getAndRemoveLookupEntries($list);
6270
$list[] = $entry;
@@ -69,12 +77,15 @@ protected function appendOrPrependLookupEntry(\Threaded $list, string $entry, bo
6977
}
7078

7179
/**
72-
* @return mixed[]
80+
* @return string[]
81+
*
82+
* @phpstan-param \ThreadedArray<int, string> $list
83+
* @phpstan-return list<string>
7384
*/
74-
protected function getAndRemoveLookupEntries(\Threaded $list) : array{
85+
protected function getAndRemoveLookupEntries(\ThreadedArray $list) : array{
7586
$entries = [];
76-
while($list->count() > 0){
77-
$entries[] = $list->shift();
87+
while(($entry = $list->shift()) !== null){
88+
$entries[] = $entry;
7889
}
7990
return $entries;
8091
}
@@ -127,8 +138,6 @@ public function findClass(string $name) : ?string{
127138
while(false !== $lastPos = strrpos($subPath, '\\')){
128139
$subPath = substr($subPath, 0, $lastPos);
129140
$search = $subPath . '\\';
130-
131-
/** @var \Threaded|null $lookup */
132141
$lookup = $this->psr4Lookup[$search] ?? null;
133142
if($lookup !== null){
134143
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);

tests/phpstan/stubs/pthreads.stub

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
<?php
22

33
/**
4-
* @implements \Traversable<array-key, mixed>
4+
* @implements \IteratorAggregate<array-key, mixed>
55
*/
6-
class Threaded implements \Traversable{
6+
abstract class ThreadedBase implements \IteratorAggregate{
77

88
/**
99
* @template TReturn
10-
* @param callable() : TReturn $function
10+
* @param \Closure() : TReturn $function
1111
* @param mixed ...$args
1212
* @return TReturn
1313
*/
14-
public function synchronized(callable $function, ...$args){}
14+
public function synchronized(\Closure $function, mixed ...$args) : mixed{}
1515
}
16+
17+
/**
18+
* @template TKey of array-key
19+
* @template TValue
20+
* @implements ArrayAccess<TKey, TValue>
21+
*/
22+
final class ThreadedArray extends ThreadedBase implements Countable, ArrayAccess{
23+
24+
/**
25+
* @return TValue|null
26+
*/
27+
public function pop() : mixed{}
28+
29+
/**
30+
* @return TValue|null
31+
*/
32+
public function shift() : mixed{}
33+
}

0 commit comments

Comments
 (0)