本文整理汇总了PHP中chdir函数的典型用法代码示例。如果您正苦于以下问题:PHP chdir函数的具体用法?PHP chdir怎么用?PHP chdir使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chdir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_dnc
public function test_dnc()
{
global $CFG;
if ($CFG->ostype === 'UNIX') {
// Try it the faster way.
$oldcwd = getcwd();
chdir($CFG->dirroot);
$output = null;
$exclude = array();
foreach ($this->extensions_to_ignore as $ext) {
$exclude[] = '--exclude="*.' . $ext . '"';
}
$exclude = implode(' ', $exclude);
exec('grep -r ' . $exclude . ' DONOT' . 'COMMIT .', $output, $code);
chdir($oldcwd);
// Return code 0 means found, return code 1 means NOT found, 127 is grep not found.
if ($code == 1) {
// Executed only if no file failed the test.
$this->assertTrue(true);
return;
}
}
$regexp = '/\\.(' . implode('|', $this->extensions_to_ignore) . ')$/';
$this->badstrings = array();
$this->badstrings['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT';
// If we put the literal string here, it fails the test!
$this->badstrings['trailing whitespace'] = "[\t ][\r\n]";
foreach ($this->badstrings as $description => $ignored) {
$this->allok[$description] = true;
}
$this->recurseFolders($CFG->dirroot, 'search_file_for_dnc', $regexp, true);
$this->assertTrue(true);
// Executed only if no file failed the test.
}
示例2: execute
/**
* Executes Composer and runs a specified command (e.g. install / update)
*/
public function execute()
{
$path = $this->phpci->buildPath;
$build = $this->build;
if ($this->directory == $path) {
return false;
}
$filename = str_replace('%build.commit%', $build->getCommitId(), $this->filename);
$filename = str_replace('%build.id%', $build->getId(), $filename);
$filename = str_replace('%build.branch%', $build->getBranch(), $filename);
$filename = str_replace('%project.title%', $build->getProject()->getTitle(), $filename);
$filename = str_replace('%date%', date('Y-m-d'), $filename);
$filename = str_replace('%time%', date('Hi'), $filename);
$filename = preg_replace('/([^a-zA-Z0-9_-]+)/', '', $filename);
$curdir = getcwd();
chdir($this->phpci->buildPath);
if (!is_array($this->format)) {
$this->format = array($this->format);
}
foreach ($this->format as $format) {
switch ($format) {
case 'tar':
$cmd = 'tar cfz "%s/%s.tar.gz" ./*';
break;
default:
case 'zip':
$cmd = 'zip -rq "%s/%s.zip" ./*';
break;
}
$success = $this->phpci->executeCommand($cmd, $this->directory, $filename);
}
chdir($curdir);
return $success;
}
示例3: invokeService
public function invokeService($source, $method, $data)
{
// locate source file
$classFile = str_replace('.', '/', $source) . '.php';
try {
// All class paths will be relative to baseClassPath
$dirname = realpath("./" . $this->baseClassPath);
if (is_dir($dirname)) {
chdir($dirname);
} else {
throw new Flex_BasepathNotFoundException($this->baseClassPath);
}
// Check to see if the source class it exists
if (!file_exists($classFile)) {
throw new SabreAMF_ClassNotFoundException($source);
}
$includeFlag = @(include_once $classFile);
$lastPeriod = strrpos($source, ".");
if ($lastPeriod > 0) {
$lastPeriod++;
}
$className = substr($source, $lastPeriod, strlen($source) - $lastPeriod);
//Check if class exists
if (!class_exists($className)) {
throw new SabreAMF_ClassNotFoundException($source);
}
$serviceInstance = new $className();
} catch (Exception $e) {
throw new SabreAMF_ClassNotFoundException($e->getMessage());
}
if (!method_exists($serviceInstance, $method)) {
throw new SabreAMF_UndefinedMethodException($source, $method);
}
return call_user_func_array(array($serviceInstance, $method), $data);
}
示例4: run
public function run($path = '.')
{
chdir($path);
$command = $this->phpspec . ' ' . $this->phpspec_options;
exec($command, $return, $status);
if ($status != 0) {
$this->expiration_in_secs = 5;
$this->notify("Error running test", $return[1], $this->fail_image);
} else {
$output = join("\n", $return);
echo $output;
foreach ($return as $line) {
if (preg_match('/^([0-9]+) example/', $line, $matches)) {
$examples = $matches[1];
preg_match('/([0-9]+) failure/', $line, $matches);
$failures = $matches[1];
preg_match('/([0-9]+) pending/', $line, $matches);
$pendings = $matches[1];
}
}
if ($failures > 0) {
$this->notify("Tests Failed", $failures . "/" . $examples . ($failures == 1 ? " test failed" : " tests failed"), $this->fail_image);
} elseif ($pendings > 0) {
$this->notify("Tests Pending", $pendings . "/" . $examples . ($pendings == 1 ? " test is pending" : " tests are pending"), $this->pending_image);
} else {
$this->notify("Tests Passed", "All " . $examples . " tests passed", $this->success_image);
}
}
}
示例5: its_preLoad_throws_when_configuration_file_not_exists
function its_preLoad_throws_when_configuration_file_not_exists(GenericEvent $event, ContainerInterface $container, PhpGuard $guard)
{
chdir(static::$tmpDir);
$container->get('phpguard')->willReturn($guard);
$guard->setOptions(array())->shouldBeCalled();
$this->shouldThrow('InvalidArgumentException')->duringPreLoad($event);
}
示例6: init
/**
* Initializes git, makes tmp folders writeable, and adds the core submodules (or specified group)
*
* @return void
*/
public function init($working)
{
$this->out(__d('baking_plate', "\n<info>Making temp folders writeable...</info>"));
$tmp = array('tmp' . DS . 'cache', 'tmp' . DS . 'cache' . DS . 'models', 'tmp' . DS . 'cache' . DS . 'persistent', 'tmp' . DS . 'cache' . DS . 'views', 'tmp' . DS . 'logs', 'tmp' . DS . 'sessions', 'tmp' . DS . 'tests', 'webroot' . DS . 'ccss', 'webroot' . DS . 'cjs', 'webroot' . DS . 'uploads');
foreach ($tmp as $dir) {
if (!is_dir($working . DS . $dir)) {
$this->out(__d('baking_plate', "\n<info>Creating Directory %s with permissions 0777</info>", $dir));
mkdir($working . DS . $dir, 0777);
} else {
$this->out(__d('baking_plate', "\n<info>Setting Permissions of %s to 0777</info>", $dir));
chmod($working . DS . $dir, 0777);
}
}
$this->nl();
chdir($working);
$this->out();
$this->out(passthru('git init'));
$this->all();
$this->args = null;
if (!file_exists($working . 'Config' . DS . 'database.php')) {
$this->DbConfig->path = $working . 'Config' . DS;
$this->out();
$this->out(__d('baking_plate', '<warning>Your database configuration was not found. Take a moment to create one.</warning>'));
$this->DbConfig->execute();
}
}
示例7: unpack_zip_inner
function unpack_zip_inner($zipfile, $clone) {
global $webDir, $uid;
require_once 'include/lib/fileUploadLib.inc.php';
$zip = new pclZip($zipfile);
if (!$clone) {
validateUploadedZipFile($zip->listContent(), 3);
}
$destdir = $webDir . '/courses/tmpUnzipping/' . $uid;
if (!is_dir($destdir)) {
mkdir($destdir, 0755);
}
chdir($destdir);
$zip->extract();
$retArr = array();
foreach (find_backup_folders($destdir) as $folder) {
$retArr[] = array(
'path' => $folder['path'] . '/' . $folder['dir'],
'file' => $folder['dir'],
'course' => preg_replace('|^.*/|', '', $folder['path'])
);
}
chdir($webDir);
return $retArr;
}
示例8: prepWorkingDirectory
/**
* @beforeScenario
*/
public function prepWorkingDirectory()
{
$this->workingDirectory = tempnam(sys_get_temp_dir(), 'phpspec-behat');
$this->filesystem->remove($this->workingDirectory);
$this->filesystem->mkdir($this->workingDirectory);
chdir($this->workingDirectory);
}
示例9: __construct
/**
* The constructor.
*/
public function __construct($rootDir, $cwd = NULL, $initialMode = NULL)
{
//set the root directory that we'll be using; this is considered just like "/" in
// linux. Directories above it are considered non-existent.
if (!is_null($rootDir)) {
parent::__construct(true);
$this->root = ToolBox::resolve_path_with_dots($rootDir);
//set the CURRENT working directory... this should be a RELATIVE path to $this->root.
if (!is_null($cwd) and is_dir($rootDir . '/' . $cwd) and !preg_match('~' . $cwd . '~', $this->root)) {
//looks good. Use it.
$this->cwd = $cwd;
$this->realcwd = $this->root . '/' . $cwd;
} else {
//no dice. Use the root.
$this->cwd = '/';
$this->realcwd = $this->root;
}
$this->realcwd = preg_replace('~/{2,}~', '/', $this->realcwd);
chdir($this->realcwd);
//check for the initialMode...
$useableModes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+');
if ($initialMode and in_array($initialMode, $useableModes)) {
//
$this->mode = $initialMode;
} else {
//define the DEFAULT mode.
$this->mode = "r+";
}
} else {
throw new InvalidArgumentException(__METHOD__ . ": invalid root directory (" . $rootDir . ")");
}
}
示例10: iAmInADirectory
/** @Given /^I am in a directory "([^"]*)"$/ */
public function iAmInADirectory($dir)
{
if (!file_exists($dir)) {
mkdir($dir);
}
chdir($dir);
}
示例11: actionIndex
public function actionIndex()
{
$error = false;
@chdir(Yii::getAlias('@app'));
foreach ($this->folders as $folder => $writable) {
if (!file_exists($folder)) {
$mode = $writable ? 0777 : 0775;
if (FileHelper::createDirectory($folder, $mode)) {
$this->outputSuccess("{$folder}: successfully created directory");
} else {
$error = true;
$this->outputError("{$folder}: unable to create directory");
}
} else {
$this->outputSuccess("{$folder}: directory exists");
}
if ($writable) {
if (!is_writable($folder)) {
$error = true;
$this->outputError("{$folder}: is not writable, please change permissions.");
}
}
}
foreach ($this->files as $file) {
if (file_exists($file)) {
$this->outputSuccess("{$file}: file exists.");
} else {
$error = true;
$this->outputError("{$file}: file does not exists!");
}
}
return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.');
}
示例12: setUp
protected function setUp()
{
$this->tikiroot = dirname(__FILE__) . '/../../../';
$this->lang = 'test_language';
$this->langDir = $this->tikiroot . 'lang/' . $this->lang;
chdir($this->tikiroot);
mkdir($this->langDir);
$this->obj = new LanguageTranslations($this->lang);
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Contributions by author', $this->lang, 'Contribuições por autor', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Remove', $this->lang, 'Novo remover', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Approved Status', $this->lang, 'Aprovado', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Something', $this->lang, 'Algo', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Trying to insert malicious PHP code back to the language.php file', $this->lang, 'asff"); echo \'teste\'; $dois = array(\'\',"', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', array('Should escape "double quotes" in the source string', $this->lang, 'Deve escapar "aspas duplas" na string original', 1));
TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`) VALUES (?, ?, ?)', array('Not changed', $this->lang, 'Translation not changed'));
TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', array('Untranslated string 1', $this->lang));
TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', array('Untranslated string 2', $this->lang));
TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', array('Untranslated string 3', $this->lang));
global ${"lang_{$this->lang}"};
copy(dirname(__FILE__) . '/fixtures/language_orig.php', $this->langDir . '/language.php');
if (!isset(${"lang_{$this->lang}"})) {
require_once 'lib/init/tra.php';
init_language($this->lang);
}
}
示例13: initializePropel
public function initializePropel()
{
// build Propel om/map/sql/forms
$files = glob(sfConfig::get('sf_lib_dir') . '/model/om/*.php');
if (false === $files || !count($files)) {
chdir(sfConfig::get('sf_root_dir'));
$task = new sfPropelBuildModelTask($this->dispatcher, new sfFormatter());
ob_start();
$task->run();
$output = ob_get_clean();
}
$files = glob(sfConfig::get('sf_data_dir') . '/sql/*.php');
if (false === $files || !count($files)) {
chdir(sfConfig::get('sf_root_dir'));
$task = new sfPropelBuildSqlTask($this->dispatcher, new sfFormatter());
ob_start();
$task->run();
$output = ob_get_clean();
}
$files = glob(sfConfig::get('sf_lib_dir') . '/form/base/*.php');
if (false === $files || !count($files)) {
chdir(sfConfig::get('sf_root_dir'));
$task = new sfPropelBuildFormsTask($this->dispatcher, new sfFormatter());
$task->run();
}
}
示例14: run
public function run()
{
DB::table('mst_countries')->truncate();
$country_name_full = array();
$country_name_file = app_path() . "/country_name_new.txt";
$myfile_country_name = fopen($country_name_file, "r") or die("Unable to open file!");
$read_country_name_file = fread($myfile_country_name, filesize($country_name_file));
$array_country_names = explode("\n", $read_country_name_file);
foreach ($array_country_names as $key_country_names) {
if ($key_country_names != null) {
$country_name_list = explode(" ", $key_country_names);
$country_name_full[$country_name_list[0]] = $country_name_list[1];
}
}
$country_name_ja = "";
$file_folder = public_path() . "/flags/";
//use the directory class
$files = dir($file_folder);
//read all files ;from the directory
chdir($file_folder);
$file_names = glob('*.png');
$i = 1;
//$c = 1;
foreach ($file_names as $file_name) {
$country_name_en = explode('.', $file_name, -1);
if (!empty($country_name_full[$country_name_en[0]])) {
$country_name_ja = $country_name_full[$country_name_en[0]];
}
$country = array("country_name" => $country_name_en[0], "flag_url" => "flags/" . $file_name, "country_name_ja" => $country_name_ja);
Country::create($country);
$i++;
echo $i . "\n";
}
closedir($files->handle);
}
示例15: testExecution
/**
* @dataProvider getFormat
* @runInSeparateProcess
*/
public function testExecution($format)
{
$tmpDir = sys_get_temp_dir() . '/sf_hello';
$filesystem = new Filesystem();
$filesystem->remove($tmpDir);
$filesystem->mkdirs($tmpDir);
chdir($tmpDir);
$tester = new CommandTester(new InitCommand());
$tester->execute(array('--name' => 'Hello' . $format, '--app-path' => 'hello' . $format, '--web-path' => 'web', '--src-path' => 'src', '--format' => $format));
// autoload
$content = file_get_contents($file = $tmpDir . '/src/autoload.php');
$content = str_replace("__DIR__.'/vendor", "'" . __DIR__ . "/../../../../src/vendor", $content);
file_put_contents($file, $content);
// Kernel
$class = 'Hello' . $format . 'Kernel';
$file = $tmpDir . '/hello' . $format . '/' . $class . '.php';
$this->assertTrue(file_exists($file));
$content = file_get_contents($file);
$content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../../../src/vendor/Symfony/src/Symfony/Bundle'", $content);
file_put_contents($file, $content);
require_once $file;
$kernel = new $class('dev', true);
$response = $kernel->handle(Request::create('/'));
$this->assertRegExp('/successfully/', $response->getContent());
$filesystem->remove($tmpDir);
}