public function getEnvironment($id, Project $project, $refresh = null, $tryMachineName = false)
    {
        // Statically cache not found environments.
        $cacheKey = $project->id . ':' . $id . ($tryMachineName ? ':mn' : '');
        if (!$refresh && isset(self::$notFound[$cacheKey])) {
            return false;
        }

        $environments = $this->getEnvironments($project, $refresh);

        // Look for the environment by ID.
        if (isset($environments[$id])) {
            return $environments[$id];
        }

        // Retry directly if the environment was not found in the cache.
        if ($refresh === null) {
            if ($environment = $project->getEnvironment($id)) {
                // If the environment was found directly, the cache must be out
                // of date.
                $this->clearEnvironmentsCache($project->id);
                return $environment;
            }
        }

        // Look for the environment by machine name.
        if ($tryMachineName) {
            foreach ($environments as $environment) {
                if ($environment->machine_name === $id) {
                    return $environment;
                }
            }
        }

        self::$notFound[$cacheKey] = true;

        return false;
    }
public function getEnvironment($id, Project $project, $refresh = null, $tryMachineName = false)
    {
        // Statically cache not found environments.
        $cacheKey = $project->id . ':' . $id . ($tryMachineName ? ':mn' : '');
        if (!$refresh && isset(self::$notFound[$cacheKey])) {
            return false;
        }

        $environments = $this->getEnvironments($project, $refresh);

        // Look for the environment by ID.
        if (isset($environments[$id])) {
            return $environments[$id];
        }

        // Retry directly if the environment was not found in the cache.
        if ($refresh === null) {
            if ($environment = $project->getEnvironment($id)) {
                // If the environment was found directly, the cache must be out
                // of date.
                $this->clearEnvironmentsCache($project->id);
                return $environment;
            }
        }

        // Look for the environment by machine name.
        if ($tryMachineName) {
            foreach ($environments as $environment) {
                if ($environment->machine_name === $id) {
                    return $environment;
                }
            }
        }

        self::$notFound[$cacheKey] = true;

        return false;
    }
public function getEnvironment ( $ id , Project $ project , $ refresh = null , $ tryMachineName = false ) { // Statically cache not found environments. $ cacheKey = $ project -> id . ':' . $ id . ( $ tryMachineName ? ':mn' : '' ) ; if ( ! $ refresh && isset ( self :: $ notFound [ $ cacheKey ] ) ) { return false ; } $ environments = $ this -> getEnvironments ( $ project , $ refresh ) ; // Look for the environment by ID. if ( isset ( $ environments [ $ id ] ) ) { return $ environments [ $ id ] ; } // Retry directly if the environment was not found in the cache. if ( $ refresh === null ) { if ( $ environment = $ project -> getEnvironment ( $ id ) ) { // If the environment was found directly, the cache must be out // of date. $ this -> clearEnvironmentsCache ( $ project -> id ) ; return $ environment ; } } // Look for the environment by machine name. if ( $ tryMachineName ) { foreach ( $ environments as $ environment ) { if ( $ environment -> machine_name === $ id ) { return $ environment ; } } } self :: $ notFound [ $ cacheKey ] = true ; return false ; }
Get a single environment.

@param string  $id          The environment ID to load.
@param Project $project     The project.
@param bool|null $refresh   Whether to refresh the list of environments.
@param bool $tryMachineName Whether to retry, treating the ID as a
machine name.

@return Environment|false The environment, or false if not found.
Get a single environment .