has() public method

public has ( string $name, boolean $notNull = true ) : boolean
$name string
$notNull boolean
return boolean
Example #1
0
 /**
  * Constructor.
  *
  * @param CliConfig|null                $config
  * @param EventDispatcherInterface|null $dispatcher
  */
 public function __construct(CliConfig $config = null, EventDispatcherInterface $dispatcher = null)
 {
     $this->config = $config ?: new CliConfig();
     $this->dispatcher = $dispatcher;
     self::$sessionId = $this->config->get('api.session_id') ?: 'default';
     if (self::$sessionId === 'api-token') {
         throw new \InvalidArgumentException('Invalid session ID: ' . self::$sessionId);
     }
     if (!isset(self::$apiToken)) {
         // Exchangeable API tokens: a token which is exchanged for a
         // temporary access token.
         if ($this->config->has('api.token_file')) {
             self::$apiToken = $this->loadTokenFromFile($this->config->get('api.token_file'));
             self::$apiTokenType = 'exchange';
             self::$sessionId = 'api-token';
         } elseif ($this->config->has('api.token')) {
             self::$apiToken = $this->config->get('api.token');
             self::$apiTokenType = 'exchange';
             self::$sessionId = 'api-token';
         } elseif ($this->config->has('api.access_token_file')) {
             self::$apiToken = $this->loadTokenFromFile($this->config->get('api.access_token_file'));
             self::$apiTokenType = 'access';
         } elseif ($this->config->has('api.access_token')) {
             self::$apiToken = $this->config->get('api.access_token');
             self::$apiTokenType = 'access';
         }
     }
     $this->setUpCache();
 }
 /**
  * Get the full path to the Drush executable.
  *
  * @return string
  *   The absolute path to the executable, or 'drush' if the path is not
  *   known.
  */
 protected function getDrushExecutable()
 {
     if ($this->config->has('local.drush_executable')) {
         return $this->config->get('local.drush_executable');
     }
     return $this->shellHelper->resolveCommand('drush');
 }
 /**
  * Test that selected user config can override initial config.
  */
 public function testUserConfigOverrides()
 {
     $config = new CliConfig([], __DIR__ . '/data/mock-cli-config.yaml', true);
     $this->assertFalse($config->has('experimental.test'));
     $home = getenv('HOME');
     putenv('HOME=' . __DIR__ . '/data');
     $config = new CliConfig([], __DIR__ . '/data/mock-cli-config.yaml', true);
     putenv('HOME=' . $home);
     $this->assertTrue($config->has('experimental.test'));
     $this->assertTrue($config->get('experimental.test'));
     $this->assertNotEquals($config->get('application.name'), 'Attempted override');
 }