Skip to content

Instantly share code, notes, and snippets.

@MacDada
Created November 20, 2012 16:05
Show Gist options
  • Save MacDada/4118834 to your computer and use it in GitHub Desktop.
Save MacDada/4118834 to your computer and use it in GitHub Desktop.
Best way to have custom methods for vendor classes
<?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);
}
}
<?php
namespace MyStuff\Imagick;
/**
* Option 2: ImagickHelper with custom static methods
*/
class ImagickHelper
{
public static function customMethod(\Imagick $imagick, $param)
{
$imagick->doSomething($param);
}
}
<?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