Guest User

Untitled

a guest
Nov 20th, 2017
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * A flexiable alias for Str class
  5. * @author abdumu <hi@abdumu.com>
  6. * @param string $value
  7. * @return mixed|Illuminate\Support\Str
  8. */
  9. function str($value = null)
  10. {
  11. if ($value === null) {
  12. return app('Illuminate\Support\Str');
  13. }
  14.  
  15. return new class($value) {
  16. protected $currentString = '';
  17.  
  18. public function __construct($value = '')
  19. {
  20. $this->currentString = $value;
  21. }
  22.  
  23. public function __call($methodName, $arguments)
  24. {
  25. if (in_array($methodName, ['replaceLast', 'replaceFirst', 'replaceArray', 'is'])) {
  26. array_push($arguments, $this->currentString);
  27. } else {
  28. array_unshift($arguments, $this->currentString);
  29. }
  30.  
  31. $result = call_user_func_array('Illuminate\Support\Str::'.$methodName, $arguments);
  32.  
  33. if (gettype($result) !== 'string') {
  34. return $result;
  35. }
  36.  
  37. $this->currentString = $result;
  38.  
  39. return $this;
  40. }
  41.  
  42. public function get()
  43. {
  44. return $this->currentString;
  45. }
  46.  
  47. public function __toString()
  48. {
  49. return $this->currentString;
  50. }
  51. };
  52. }
Add Comment
Please, Sign In to add comment