Advertisement
Berger92

Phalcon Setter Injection

Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  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 { ... }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement