Created
November 20, 2012 16:05
-
-
Save MacDada/4118834 to your computer and use it in GitHub Desktop.
Best way to have custom methods for vendor classes
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
<?php | |
namespace MyStuff\Imagick; | |
/** | |
* Option 1: My Imagick extending the original one with custom methods | |
*/ | |
class Imagick extends \Imagick | |
{ | |
public function customMethod($param) | |
{ | |
$this->doSomething($param); | |
} | |
} |
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
<?php | |
namespace MyStuff\Imagick; | |
/** | |
* Option 2: ImagickHelper with custom static methods | |
*/ | |
class ImagickHelper | |
{ | |
public static function customMethod(\Imagick $imagick, $param) | |
{ | |
$imagick->doSomething($param); | |
} | |
} |
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
<?php | |
namespace MyStuff\Imagick; | |
/** | |
* Option 3: ImagickHelper with custom methods | |
*/ | |
class ImagickHelper | |
{ | |
$this->$imagick; | |
public function __construct(\Imagick $imagick) | |
{ | |
$this->imagick = $imagick; | |
} | |
public function customMethod($param) | |
{ | |
$this->imagick->doSomething($param); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment