Created
May 17, 2023 18:27
-
-
Save ghostwriter/4bf1d15027639b231f2ea7989b0bf5bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Customer | |
| { | |
| private int $id; | |
| private string $name; | |
| private string $status; | |
| public function __construct(int $id, string $name, string $status) | |
| { | |
| $this->id = $id; | |
| $this->name = $name; | |
| $this->status = $status; | |
| } | |
| public function getId(): int | |
| { | |
| return $this->id; | |
| } | |
| public function getName(): string | |
| { | |
| return $this->name; | |
| } | |
| public function getStatus(): string | |
| { | |
| return $this->status; | |
| } | |
| public function setStatus(string $status): void | |
| { | |
| $this->status = $status; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class CustomerService | |
| { | |
| public function addCustomer(string $name): Customer | |
| { | |
| // Create a new customer with the "new" status | |
| $customer = new Customer(1, $name, CustomerStatus::NEW); | |
| // Perform any necessary actions, such as syncing with the website | |
| // Return the newly created customer | |
| return $customer; | |
| } | |
| public function registerOnWebsite(Customer $customer): void | |
| { | |
| // Perform the registration logic on the website | |
| // Update the customer's status to "invited" or "active" based on the registration result | |
| $customer->setStatus(CustomerStatus::ACTIVE); | |
| } | |
| public function denyRegistration(Customer $customer): void | |
| { | |
| // Deny the registration on the website | |
| // Update the customer's status to "denied" | |
| $customer->setStatus(CustomerStatus::DENIED); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class CustomerStatus | |
| { | |
| public const NEW = 'new'; | |
| public const INVITED = 'invited'; | |
| public const ACTIVE = 'active'; | |
| public const DENIED = 'denied'; | |
| public const DEACTIVATED = 'deactivated'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Example usage | |
| $customerService = new CustomerService(); | |
| // Add a new customer | |
| $customer = $customerService->addCustomer('John Doe'); | |
| echo "New customer added: {$customer->getName()} ({$customer->getStatus()})\n"; | |
| // Simulate registration on the website | |
| $customerService->registerOnWebsite($customer); | |
| echo "Customer registered on the website: {$customer->getName()} ({$customer->getStatus()})\n"; | |
| // Deny the registration | |
| $customerService->denyRegistration($customer); | |
| echo "Customer registration denied: {$customer->getName()} ({$customer->getStatus()})\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment