Skip to content

Commit

Permalink
Merge branch '3.x' into pull/43
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 11, 2022
2 parents 3434746 + 6aff799 commit 97c4452
Show file tree
Hide file tree
Showing 19 changed files with 529 additions and 20 deletions.
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Bug Report
description: 🐛 File a bug report
title: "🐛 "
labels: ["type:bug", "status:to be verified"]
assignees:
- roxblnfk
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: checkboxes
id: search-done
attributes:
label: No duplicates 🥲.
options:
- label: I have searched for a similar issue in our bug tracker and didn't find any solutions.
required: true
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen? Please write only in English.
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: textarea
id: version
attributes:
label: Version
description: What version of our software are you running?
value: "annotated v3.0.0, orm v2.0.0, PHP 8.1"
validations:
required: true
- type: textarea
id: schema
attributes:
label: ORM Schema
description: Please provide a relevant part of the ORM Schema. You can get schema using [schema-renderer](https://github.com/cycle/schema-renderer)
render: shell
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
blank_issues_enabled: false

contact_links:
- name: ❓ Start a discussion or ask a question.
url: https://github.com/cycle/orm/discussions
about: Please ask and answer questions here.
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Feauture request
description: 💡 Suggest an idea for this project
title: "💡 "
labels: ["type:feature"]
assignees:
- roxblnfk
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to share your idea!
- type: textarea
id: idea
attributes:
label: I have an idea!
description: Clear and concise description of your idea. Please write only in English.
placeholder: Tell us what you see!
value: "I have an idea, listen to me!!"
validations:
required: true
27 changes: 17 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on: [push, pull_request]

jobs:
test:
name: Test PHP ${{ matrix.php-versions }} with Code Coverage
name: Test PHP ${{ matrix.php-version }} with Code Coverage
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['8.0']
php-version: ['8.0' ,'8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -18,13 +18,13 @@ jobs:
cd tests
docker-compose up -d
cd ..
- name: Setup PHP ${{ matrix.php-versions }}
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
coverage: pcov
tools: pecl
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv-5.10.0beta2, pdo_mysql
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand All @@ -36,19 +36,26 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies with composer
if: matrix.php-versions != '8.1'
if: matrix.php-version != '8.2'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install dependencies with composer php 8.1
if: matrix.php-versions == '8.1'
if: matrix.php-version == '8.2'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Execute Tests
run: |
vendor/bin/phpunit --coverage-clover=coverage.xml
vendor/bin/phpunit --coverage-clover=coverage.clover
- name: Upload coverage to Codecov
continue-on-error: true # if is fork
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
file: ./coverage.clover

- name: Upload coverage to Scrutinizer
continue-on-error: true # if is fork
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover coverage.clover"
21 changes: 21 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
checks:
php: true

filter:
paths:
- "src/*"

tools:
external_code_coverage:
timeout: 600 # Timeout in seconds.
runs: 2 # How many code coverage submissions Scrutinizer will wait

build:
nodes:
analysis:
environment:
php: 8.0

tests:
override:
- php-scrutinizer-run
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": ">=8.0",
"spiral/tokenizer": "^2.8",
"cycle/schema-builder": "^2.0",
"cycle/schema-builder": "^2.0.1",
"doctrine/annotations": "^1.13",
"spiral/attributes": "^2.8",
"doctrine/inflector": "^2.0"
Expand Down
19 changes: 18 additions & 1 deletion src/Annotation/Relation/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@
final class Embedded extends Relation
{
protected const TYPE = 'embedded';
protected ?string $embeddedPrefix = null;

/**
* @param non-empty-string $target Entity to embed.
* @param non-empty-string $load Relation load approach.
* @param non-empty-string|null $prefix Prefix for embedded entity columns.
*/
public function __construct(
string $target,
#[ExpectedValues(values: ['lazy', 'eager'])]
string $load = 'eager'
string $load = 'eager',
?string $prefix = null,
) {
$this->embeddedPrefix = $prefix;

parent::__construct($target, $load);
}

public function getInverse(): ?Inverse
{
return null;
}

public function getPrefix(): ?string
{
return $this->embeddedPrefix;
}

public function setPrefix(string $prefix): self
{
$this->embeddedPrefix = $prefix;

return $this;
}
}
9 changes: 9 additions & 0 deletions src/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public function initRelations(EntitySchema $entity, \ReflectionClass $class): vo
);
}

