本文整理汇总了PHP中Environment类的典型用法代码示例。如果您正苦于以下问题:PHP Environment类的具体用法?PHP Environment怎么用?PHP Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDirectory
public static function createDirectory($original_path, $type, Environment $environment)
{
$paths = pathinfo($original_path);
$dirname = realpath($paths['dirname']);
if (!$dirname || !is_dir($dirname) || !is_readable($dirname)) {
if (@mkdir($original_path, 0777, true) === true) {
$realpath = $original_path;
} else {
return $environment->set_error(ucfirst($type) . " parent path '{$paths['dirname']}' does not exist. Please correct the path or create the directory.");
}
}
$path = $dirname . '/' . $paths['basename'];
$realpath = realpath($path);
if ($realpath === false || !file_exists($realpath)) {
if (@mkdir($path, 0777, true) === true) {
$realpath = $path;
} else {
return $environment->set_error("Unable to create directory '{$path}'. Please make the directory manually or check the permissions of the parent directory.");
}
} elseif (!is_readable($realpath) || !is_writable($realpath)) {
@chmod($realpath, 0777);
}
if (substr($realpath, -1) != '/') {
$realpath .= '/';
}
if (is_dir($realpath) && is_readable($realpath) && is_writable($realpath)) {
return $realpath;
} else {
return $environment->set_error("Path to directory for {$type} is not valid. Please correct the path or create the directory and check that is readable and writable.");
}
}
示例2: setDefaultEnv
public function setDefaultEnv($environment)
{
$env = new Environment();
if (is_object($env->add($environment))) {
$this->currentEnviroment = $environment;
}
}
示例3: changeEnvironmentRole
/**
* Change the user's environment-level role.
*
* @param Environment $environment
* @param string $newRole The new role ('admin', 'contributor',
* or 'viewer').
*/
public function changeEnvironmentRole(Environment $environment, $newRole)
{
if (!in_array($newRole, ['admin', 'contributor', 'viewer'])) {
throw new \InvalidArgumentException("Invalid role: {$newRole}");
}
$this->sendRequest($environment->getUri() . '/access/' . $this->id, 'patch', ['json' => ['role' => $newRole]]);
}
示例4: testGet
public function testGet()
{
$get = array('n' => 'v');
$env = new Environment($get, array(), array());
$this->assertEquals('v', $env->get('n'));
$this->assertNull($env->get('not-existed-param'));
}
示例5: getAssetsOutput
/**
* Proxy method that handles return of assets instead of instant output.
*
* @param Environment $env
* @param string $method
* @param string|null $options Assets CollectionName
* @return string
*/
protected function getAssetsOutput(Environment $env, $method, $options = null)
{
$env->getDi()->get('assets')->useImplicitOutput(false);
$result = $env->getDi()->get('assets')->{$method}($options);
$env->getDi()->get('assets')->useImplicitOutput(true);
return $result;
}
示例6: setEnvironment
function setEnvironment(Environment $env)
{
$this->environment = $env;
$env->setLoader($this);
Controller::setEnvironment($env);
return $this;
}
示例7: testUsesEnvironmentVariables
/**
* Test that the parser gets its values from the $_SERVER and $_ENV environment variables
*/
public function testUsesEnvironmentVariables()
{
$_SERVER['foo'] = 'bar';
$_ENV['test'] = 'example';
$configuration = $this->parser->parse();
$this->assertArrayHasKey('foo', $configuration);
$this->assertArrayHasKey('test', $configuration);
}
示例8: saveCachedEnvironmentObject
public static function saveCachedEnvironmentObject()
{
if (!file_exists(DIR_FILES_CACHE . '/' . FILENAME_ENVIRONMENT_CACHE)) {
$env = new Environment();
$env->getOverrides();
@file_put_contents(DIR_FILES_CACHE . '/' . FILENAME_ENVIRONMENT_CACHE, serialize($env));
}
}
示例9: init
static function init($ApiKey, Environment $env)
{
if ($env->getBaseUrl() != Environment::PROD and $env->getBaseUrl() != Environment::TEST and $env->getBaseUrl() != Environment::DEV) {
throw new \InvalidArgumentException('$env must be Apruve\\Environment::PROD or Apruve\\Environment::TEST to be valid.');
}
ClientStorage::setEnvironment($env);
ClientStorage::setApiKey($ApiKey);
return new Client();
}
示例10: register
public function register(Environment $environment)
{
$env = $environment->getEnv();
foreach ($env['packages'] as $k => $e) {
if ($k !== "Syph") {
$this->app_container_config[$k] = array("app_path_conf" => $e . DS . "Config" . DS . "config.php");
}
}
}
示例11: createFromEnvironment
/**
* Create a normalized tree of UploadedFile instances from the Environment.
*
* @param Environment $env The environment
*
* @return array|null A normalized tree of UploadedFile instances or null if none are provided.
*/
public static function createFromEnvironment(Environment $env)
{
if (is_array($env['slim.files']) && $env->has('slim.files')) {
return $env['slim.files'];
} elseif (isset($_FILES)) {
return static::parseUploadedFiles($_FILES);
}
return [];
}
示例12: testModuleActivation
/**
* Tests if module was activated.
*
* @dataProvider providerModuleActivation
*
* @param array $aInstallModules
* @param string $sModule
* @param array $aResultToAsserts
*/
public function testModuleActivation($aInstallModules, $sModule, $aResultToAsserts)
{
$oEnvironment = new Environment();
$oEnvironment->prepare($aInstallModules);
$oModule = oxNew('oxModule');
$oModule->load($sModule);
$this->deactivateModule($oModule);
$this->activateModule($oModule);
$this->runAsserts($aResultToAsserts);
}
示例13: checkConnectionMode
/**
* Checks the site's mode and suggests SFTP if it is not set.
*
* @param Environment $environment Environment object to check mode of
* @return void
*/
protected function checkConnectionMode($environment)
{
if ($environment->getConnectionMode() != 'sftp') {
$message = 'Note: This environment is in read-only Git mode. If you ';
$message .= 'want to make changes to the codebase of this site ';
$message .= '(e.g. updating modules or plugins), you will need to ';
$message .= 'toggle into read/write SFTP mode first.';
$this->log()->warning($message);
}
}
示例14: testModulesWithoutMetadataShouldBeAddToCleanupAllModulesWithMetadata
public function testModulesWithoutMetadataShouldBeAddToCleanupAllModulesWithMetadata()
{
// modules to be activated during test preparation
$aInstallModules = array('extending_1_class');
$oEnvironment = new Environment();
$oEnvironment->prepare($aInstallModules);
$oModuleList = oxNew('oxModuleList');
$aGarbage = $oModuleList->getDeletedExtensions();
$this->assertSame(array(), $aGarbage);
}
示例15: run
/**
* {@inheritdoc}
*
* @throws \Icicle\File\Exception\FileException
* @throws \Icicle\Exception\InvalidArgumentError
*/
public function run(Environment $environment)
{
if ('f' === $this->operation[0]) {
if ('fopen' === $this->operation) {
$file = new File($this->args[0], $this->args[1]);
$id = $file->getId();
$environment->set($this->makeId($id), $file);
return [$id, $file->stat()['size'], $file->inAppendMode()];
}
if (null === $this->id) {
throw new FileException('No file ID provided.');
}
if (!$environment->exists($this->id)) {
throw new FileException('No file handle with the given ID has been opened on the worker.');
}
if (!($file = $environment->get($this->id)) instanceof File) {
throw new FileException('File storage found in inconsistent state.');
}
switch ($this->operation) {
case 'fread':
case 'fwrite':
case 'fseek':
case 'fstat':
case 'ftruncate':
return [$file, substr($this->operation, 1)](...$this->args);
case 'fclose':
$environment->delete($this->id);
return true;
default:
throw new InvalidArgumentError('Invalid operation.');
}
}
switch ($this->operation) {
case 'stat':
case 'unlink':
case 'rename':
case 'copy':
case 'link':
case 'symlink':
case 'readlink':
case 'isfile':
case 'isdir':
case 'mkdir':
case 'lsdir':
case 'rmdir':
case 'chmod':
case 'chown':
case 'chgrp':
return [$this, $this->operation](...$this->args);
default:
throw new InvalidArgumentError('Invalid operation.');
}
}