Example #1
0
 /**
  * @param string    $name       $_FILES内のフィールド名
  * @return Upload
  */
 public static function get($name)
 {
     $file = Arr::get($_FILES, $name);
     if (!self::validFile($file)) {
         return;
     }
     return new self($file);
 }
Example #2
0
 private function executeHandler()
 {
     $method = Input::method();
     $handler = Arr::get($this->handlers, $method);
     $response = null;
     if (is_callable($handler)) {
         $response = $handler();
     } else {
         $handler = $this->unsupportedHandler;
         if (is_callable($handler)) {
             $response = $this->unsupportedHandler();
         }
     }
     if (!empty($response)) {
         return $this->processResponse($response);
     }
 }
Example #3
0
 /**
  * 指定した接続のコネクションインスタンスを取得します。
  *
  * 既存のコネクション、もしくは接続設定ファイルからコネクションを生成します。<br>
  * <br>
  * 接続設定は config/db.phpの設定を参照します。<br>
  * Configクラスを利用して、"db"名前空間に接続設定を読み込んでください。<br>
  *
  * @param string|null $connectionName (オプション) 取得する接続名
  * @throws OutOfBoundsException
  *      dbconfig.phpに記述されていないコネクション名が指定された時にスローされます。
  */
 public static function instance($connectionName = null)
 {
     !is_string($connectionName) and $connectionName = self::DEFAULT_CONNECTION_NAME;
     if (array_key_exists($connectionName, self::$_connections)) {
         return self::$_connections[$connectionName];
     }
     $config = Config::get('db', array());
     if (array_key_exists($connectionName, $config) === false) {
         // 接続設定に指定されたコネクション用の設定がなければ、例外を投げる
         throw new OutOfBoundsException('定義されていないコネクションが要求されました。(接続名: ' . $connectionName . ')');
     }
     // 新しいコネクションを生成する
     $conf = $config[$connectionName];
     if ($conf === null) {
         throw new OutOfBoundsException('定義されていないコネクションが要求されました。(接続名: ' . $connectionName . ')');
     }
     $host = Arr::get($conf, 'host');
     $user = Arr::get($conf, 'user');
     $pass = Arr::get($conf, 'password');
     $dbname = Arr::get($conf, 'database');
     $charset = Arr::get($conf, 'charset');
     $con = self::connect($host, $user, $pass, false, $connectionName);
     !empty($dbname) and $con->useDB($dbname);
     !empty($charset) and $con->setCharset($charset);
     return $con;
 }
Example #4
0
 /**
  * $_SERVER変数の値を取得します。
  *
  * @param string|null $key (optional) 取得する属性名
  * @param mixed|null $default (optional)パラメータが存在しない時のデフォルト値
  * @return mixed
  */
 public static function server($key = null, $default = null)
 {
     return Arr::get($_SERVER, $key, $default);
 }
Example #5
0
 /**
  * フィールドに対する検証ルールを設定します。
  * @param string    $fieldName      検証するフィールド名
  * @param array     $rules          検証ルールのリスト
  * @return $this
  */
 public function rule($fieldName, array $rules)
 {
     $fieldLabelPair = explode(':', $fieldName, 2);
     $field = $fieldLabelPair[0];
     $label = Arr::get($fieldLabelPair, '1', $field);
     $this->fieldSet[$field] = ['label' => $label, 'rules' => $rules];
     return $this;
 }
Example #6
0
 /**
  * @covers \CodeLapse\Arr::except
  * @dataProvider provider_personInfo
  */
 public function testExcept($person)
 {
     $original = $person;
     // Simple except
     $excepted1 = Arr::except($person, 'location');
     $this->assertFalse(array_key_exists('location', $excepted1), 'Arr::except 1');
     // Deep except
     $excepted2 = Arr::except($person, 'location.country');
     $this->assertTrue(array_key_exists('location', $excepted2), 'Arr::except 2-1');
     $this->assertFalse(array_key_exists('country', $excepted2['location']), 'Arr::except 2-2');
     // Multiple simple & deep except
     $excepted3 = Arr::except($person, ['tags', 'location.country']);
     $this->assertFalse(array_key_exists('tags', $excepted3), 'Arr::except 3-1');
     $this->assertTrue(array_key_exists('location', $excepted3), 'Arr::except 3-2');
     $this->assertFalse(array_key_exists('country', $excepted3['location']), 'Arr::except 3-3');
     // Check non-destructive except
     $this->assertEmpty(Arr::diffRecursive($original, $person), 'ARR::except 4');
 }
Example #7
0
 /**
  * $array1の中で$array2の中に含まれない要素を返します。
  */
 public static function diffRecursive(array $array1, array $array2)
 {
     // Thanks: http://stackoverflow.com/questions/3876435/recursive-array-diff
     $diff = array();
     foreach ($array1 as $key => $value) {
         // key unmatched but a value in array, it's not diff.
         if (array_key_exists($key, $array2) === false) {
             if (in_array($value, $array2, true)) {
                 continue;
             }
             // key unmatch and value not in array, it's diff.
             $diff[$key] = $value;
             continue;
         }
         // match key and value then not diff
         if ($value === $array2[$key]) {
             continue;
         }
         if (is_array($value)) {
             if (is_array($array2[$key])) {
                 $arrayDiff = Arr::diffRecursive($value, $array2[$key]);
                 if (count($arrayDiff) !== 0) {
                     $diff[$key] = $arrayDiff;
                 }
             }
             continue;
         }
         $diff[$key] = $value;
     }
     return $diff;
 }