Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <?php
  2. class Name{
  3. protected $first ;
  4. public function setNameType($value) {
  5. $this->first = $value;
  6. }
  7. public function getNameType() {
  8. return $this->first;
  9. }
  10. }
  11.  
  12. $name = new Name;
  13. $name->setNameType("My Name");
  14. echo $name->getNameType();
  15. ?>
  16.  
  17. <?php
  18. class Name{
  19. protected $first ;
  20. public function __construct($value) {
  21. $this->first = $value;
  22. }
  23. public function getNameType() {
  24. return $this->first;
  25. }
  26. }
  27.  
  28. $name = new Name("My Name");
  29. echo $name->getNameType();
  30. ?>
  31.  
  32. class Book {
  33.  
  34. public function __construct() {
  35.  
  36. $registry = RegistrySingleton::getInstance();
  37. $this->_database = $registry->database;
  38.  
  39. // or
  40.  
  41. global $databaseConnection;
  42. $this->_database = $database;
  43. }
  44.  
  45. }
  46.  
  47. class Book {
  48.  
  49. private $_databaseConnection;
  50.  
  51. public function __construct() { }
  52.  
  53. public function setDatabaseConnection($databaseConnection) {
  54. $this->_databaseConnection = $databaseConnection;
  55. }
  56.  
  57. }
  58.  
  59. $book = new Book();
  60. $book->setDatabase($databaseConnection);
  61.  
  62. $book = new Book($databaseConnection, $configFile);
  63.  
  64. $book = new Book();
  65. $book->setDatabase($databaseConnection);
  66. $book->setConfigFile($configFile);
  67.  
  68. class Container {
  69.  
  70. public static $_database;
  71.  
  72. public static function makeBook() {
  73.  
  74. $book = new Book();
  75. $book->setDatabase(self::$_database);
  76. // more injection...
  77.  
  78. return $book;
  79. }
  80.  
  81. }
  82.  
  83. $book = Container::makeBook();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement