background image


 

/** 
* The RealSubject. Always loads the image, even if no dump of the data 
* is required. 
*/

 

class

 RawImage 

extends

 AbstractImage 

public

 

function

 __construct(

$path

$this

->_path = 

$path

list (

$this

->_width, 

$this

->_height) = 

getimagesize

(

$path

); 

$this

->_data = 

file_get_contents

(

$path

); 


 

public

 

function

 dump() 

return

 

$this

->_data; 



 

/** 
* Proxy. Defers loading the image data until it becomes really mandatory. 
* This class does its best to postpone the very expensive operations 
* such as the actual loading of the BLOB. 
*/

 

class

 ImageProxy 

extends

 AbstractImage 

public

 

function

 __construct(

$path

$this

->_path = 

$path

list (

$this

->_width, 

$this

->_height) = 

getimagesize

(

$path

); 


 

/** 
* Creates a RawImage and exploits its functionalities. 
*/

 

protected

 

function

 _lazyLoad() 

if

 (

$this

->_realImage === null) { 

$this

->_realImage = 

new

 RawImage(

$this

->_path);