本文整理匯總了PHP中Install::ls方法的典型用法代碼示例。如果您正苦於以下問題:PHP Install::ls方法的具體用法?PHP Install::ls怎麽用?PHP Install::ls使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Install
的用法示例。
在下文中一共展示了Install::ls方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ls
/**
* This function will take a pattern and a folder as the argument and go thru it(recursively if needed)and return the list of
* all files in that folder.
* Link : http://www.bin-co.com/php/scripts/filesystem/ls/
* License : BSD
* Arguments : $pattern - The pattern to look out for [OPTIONAL]
* $folder - The path of the directory of which's directory list you want [OPTIONAL]
* $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
* $options - An array of values 'return_files' or 'return_folders' or both
* Returns : A flat list with the path of all the files(no folders) that matches the condition given.
*/
public static function ls($pattern = "*", $folder = "", $recursivly = false, $options = array('return_files', 'return_folders'))
{
if ($folder) {
$current_folder = realpath('.');
if (in_array('quiet', $options)) {
// If quiet is on, we will suppress the 'no such folder' error
if (!file_exists($folder)) {
return array();
}
}
if (!chdir($folder)) {
return array();
}
}
$get_files = in_array('return_files', $options);
$get_folders = in_array('return_folders', $options);
$both = array();
$folders = array();
// Get the all files and folders in the given directory.
if ($get_files) {
$both = glob($pattern, GLOB_BRACE + GLOB_MARK);
}
if ($recursivly or $get_folders) {
$folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
}
//If a pattern is specified, make sure even the folders match that pattern.
$matching_folders = array();
if ($pattern !== '*') {
$matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
}
//Get just the files by removing the folders from the list of all files.
$all = array_values(array_diff($both, $folders));
if ($recursivly or $get_folders) {
foreach ($folders as $this_folder) {
if ($get_folders) {
//If a pattern is specified, make sure even the folders match that pattern.
if ($pattern !== '*') {
if (in_array($this_folder, $matching_folders)) {
array_push($all, $this_folder);
}
} else {
array_push($all, $this_folder);
}
}
if ($recursivly) {
// Continue calling this function for all the folders
$deep_items = Install::ls($pattern, $this_folder, $recursivly, $options);
# :RECURSION:
foreach ($deep_items as $item) {
array_push($all, $this_folder . $item);
}
}
}
}
if ($folder) {
chdir($current_folder);
}
return $all;
}
示例2: Step2
public function Step2()
{
Kit::ClassLoader('install');
// Work out what is involved in this upgrade
$_SESSION['upgradeFrom'] = Config::Version('DBVersion');
if ($_SESSION['upgradeFrom'] < 1) {
$_SESSION['upgradeFrom'] = 1;
}
// Get a list of .sql and .php files for the upgrade
$sql_files = Install::ls('*.sql', 'install/database', false, array('return_files'));
$php_files = Install::ls('*.php', 'install/database', false, array('return_files'));
// Sort by natural filename (eg 10 is bigger than 2)
natcasesort($sql_files);
natcasesort($php_files);
$_SESSION['phpFiles'] = $php_files;
$_SESSION['sqlFiles'] = $sql_files;
$max_sql = Kit::ValidateParam(substr(end($sql_files), 0, -4), _INT);
$max_php = Kit::ValidateParam(substr(end($php_files), 0, -4), _INT);
$_SESSION['upgradeTo'] = max($max_sql, $max_php);
if (!$_SESSION['upgradeTo']) {
throw new Exception(__('Unable to calculate the upgradeTo value. Check for non-numeric SQL and PHP files in the "install / database" directory.'));
}
if ($_SESSION['upgradeTo'] < $_SESSION['upgradeFrom']) {
$_SESSION['upgradeTo'] = $_SESSION['upgradeFrom'];
}
// Form to collect some information.
$formFields = array();
$formButtons = array();
// Put up an error message if one has been set (and then unset it)
if ($this->errorMessage != '') {
Theme::Set('message', $this->errorMessage);
Theme::Set('prepend', Theme::RenderReturn('message_box'));
$this->errorMessage == '';
}
$formFields[] = FormManager::AddHidden('step', 3);
$formFields[] = FormManager::AddHidden('upgradeFrom', $_SESSION['upgradeFrom']);
$formFields[] = FormManager::AddHidden('upgradeTo', $_SESSION['upgradeTo']);
$formFields[] = FormManager::AddHidden('includes', true);
$formFields[] = FormManager::AddMessage(sprintf(__('Upgrading from database version %d to %d'), $_SESSION['upgradeFrom'], $_SESSION['upgradeTo']));
// Loop for $i between upgradeFrom + 1 and upgradeTo.
// If a php file exists for that upgrade, make an instance of it and call Questions so we can
// Ask the user for input.
for ($i = $_SESSION['upgradeFrom'] + 1; $i <= $_SESSION['upgradeTo']; $i++) {
if (file_exists('install/database/' . $i . '.php')) {
include_once 'install/database/' . $i . '.php';
$stepName = 'Step' . $i;
// Check that a class called Step$i exists
if (class_exists($stepName)) {
$_SESSION['Step' . $i] = new $stepName($this->db);
// Call Questions on the object and send the resulting hash to createQuestions routine
$questionFields = $this->createQuestions($i, $_SESSION['Step' . $i]->Questions());
$formFields = array_merge($formFields, $questionFields);
} else {
$formFields[] = FormManager::AddMessage(sprintf(__('Warning: We included %s.php, but it did not include a class of appropriate name.'), $i));
}
}
}
$formFields[] = FormManager::AddCheckbox('doBackup', 'I agree I have a valid database backup and can restore it should the upgrade process fail', 0, __('It is important to take a database backup before running the upgrade wizard. A backup is essential for recovering your CMS should there be a problem with the upgrade.'), 'b');
// Return a rendered form
Theme::Set('form_action', 'index.php?p=upgrade');
Theme::Set('form_fields', $formFields);
Theme::Set('form_buttons', array(FormManager::AddButton(__('Next'))));
return Theme::RenderReturn('form_render');
}