SHARE
TWEET

Phalcon Setter Injection

Berger92 Nov 22nd, 2017 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.php:
  2. $di->set('ImgStorage',
  3.     [
  4.         'className' => 'Gallery\Classes\AmazonS3'
  5.     ]
  6. );
  7.  
  8. $di->set('AbstractController',
  9.     [
  10.         'className' => 'AbstractController',
  11.         'calls' => [
  12.             [
  13.                 'method'    => 'setStorage',
  14.                 'arguments' => [
  15.                     [
  16.                         'type'  => 'service',
  17.                         'name'  => 'ImgStorage'
  18.                     ]
  19.                 ]
  20.             ]
  21.         ]
  22.     ]
  23. );
  24.  
  25.  
  26. // AbstractController.php:
  27. abstract class AbstractController extends Controller {
  28.  
  29.     protected $storage;
  30.  
  31.     public function setStorage(ImgStorage $storage) {
  32.  
  33.         $this->storage = $storage;
  34.     }
  35.  
  36.     // ...
  37. }
  38.  
  39. // Other controllers
  40. class AlbumsController extends AbstractController { ... }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top