if ($meta instanceof RelationAnnotation\Embedded && $meta->getPrefix() === null) {
/** @var Embeddable|null $embeddable */
$embeddable = $this->reader->firstClassMetadata(
new \ReflectionClass($relation->getTarget()),
Embeddable::class
);
$meta->setPrefix($embeddable->getColumnPrefix());
}

foreach ($meta->getOptions() as $option => $value) {
$value = match ($option) {
'collection' => $this->resolveName($value, $class),
Expand Down
3 changes: 2 additions & 1 deletion src/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ public function run(Registry $registry): Registry
if ($em === null) {
continue;
}
\assert($em instanceof Embeddable);

$e = $this->generator->initEmbedding($em, $class);

$this->verifyNoRelations($e, $class);

// columns
$this->generator->initFields($e, $class, $em->getColumnPrefix());
$this->generator->initFields($e, $class);

// register entity (OR find parent)
$registry->register($e);
Expand Down
62 changes: 62 additions & 0 deletions tests/Annotated/Fixtures/Fixtures18/Booking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures18;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Relation\HasOne;
use Cycle\Annotated\Annotation\Relation\ManyToMany;

#[Entity(
table: 'FlightBooking'
)]
class Booking
{
#[Column(type: 'primary', name: 'id_booking')]
protected ?int $bid = null;

#[Column(type: 'bigInteger', name: 'reserv_id_column')]
private int $reserv_id;

// Without manual declaration
#[HasOne(target: Reservation::class, fkCreate: false)]
protected Reservation $reservation0;

// Use property names
#[HasOne(target: Reservation::class, innerKey: 'reserv_id', outerKey: 'rid', fkCreate: false)]
protected Reservation $reservation1;

// Use column names
#[HasOne(target: Reservation::class, innerKey: 'reserv_id_column', outerKey: 'id_reservation', fkCreate: false)]
protected Reservation $reservation2;

// Without manual declaration
#[ManyToMany(target: Reservation::class, through: Pivot::class, fkCreate: false)]
protected array $reservations0;

// Use property names
#[ManyToMany(
target: Reservation::class,
through: Pivot::class,
innerKey: 'reserv_id',
outerKey: 'booking_id',
throughInnerKey: 'booking_reservation_rid',
throughOuterKey: 'booking_bid',
fkCreate: false,
)]
protected array $reservations1;

// Use column names
#[ManyToMany(
target: Reservation::class,
through: Pivot::class,
innerKey: 'reserv_id_column',
outerKey: 'booking_id_column',
throughInnerKey: 'booking_reservation_id_column',
throughOuterKey: 'reserv_id_column',
fkCreate: false,
)]
protected array $reservations2;
}
23 changes: 23 additions & 0 deletions tests/Annotated/Fixtures/Fixtures18/Pivot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures18;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;

#[Entity(
table: 'Pivotable'
)]
class Pivot
{
#[Column(type: 'primary', name: 'id_pivot')]
protected ?int $pid = null;

#[Column(type: 'bigInteger', name: 'reserv_id_column')]
private int $booking_bid;

#[Column(type: 'bigInteger', name: 'booking_reservation_id_column')]
private int $booking_reservation_rid;
}
37 changes: 37 additions & 0 deletions tests/Annotated/Fixtures/Fixtures18/Reservation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures18;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Relation\HasMany;

#[Entity(
role: 'booking_reservation',
table: 'FlightReservation'
)]
class Reservation
{
#[Column(type: 'primary', name: 'id_reservation')]
protected ?int $rid = null;

#[Column(type: 'bigInteger', name: 'booking_id_column')]
private int $booking_id;

// #[BelongsTo(target: Booking::class, innerKey: 'id', outerKey: 'FlightRezervationId', fkCreate: false)]
// private ?Booking $booking = null;

// Without manual declaration
#[HasMany(target: Segment::class, fkCreate: false)]
private array $segments0 = [];

// Use property names
#[HasMany(target: Segment::class, innerKey: 'rid', outerKey: 'parent_id', fkCreate: false)]
private array $segments1 = [];

// Use column names
#[HasMany(target: Segment::class, innerKey: 'id_reservation', outerKey: 'parent_id_column', fkCreate: false)]
private array $segments2 = [];
}
20 changes: 20 additions & 0 deletions tests/Annotated/Fixtures/Fixtures18/Segment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures18;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;

#[Entity(
table: 'FlightSegment'
)]
class Segment
{
#[Column(name: 'id_segment', type: 'primary')]
protected ?int $sid = null;

#[Column(name: 'parent_id_column', type: 'bigInteger')]
protected ?int $parent_id = null;
}
Loading

0 comments on commit 97c4452

Please sign in to comment.