Guest User

Untitled

a guest
Apr 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. class Base
  4. {
  5. protected $_availableSizes = array();
  6.  
  7. public function __call($name, $args)
  8. {
  9. $action = strtolower(substr($name, 0, 3));
  10. $field = '_' . strtolower($name[3]) . substr($name, 4);
  11.  
  12. switch ($action) {
  13. case 'set':
  14. $this->$field = $args[0];
  15. break;
  16.  
  17. case 'get':
  18. return $this->$field;
  19. break;
  20.  
  21. default:
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. class Foo extends Base
  28. {
  29. /**
  30. * Overrides the admin setAvailableSizes to ensure every
  31. * item within the context of an Order has a size and cost.
  32. *
  33. * @return void
  34. **/
  35. public function setAvailableSizes(array $sizes)
  36. {
  37. parent::setAvailableSizes($sizes);
  38. if (empty($this->_availableSizes)) {
  39. $this->_availableSizes[] = array(
  40. 'name' => 'Default',
  41. 'cost' => 0.00,
  42. );
  43. }
  44. }
  45. }
  46.  
  47. $foo = new Foo();
  48. $foo->setAvailableSizes(array(
  49. array(
  50. 'name' => 'Test',
  51. 'cost' => '0.00',
  52. ),
  53. ));
  54.  
  55. var_dump($foo);
Add Comment
Please, Sign In to add comment