Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php-psr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [ push, pull_request ]
jobs:
test:
name: deafult with ${{ matrix.php }}
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: [ '8.1' ]
php: [ '8.3' ]
steps:
- uses: actions/checkout@v2
name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php-stan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [push, pull_request]
jobs:
test:
name: PHP ${{ matrix.php }} with ${{ matrix.database }}
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: [ '8.1' ]
php: [ '8.3' ]
steps:
- uses: actions/checkout@v2
name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [push, pull_request]
jobs:
test:
name: PHP ${{ matrix.php }} with ${{ matrix.database }}
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: [ '8.1' ]
php: [ '8.3' ]
database: [ 'mysql' ]
steps:
# MariaDB container has to be started in advance to initialize itself before using it.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"license": "GPL-3.0-or-later",
"require": {
"php": ">=8.1",
"php": ">=8.3",
"nette/di": "v3.*",
"nette/database": "v3.*",
"ext-pdo": "*",
Expand All @@ -13,7 +13,7 @@
"require-dev": {
"nette/tester": "^2.4.0",
"squizlabs/php_codesniffer": "3.6.0",
"phpstan/phpstan": "1.10.21"
"phpstan/phpstan": "2.1.21"
},
"authors": [
{
Expand Down
101 changes: 50 additions & 51 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Attributes/ReferencedFollow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Fykosak\NetteORM\Attributes;

use Attribute;

#[Attribute(\Attribute::TARGET_METHOD)]
class ReferencedFollow
{
public function __construct(public bool $follow = true)
{
}
}
12 changes: 6 additions & 6 deletions src/Exceptions/CannotAccessModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class CannotAccessModelException extends RuntimeException
* @phpstan-param class-string<Model> $modelClassName
* @phpstan-param Model $model
*/
public function __construct(string $modelClassName, Model $model, int $code = 0, ?\Throwable $previous = null)
{
public function __construct(
public readonly string $modelClassName,
public readonly Model $model,
) {
parent::__construct(
sprintf(
_('Can not access model %s from %s'),
'Can not access model %s from %s',
$modelClassName,
get_class($model)
),
$code,
$previous
)
);
}
}
9 changes: 9 additions & 0 deletions src/ModelRelationsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Fykosak\NetteORM;

use Fykosak\NetteORM\Attributes\ReferencedFollow;
use Fykosak\NetteORM\Model\Model;
use Nette\Utils\Reflection;
use Nette\Utils\Type;
Expand Down Expand Up @@ -65,6 +66,14 @@ public static function resolveReferencedMethods(\ReflectionClass $model): array
) {
continue;
}
foreach ($method->getAttributes() as $attribute) {
$instance = $attribute->newInstance();
if ($instance instanceof ReferencedFollow) {
if (!$instance->follow) {
continue 2;
}
}
}
$type = Type::fromString($returnType->getName());
if (!$type->isClass()) {
continue;
Expand Down
Loading
Loading