Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving a class to a local package and registering it as a new service
- Loading branch information
Grigori Kochanov
committed
Dec 6, 2020
1 parent
4cfba01
commit de797ef
Showing
8 changed files
with
103 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
{ | |||
"name": "acme/image", | |||
"description": "a demo module for splitting a monolith application", | |||
"license": "proprietary", | |||
"version": "0.1", | |||
"authors": [ | |||
{ | |||
"name": "Grigori", | |||
"email": "public@grik.net" | |||
} | |||
], | |||
"require": { | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Acme\\Image\\": "src/" | |||
} | |||
} | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
<?php | |||
|
|||
|
|||
namespace Acme\Image\Contracts; | |||
|
|||
/** | |||
* Interface ImageInterface | |||
* @package Acme\Image | |||
*/ | |||
interface ImageInterface | |||
{ | |||
public function load(string $tmp_name): mixed; | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
<?php | |||
declare(strict_types=1); | |||
|
|||
namespace Acme\Image; | |||
|
|||
use Acme\Image\Contracts\ImageInterface; | |||
use Acme\Image\lib\Image; | |||
|
|||
/** | |||
* Class ImageService provides an API for the application. | |||
* It is a bridge registered as a service assisting decoupling the module | |||
* to change it independently from the service API. | |||
* | |||
* @package Acme\Image | |||
* @api | |||
*/ | |||
class ImageService implements ImageInterface | |||
{ | |||
|
|||
/** | |||
* @var Image | |||
*/ | |||
private Image $imageLib; | |||
|
|||
public function __construct() | |||
{ | |||
$this->imageLib = new Image(); | |||
} | |||
|
|||
/** | |||
* @param string $tmp_name | |||
*/ | |||
public function load(string $tmp_name): mixed | |||
{ | |||
return $this->imageLib->load($tmp_name); | |||
} | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
<?php | |||
|
|||
namespace Acme\Image\lib; | |||
|
|||
/** | |||
* This class can now be changed without breaking the application | |||
* because API is fixed in the ImageService class | |||
* | |||
* @internal | |||
* @package Acme\Image | |||
*/ | |||
class Image extends \BaseModel | |||
{ | |||
public function load($tmp_name) | |||
{ | |||
// calls to inherited methods | |||
$this->foo(); | |||
parent::bar(); | |||
} | |||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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