Skip to content
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
}
}