Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. private function getRelatedAttribute($name)
  2. {
  3. // $var = $order->CustomerAddressAddress_line_1;
  4. // $var = $order->getCustomer()->getAddress()->address_line_1;
  5.  
  6. $dashSeperated = trim(strtolower(preg_replace('/(?<![A-Z])[A-Z]/', '-\0', $name)), '-');
  7.  
  8. $arr = explode('-', $dashSeperated);
  9.  
  10. $self = $this;
  11. while ($name = array_shift($arr)) {
  12.  
  13. $self = $self->$name;
  14. }
  15. return $self;
  16. }
  17.  
  18. public function __get($name)
  19. {
  20. try {
  21. return parent::__get($name);
  22.  
  23. } catch (\Exception $e) {
  24.  
  25. try {
  26. return $this->getRelatedAttribute($name);
  27. } catch (\Exception $ex ){
  28.  
  29. if (method_exists($this, 'set' . $name)) {
  30. throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
  31. } else {
  32. throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement