Esempio n. 1
0
 /**
  *  Get the configuration by index
  *
  * @param      $key
  * @param bool $value
  * @return mixed|null
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 protected function get($key, $value = false)
 {
     if (is_null($key)) {
         throw new \InvalidArgumentException('Null argument passed to ' . __METHOD__);
     }
     $config = [];
     $config = self::$config;
     if (empty($config)) {
         throw new \Exception('Config stack is empty!');
     }
     if ($value == false && array_key_exists($key, $config)) {
         return isset($config[$key]) ? $config[$key] : null;
     }
     if (array_key_exists($key, $config) && $value == true) {
         return $config[$key][$value];
     }
     /*
     | We will access array value as string with dot separator
     | 'module.config' => [
     |    "config"  => [
     |        "name" => "Welcome To Module"
     |    ]
     | ]
     | Config::get('module-config.config.name');
     */
     return ArrayAccessor::make($config, function ($a) use($key) {
         return $a->toString($key);
     });
 }
Esempio n. 2
0
 public function testHasKey()
 {
     $array = ['foo' => ["bar" => 'Foo Bar']];
     $output = ArrayAccessor::make($array, function ($a) {
         return $a->has('bar');
     });
     $this->assertTrue($output);
 }
Esempio n. 3
0
 /**
  * @param null $key
  * @param null $value
  *
  * @throws \InvalidArgumentException
  *
  * @return bool|null
  */
 public function post($key = null, $value = null)
 {
     if (!is_null($this->except)) {
         $this->skip();
     }
     if (!is_null($key) && !string_has($key, '.') && is_null($value)) {
         $postValue = '';
         $key = $this->security->sanitize($key);
         $postValue = $this->security->sanitize($this->request['post'][$key]);
         $this->request['post'][$key] = $postValue;
         if (array_key_exists($key, $this->request['post'])) {
             return $this->request['post'][$key];
         }
         throw new InvalidArgumentException("Invalid key {$key} passed to " . __METHOD__);
     }
     /*
     | User can access post array element by passing
     | key as dot separator with index
     | ['user' => ['name' => 'foo']]
     |
     | $input->post('user.name'); // output: foo
     */
     if (!is_null($key) && string_has($key, '.') && is_null($value)) {
         $arr = ArrayAccessor::make($this->request['post']);
         return $arr->toString($this->security->sanitize($key));
     }
     $this->setPostValue($key, $value);
     if (is_null($key)) {
         $postArr = $this->security->sanitize($this->request['post']);
         return !empty($postArr) ? $postArr : null;
     }
 }
Esempio n. 4
0
 /**
  * Returns Translator of a string. If no Translator exists, the original
  * string will be returned.
  *
  * trans('Hello, :user', array(':user' => $username));
  * $hello = $trans->get('welcome.Hello friends, my name is :name');
  *
  * @param      $key    to translate
  * @param null $locale target language
  *
  * @return string
  */
 public function get($key, $locale = null)
 {
     if (!$locale) {
         // Use the global target language
         $locale = $this->locale();
     }
     if (string_has($key, ':')) {
         $exp = string_split($key, ':');
         // Load the translation table for this language
         $translator = $this->load($locale . '-' . $exp[0]);
         unset($exp[0]);
         $string = ArrayAccessor::make($translator, function ($a) use($exp) {
             return $a->toString(implode('.', $exp));
         });
         // Return the translated string if it exists
         return !is_null($string) ? $string : $key;
     }
     // Load the Translator array for this language
     $translator = $this->load($locale);
     // Return the translated string if it exists
     return isset($translator[$key]) ? $translator[$key] : $key;
 }