Overview

Namespaces

  • Deimos
    • Helper
      • Exceptions
      • Helpers
        • Arr
        • Str
      • Traits
  • PHP

Classes

  • Deimos\Helper\AbstractHelper
  • Deimos\Helper\Helper
  • Deimos\Helper\Helpers\Arr\Arr
  • Deimos\Helper\Helpers\Dir
  • Deimos\Helper\Helpers\File
  • Deimos\Helper\Helpers\Json
  • Deimos\Helper\Helpers\Math
  • Deimos\Helper\Helpers\Money
  • Deimos\Helper\Helpers\Str\Str

Interfaces

  • Deimos\Helper\InterfaceHelper
  • Throwable

Traits

  • Deimos\Helper\Helpers\Arr\KeyTrait
  • Deimos\Helper\Helpers\Arr\StackTrait
  • Deimos\Helper\Helpers\Str\DefaultTrait
  • Deimos\Helper\Traits\Helper

Exceptions

  • Deimos\Helper\Exceptions\ExceptionEmpty
  • Exception
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: namespace Deimos\Helper\Helpers\Arr;
  4: 
  5: use Deimos\Helper\Exceptions\ExceptionEmpty;
  6: 
  7: trait StackTrait
  8: {
  9: 
 10:     /**
 11:      * @param array $storage
 12:      * @param       $mixed
 13:      *
 14:      * @return mixed
 15:      */
 16:     public function push(array &$storage, $mixed)
 17:     {
 18:         return array_push($storage, $mixed);
 19:     }
 20: 
 21:     /**
 22:      * @param array $storage
 23:      *
 24:      * @return mixed
 25:      */
 26:     public function pop(array &$storage)
 27:     {
 28:         return array_pop($storage);
 29:     }
 30: 
 31:     /**
 32:      * @param array $storage
 33:      *
 34:      * @return mixed
 35:      */
 36:     public function shift(array &$storage)
 37:     {
 38:         return array_shift($storage);
 39:     }
 40: 
 41:     /**
 42:      * @param array $storage
 43:      * @param       $mixed
 44:      *
 45:      * @return mixed
 46:      */
 47:     public function unShift(array &$storage, $mixed)
 48:     {
 49:         return array_unshift($storage, $mixed);
 50:     }
 51: 
 52:     /**
 53:      * @param array $storage
 54:      *
 55:      * @return mixed
 56:      */
 57:     public function first(array $storage)
 58:     {
 59:         reset($storage);
 60: 
 61:         return current($storage);
 62:     }
 63: 
 64:     /**
 65:      * @param array $storage
 66:      *
 67:      * @return mixed
 68:      */
 69:     public function last(array $storage)
 70:     {
 71:         return end($storage);
 72:     }
 73: 
 74:     /**
 75:      * 1, 3, 5...
 76:      *
 77:      * @param array $storage
 78:      *
 79:      * @return array
 80:      */
 81:     public function odd(array $storage)
 82:     {
 83:         return $this->filter($storage, function ($value)
 84:         {
 85:             return $this->helper->math()->isOdd($value);
 86:         });
 87:     }
 88: 
 89:     /**
 90:      * 0, 2, 4...
 91:      *
 92:      * @param array $storage
 93:      *
 94:      * @return array
 95:      */
 96:     public function even(array $storage)
 97:     {
 98:         return $this->filter($storage, function ($value)
 99:         {
100:             return $this->helper->math()->isEven($value);
101:         });
102:     }
103: 
104:     /**
105:      * @param array  $storage
106:      * @param string $key
107:      * @param mixed  $default
108:      *
109:      * @return mixed
110:      */
111:     public function get(array $storage, $key, $default = null)
112:     {
113:         try
114:         {
115:             return $this->findPath($storage, $this->keys($key));
116:         }
117:         catch (ExceptionEmpty $empty)
118:         {
119:             return $default;
120:         }
121:     }
122: 
123:     /**
124:      * @param array  $storage
125:      * @param string $key
126:      * @param mixed  $value
127:      */
128:     public function initOrPush(array &$storage, $key, $value)
129:     {
130:         if (empty($storage[$key]))
131:         {
132:             $storage[$key] = [];
133:         }
134: 
135:         $storage[$key][] = $value;
136:     }
137: 
138: }
139: 
API documentation generated by ApiGen