Skip to content

Commit 6a05784

Browse files
authored
Merge pull request #20 from fykosak/dev-mapper
Attributes
2 parents 1124585 + fdb0765 commit 6a05784

File tree

11 files changed

+91
-68
lines changed

11 files changed

+91
-68
lines changed

.github/workflows/php-psr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ on: [ push, pull_request ]
55
jobs:
66
test:
77
name: deafult with ${{ matrix.php }}
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-24.04
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php: [ '8.1' ]
12+
php: [ '8.3' ]
1313
steps:
1414
- uses: actions/checkout@v2
1515
name: Checkout

.github/workflows/php-stan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ on: [push, pull_request]
55
jobs:
66
test:
77
name: PHP ${{ matrix.php }} with ${{ matrix.database }}
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-24.04
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php: [ '8.1' ]
12+
php: [ '8.3' ]
1313
steps:
1414
- uses: actions/checkout@v2
1515
name: Checkout

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ on: [push, pull_request]
55
jobs:
66
test:
77
name: PHP ${{ matrix.php }} with ${{ matrix.database }}
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-24.04
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php: [ '8.1' ]
12+
php: [ '8.3' ]
1313
database: [ 'mysql' ]
1414
steps:
1515
# MariaDB container has to be started in advance to initialize itself before using it.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "library",
55
"license": "GPL-3.0-or-later",
66
"require": {
7-
"php": ">=8.1",
7+
"php": ">=8.3",
88
"nette/di": "v3.*",
99
"nette/database": "v3.*",
1010
"ext-pdo": "*",
@@ -13,7 +13,7 @@
1313
"require-dev": {
1414
"nette/tester": "^2.4.0",
1515
"squizlabs/php_codesniffer": "3.6.0",
16-
"phpstan/phpstan": "1.10.21"
16+
"phpstan/phpstan": "2.1.21"
1717
},
1818
"authors": [
1919
{

composer.lock

Lines changed: 50 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fykosak\NetteORM\Attributes;
6+
7+
use Attribute;
8+
9+
#[Attribute(\Attribute::TARGET_METHOD)]
10+
class ReferencedFollow
11+
{
12+
public function __construct(public bool $follow = true)
13+
{
14+
}
15+
}

src/Exceptions/CannotAccessModelException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class CannotAccessModelException extends RuntimeException
1313
* @phpstan-param class-string<Model> $modelClassName
1414
* @phpstan-param Model $model
1515
*/
16-
public function __construct(string $modelClassName, Model $model, int $code = 0, ?\Throwable $previous = null)
17-
{
16+
public function __construct(
17+
public readonly string $modelClassName,
18+
public readonly Model $model,
19+
) {
1820
parent::__construct(
1921
sprintf(
20-
_('Can not access model %s from %s'),
22+
'Can not access model %s from %s',
2123
$modelClassName,
2224
get_class($model)
23-
),
24-
$code,
25-
$previous
25+
)
2626
);
2727
}
2828
}

src/ModelRelationsParser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Fykosak\NetteORM;
66

7+
use Fykosak\NetteORM\Attributes\ReferencedFollow;
78
use Fykosak\NetteORM\Model\Model;
89
use Nette\Utils\Reflection;
910
use Nette\Utils\Type;
@@ -65,6 +66,14 @@ public static function resolveReferencedMethods(\ReflectionClass $model): array
6566
) {
6667
continue;
6768
}
69+
foreach ($method->getAttributes() as $attribute) {
70+
$instance = $attribute->newInstance();
71+
if ($instance instanceof ReferencedFollow) {
72+
if (!$instance->follow) {
73+
continue 2;
74+
}
75+
}
76+
}
6877
$type = Type::fromString($returnType->getName());
6978
if (!$type->isClass()) {
7079
continue;

0 commit comments

Comments
 (0)