Skip to content

Update #[Friend] attribute to cope with inheritance #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
41 changes: 41 additions & 0 deletions examples/friend/friendWIthInheritance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace FriendWithInheritance;

use DaveLiddament\PhpLanguageExtensions\Friend;


interface Emailer
{
#[Friend(EmailQueueProcessor::class)]
public function sendEmail(): void;
}

class PhpMailer implements Emailer
{
public function sendEmail(): void
{
}
}


class EmailQueueProcessor
{
public function sendEmail(): void
{
$mailer = new PhpMailer();
$mailer->sendEmail(); // OK
}
}

class AnotherClass {
public function sendEmail(): void
{
$mailer = new PhpMailer();
$mailer->sendEmail(); // ERROR
}
}


45 changes: 45 additions & 0 deletions examples/friend/friendWIthInheritance2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace FriendWithInheritance2;

use DaveLiddament\PhpLanguageExtensions\Friend;


interface Command
{
#[Friend(CommandProcessor::class)]
public function execute(): void;
}

class PrintCommand implements Command
{

public function execute(): void
{
}
}


interface CommandProcessor
{
public function process(Command $command);
}

class PrintCommandProcessor implements CommandProcessor
{
public function process(Command $command): void
{
$command->execute(); // OK
}
}


class AnotherClass
{
public function process(Command $command): void
{
$command->execute(); // ERROR
}
}
Loading