/** * */ public function testGet() { $arr = ['foo' => '123', 'bar' => ['baz' => '456', 'bax' => ['789']]]; $this->assertEquals('123', Arr::get($arr, 'foo')); $this->assertEquals('456', Arr::get($arr, 'bar.baz')); $this->assertEquals('789', Arr::get($arr, 'bar.bax.0')); $this->assertEquals('abc', Arr::get($arr, 'bar.bax.1', 'abc')); }
/** * Set email blind carbon copy addresses / names * * @access public * @param string $email A unique or array of valid emails addresses * @param string $name (optional) Set a receiver name * @return \carteiro\Mail */ public function bcc($email, $name = null) { if (is_array($email)) { foreach ($email as $address) { // Fix array if (!is_array($address)) { $address = array($address); } // Set convention $this->bcc[] = ['email' => Arr::get($address, 0), 'name' => Arr::get($address, 1)]; } } else { // Set normal $this->bcc[] = ['email' => $email, 'name' => $name]; } return $this; }
/** * Returns the language string. * * @access protected * @param string $key Language key * @param string $language Name of the language pack * @return string */ protected function getString($key, $language) { $language = $language ?? $this->language; list($file, $string) = $this->parseKey($key); if (!isset($this->strings[$language][$file])) { $this->loadStrings($language, $file); } return Arr::get($this->strings[$language][$file], $string, $key); }
/** * Fetch server info. * * @access public * @param string $key Array key * @param mixed $default Default value * @return mixed */ public function server($key = null, $default = null) { return $key === null ? $this->server : Arr::get($this->server, $key, $default); }
/** * Extract parsed views by string or array. * * @access protected * @param mixed $views View parameters * @return array * * @throws \InvalidArgumentException */ protected function extractViews($views) { // Return only html view if (is_string($views)) { return [$views, null, null]; } // If the given view is an array with numeric or associative keys if (is_array($views)) { if (Arr::isAssoc($views)) { // Return only raw body content if (Arr::has($views, 'raw') && Arr::get($views, 'raw')) { return [null, null, Arr::get($views, 'raw')]; } else { // Return associative values in order (html | text | raw) return [Arr::get($views, 'html'), Arr::get($views, 'text'), null]; } } else { // Return numeric values in order (html | text | raw) return [Arr::get($views, 0), Arr::get($views, 1), null]; } } throw new \InvalidArgumentException("Invalid view parameters."); }
/** * Returns config value or entire config array from a file. * * @access public * @param string $key Config key * @param mixed $default Default value to return if config value doesn't exist * @return mixed */ public function get($key, $default = null) { list($file, $path) = $this->parseKey($key); if (!isset($this->configuration[$file])) { $this->load($file); } return $path === null ? $this->configuration[$file] : Arr::get($this->configuration[$file], $path, $default); }