Esempio n. 1
0
 public function testContainsItems()
 {
     $items = ['name' => 'Jim', 'age' => 79, 'sex' => 'M', 'country' => 'N/A'];
     $this->assertTrue(ArrayUtils::contains($items, ['name', 'age']));
     $this->assertFalse(ArrayUtils::contains($items, ['name', 'age', 'city']));
     $this->assertTrue(ArrayUtils::contains($items, 'name', 'age'));
 }
Esempio n. 2
0
 /**
  * Create a config and configuration file into $path
  * @param $data
  * @param $path
  */
 public static function createConfig($data, $path)
 {
     $requiredAttributes = ['db_host', 'db_name', 'db_user', 'db_password', 'directus_path'];
     if (!ArrayUtils::contains($data, $requiredAttributes)) {
         $message = sprintf(__t('creating_config_files_required_x', ['attributes' => implode(', ', $requiredAttributes)]));
         throw new \InvalidArgumentException($message);
     }
     static::createConfigFile($data, $path);
     static::createConfigurationFile($data, $path);
 }
Esempio n. 3
0
 /**
  * Check if a user is logged in.
  * @return boolean
  */
 public static function loggedIn()
 {
     if (self::$authenticated != null) {
         return self::$authenticated;
     }
     self::prependSessionKey();
     if (php_sapi_name() != 'cli' && '' === session_id()) {
         session_start();
     }
     self::$authenticated = $isLoggedIn = false;
     $ZendDb = Bootstrap::get('ZendDb');
     $session = [];
     if (isset($_SESSION[self::$SESSION_KEY]) && !empty($_SESSION[self::$SESSION_KEY])) {
         $session = $_SESSION[self::$SESSION_KEY];
     }
     if (is_array($session) && ArrayUtils::contains($session, ['id', 'access_token'])) {
         $DirectusUsersTableGateway = new \Zend\Db\TableGateway\TableGateway('directus_users', $ZendDb);
         $user = $DirectusUsersTableGateway->select(['id' => $session['id'], 'access_token' => $session['access_token']]);
         if ($user->count()) {
             self::$authenticated = $isLoggedIn = true;
         }
     }
     return $isLoggedIn;
 }