本文整理汇总了PHP中file_scan_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP file_scan_directory函数的具体用法?PHP file_scan_directory怎么用?PHP file_scan_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_scan_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fillRandomValues
/**
* Fill generic file field with random files.
*
* @param Form $formObject
* Form object.
* @param string $field_name
* Field name.
* @param array $options
* Options array.
*
* @return array
* An array with 3 values:
* (1) $success: Whether default values could be filled in the field.
* (2) $values: Values that were filled for the field.
* (3) $msg: Message in case there is an error. This will be empty if
* $success is TRUE.
*/
public static function fillRandomValues(Form $formObject, $field_name, $options = array())
{
$num = 1;
$file_extensions = 'txt';
$scheme = 'public';
$show_description = FALSE;
if (method_exists($formObject, 'getEntityObject')) {
// This is an entity form.
list($field, $instance, $num) = $formObject->getFieldDetails($field_name);
$file_extensions = $instance['settings']['file_extensions'];
$scheme = $field['settings']['uri_scheme'];
$show_description = $instance['settings']['description_field'];
}
$extensions = str_replace(" ", "|", $file_extensions);
$files = file_scan_directory('tests/assets', '/^.*\\.(' . $extensions . ')$/i');
$filenames = array();
foreach ($files as $file_name => $file_array) {
$filenames[] = $file_array->uri;
}
if (!sizeof($filenames)) {
return new Response(FALSE, array(), "Could not find a file to attach with any of the following extensions: " . $file_extensions);
}
$files = array();
for ($i = 0; $i < $num; $i++) {
if ($show_description) {
$files[] = array('uri' => $filenames[Utils::getRandomInt(0, sizeof($filenames) - 1)], 'description' => Utils::getRandomText(20), 'scheme' => $scheme);
} else {
$files[] = array('uri' => $filenames[Utils::getRandomInt(0, sizeof($filenames) - 1)], 'scheme' => $scheme);
}
}
$files = Utils::normalize($files);
$function = "fill" . Utils::makeTitleCase($field_name) . "Values";
return $formObject->{$function}($files);
}
示例2: canUpdateDirectory
/**
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/
public static function canUpdateDirectory($directory)
{
if (file_scan_directory($directory, '/.*\\.module$/')) {
return TRUE;
}
return FALSE;
}
示例3: preparePackage
/**
* Reads and merges in existing files for a given package or profile.
*/
protected function preparePackage(Package $package, array $existing_packages, FeaturesBundleInterface $bundle = NULL)
{
if (isset($existing_packages[$package->getMachineName()])) {
$existing_directory = $existing_packages[$package->getMachineName()];
// Scan for all files.
$files = file_scan_directory($existing_directory, '/.*/');
foreach ($files as $file) {
// Skip files in the any existing configuration directory, as these
// will be replaced.
foreach (array_keys($this->featuresManager->getExtensionStorages()->getExtensionStorages()) as $directory) {
if (strpos($file->uri, $directory) !== FALSE) {
continue 2;
}
}
// Merge in the info file.
if ($file->name == $package->getMachineName() . '.info') {
$files = $package->getFiles();
$files['info']['string'] = $this->mergeInfoFile($package->getFiles()['info']['string'], $file->uri);
$package->setFiles($files);
} else {
// Determine if the file is within a subdirectory of the
// extension's directory.
$file_directory = dirname($file->uri);
if ($file_directory !== $existing_directory) {
$subdirectory = substr($file_directory, strlen($existing_directory) + 1);
} else {
$subdirectory = NULL;
}
$package->appendFile(['filename' => $file->filename, 'subdirectory' => $subdirectory, 'string' => file_get_contents($file->uri)]);
}
}
}
}
示例4: testPiwikUninstall
/**
* Tests if the module cleans up the disk on uninstall.
*/
public function testPiwikUninstall()
{
$cache_path = 'public://piwik';
$site_id = '1';
$this->config('piwik.settings')->set('site_id', $site_id)->save();
$this->config('piwik.settings')->set('url_http', 'http://www.example.com/piwik/')->save();
$this->config('piwik.settings')->set('url_https', 'https://www.example.com/piwik/')->save();
// Enable local caching of piwik.js
$this->config('piwik.settings')->set('cache', 1)->save();
// Load front page to get the piwik.js downloaded into local cache. But
// loading the piwik.js is not possible as "url_http" is a test dummy only.
// Create a dummy file to complete the rest of the tests.
file_prepare_directory($cache_path, FILE_CREATE_DIRECTORY);
file_unmanaged_save_data($this->randomMachineName(16), $cache_path . '/piwik.js');
// Test if the directory and piwik.js exists.
$this->assertTrue(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been found.');
$this->assertTrue(file_exists($cache_path . '/piwik.js'), 'Cached piwik.js tracking file has been found.');
// Uninstall the module.
$edit = [];
$edit['uninstall[piwik]'] = TRUE;
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this->assertNoText(\Drupal::translation()->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.');
$this->drupalPostForm(NULL, NULL, t('Uninstall'));
$this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
// Test if the directory and all files have been removed.
$this->assertFalse(file_scan_directory($cache_path, '/.*/'), 'Cached JavaScript files have been removed.');
$this->assertFalse(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been removed.');
}
示例5: preparePackage
/**
* Reads and merges in existing files for a given package or profile.
*/
protected function preparePackage(array &$package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) {
if (isset($existing_packages[$package['machine_name']])) {
$existing_directory = $existing_packages[$package['machine_name']];
// Scan for all files.
$files = file_scan_directory($existing_directory, '/.*/');
foreach ($files as $file) {
// Skip files in the install directory.
if (strpos($existing_directory, InstallStorage::CONFIG_INSTALL_DIRECTORY) !== FALSE) {
continue;
}
// Merge in the info file.
if ($file->name == $package['machine_name'] . '.info') {
$package['files']['info']['string'] = $this->mergeInfoFile($package['files']['info']['string'], $file->uri);
}
// Read in remaining files.
else {
// Determine if the file is within a subdirectory of the
// extension's directory.
$file_directory = dirname($file->uri);
if ($file_directory !== $existing_directory) {
$subdirectory = substr($file_directory, strlen($existing_directory) + 1);
}
else {
$subdirectory = NULL;
}
$package['files'][] = [
'filename' => $file->filename,
'subdirectory' => $subdirectory,
'string' => file_get_contents($file->uri)
];
}
}
}
}
示例6: canUpdateDirectory
/**
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/
static function canUpdateDirectory($directory)
{
// This is a lousy test, but don't know how else to confirm it is a theme.
if (file_scan_directory($directory, '/.*\\.module$/')) {
return FALSE;
}
return TRUE;
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$tables = file_scan_directory($this->getDumpDirectory(), '/.php$/', array('recurse' => FALSE));
$this->loadDumps(array_keys($tables));
$this->installEntitySchema('user');
$this->installConfig(['migrate_drupal', 'system']);
}
示例8: systemListing
/**
* A version-independent wrapper for drupal_system_listing().
*
* Based on notes in change record at https://www.drupal.org/node/2198695.
*/
function systemListing($mask, $directory, $key = 'name', $min_depth = 1)
{
$files = array();
foreach (\Drupal::moduleHandler()->getModuleList() as $name => $module) {
$files += file_scan_directory($module->getPath(), $mask, array('key' => $key));
}
return $files;
}
示例9: verifyDumpFiles
protected function verifyDumpFiles($directory)
{
$tables = file_scan_directory($directory, '/.php$/');
foreach ($tables as $table) {
$contents = rtrim(file_get_contents($table->uri));
$this->assertIdentical(substr($contents, -32), md5(substr($contents, 0, -33)), $table->uri);
}
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Log execution time.
$start_time = microtime(TRUE);
// Try to load the files count from cache. This function will accept two
// arguments:
// - cache object name (cid)
// - cache bin, the (optional) cache bin (most often a database table) where
// the object is to be saved.
//
// cache_get() returns the cached object or FALSE if object does not exist.
if ($cache = \Drupal::cache()->get('cache_example_files_count')) {
/*
* Get cached data. Complex data types will be unserialized automatically.
*/
$files_count = $cache->data;
} else {
// If there was no cached data available we have to search filesystem.
// Recursively get all files from Drupal's folder.
$files_count = count(file_scan_directory('.', '/.*/'));
// Since we have recalculated, we now need to store the new data into
// cache. Complex data types will be automatically serialized before
// being saved into cache.
// Here we use the default setting and create an unexpiring cache item.
// See below for an example that creates an expiring cache item.
\Drupal::cache()->set('cache_example_files_count', $files_count, CacheBackendInterface::CACHE_PERMANENT);
}
$end_time = microtime(TRUE);
$duration = $end_time - $start_time;
// Format intro message.
$intro_message = '<p>' . t('This example will search the entire drupal folder and display a count of the files in it.') . ' ';
$intro_message .= t('This can take a while, since there are a lot of files to be searched.') . ' ';
$intro_message .= t('We will search filesystem just once and save output to the cache. We will use cached data for later requests.') . '</p>';
$intro_message .= '<p>' . t('<a href="@url">Reload this page</a> to see cache in action.', array('@url' => request_uri())) . ' ';
$intro_message .= t('You can use the button below to remove cached data.') . '</p>';
$form['file_search'] = array('#type' => 'fieldset', '#title' => t('File search caching'));
$form['file_search']['introduction'] = array('#markup' => $intro_message);
$color = empty($cache) ? 'red' : 'green';
$retrieval = empty($cache) ? t('calculated by traversing the filesystem') : t('retrieved from cache');
$form['file_search']['statistics'] = array('#type' => 'item', '#markup' => t('%count files exist in this Drupal installation; @retrieval in @time ms. <br/>(Source: <span style="color:@color;">@source</span>)', array('%count' => $files_count, '@retrieval' => $retrieval, '@time' => number_format($duration * 1000, 2), '@color' => $color, '@source' => empty($cache) ? t('actual file search') : t('cached'))));
$form['file_search']['remove_file_count'] = array('#type' => 'submit', '#submit' => array(array($this, 'expireFiles')), '#value' => t('Explicitly remove cached file count'));
$form['expiration_demo'] = array('#type' => 'fieldset', '#title' => t('Cache expiration settings'));
$form['expiration_demo']['explanation'] = array('#markup' => t('A cache item can be set as CACHE_PERMANENT, meaning that it will only be removed when explicitly cleared, or it can have an expiration time (a Unix timestamp).'));
$item = \Drupal::cache()->get('cache_example_expiring_item', TRUE);
if ($item == FALSE) {
$item_status = t('Cache item does not exist');
} else {
$item_status = $item->valid ? t('Cache item exists and is set to expire at %time', array('%time' => $item->data)) : t('Cache_item is invalid');
}
$form['expiration_demo']['current_status'] = array('#type' => 'item', '#title' => t('Current status of cache item "cache_example_expiring_item"'), '#markup' => $item_status);
$form['expiration_demo']['expiration'] = array('#type' => 'select', '#title' => t('Time before cache expiration'), '#options' => array('never_remove' => t('CACHE_PERMANENT'), -10 => t('Immediate expiration'), 10 => t('10 seconds from form submission'), 60 => t('1 minute from form submission'), 300 => t('5 minutes from form submission')), '#default_value' => -10, '#description' => t('Any cache item can be set to only expire when explicitly cleared, or to expire at a given time.'));
$form['expiration_demo']['create_cache_item'] = array('#type' => 'submit', '#value' => t('Create a cache item with this expiration'), '#submit' => array(array($this, 'createExpiringItem')));
$form['cache_clearing'] = array('#type' => 'fieldset', '#title' => t('Expire and remove options'), '#description' => t("We have APIs to expire cached items and also to just remove them. Unfortunately, they're all the same API, cache_clear_all"));
$form['cache_clearing']['cache_clear_type'] = array('#type' => 'radios', '#title' => t('Type of cache clearing to do'), '#options' => array('expire' => t('Remove items from the "cache" bin that have expired'), 'remove_all' => t('Remove all items from the "cache" bin regardless of expiration'), 'remove_tag' => t('Remove all items in the "cache" bin with the tag "cache_example" set to 1')), '#default_value' => 'expire');
// Submit button to clear cached data.
$form['cache_clearing']['clear_expired'] = array('#type' => 'submit', '#value' => t('Clear or expire cache'), '#submit' => array(array($this, 'cacheClearing')), '#access' => \Drupal::currentUser()->hasPermission('administer site configuration'));
return $form;
}
示例11: glossy_style_option
/**
* Generate list of available styles definitions
* @return $styles
* Style names that found in skin directory
*/
function glossy_style_option() {
$styles = array();
$skin_path = variable_get('glossy_skin_dir', drupal_get_path('theme', 'glossy') . '/css/skins');
if(is_dir($skin_path)) {
$styles = file_scan_directory($skin_path, '/\.css$/i');
}
asort($styles);
return $styles;
}
示例12: isImageFilename
private function isImageFilename($filename, $directory)
{
$files = file_scan_directory($directory, '/.*' . $filename . '$/', array('recurse' => TRUE));
// First look for file with the exact name.
foreach ($files as $uri => $file) {
if ($file->filename == $filename && @getimagesize($uri)) {
return $uri;
}
}
// There is no file with the exact name. Return FALSE.
return FALSE;
}
示例13: __construct
public function __construct($filename, $directory = '')
{
$found = FALSE;
// Some OBJ files provide full relative pathname. Extract just the filename.
$path_info = pathinfo($filename);
$filename = $path_info['basename'];
$files = file_scan_directory($directory, '/.*' . $filename . '$/', array('recurse' => TRUE));
foreach ($files as $uri => $file) {
if ($file->filename != $filename) {
continue;
}
$found = TRUE;
$handle = fopen($uri, 'r');
$material = NULL;
$text = '';
while (($line = fgets($handle)) !== FALSE) {
$line = trim($line);
// Start of a new material.
// Store the old material first.
if (strpos($line, 'newmtl ') === 0) {
// Start a new material.
// First close the previous material.
if (!empty($text)) {
$material = new Material($text, $directory);
if ($error = $material->getError()) {
$this->error = $error;
return;
}
$this->materials[$material->name] = $material;
}
$text = $line;
} elseif (!empty($line) && strpos($line, '#') !== 0) {
$text .= PHP_EOL . $line;
}
}
// End of file. Create the material.
if (!empty($text)) {
$material = new Material($text, $directory);
if ($error = $material->getError()) {
$this->error = $error;
return;
}
$this->materials[$material->name] = $material;
}
}
if (!$found) {
$this->error = 'File ' . $filename . ' doesn\'t exist.';
return;
}
}
示例14: prepare
function prepare($caller)
{
global $settings;
foreach (file_scan_directory(__DIR__ . '/include/', '/.*\\.inc$/') as $include) {
include_once $include->uri;
}
$settings = settings($caller);
$install_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.install';
$info_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.info';
$includes = file_scan_directory($settings['script_path']['dirname'], '/.*\\.inc$/');
foreach ($includes as $include) {
include_once $include->uri;
}
}
示例15: migrate
function migrate()
{
global $term_dir;
$completed = array();
$names = $_POST['edit']['migrate'];
foreach ($names as $name => $status) {
$files = file_scan_directory($term_dir, $name);
if (count($files) != 1) {
print count($files) . " files match the name: {$name}";
exit;
}
$image = array_pop($files);
$image->filename_orig = $image->filename;
if ($status == 1) {
$image->tid = migrate_term_image_get_tid($image->name);
if (!taxonomy_get_term($image->tid)) {
print "cant find the tid: {$tid}";
exit;
}
$t_i_image = db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid = %d', $image->tid));
if ($t_i_image) {
$term->has_image = true;
}
if ($term->has_image) {
taxonomy_image_delete($image->tid);
}
if (file_copy($image->filename) != 1) {
print "couldnt copy file: {$image->filename} to new location";
exit;
}
db_query("INSERT INTO {term_image} (tid, path) VALUES (%d, '%s')", $image->tid, $image->filename);
$completed[] = $image;
}
if ($_POST['edit']['delete'][$name] == 1) {
file_delete($image->filename_orig);
$deleted[] = $image;
}
}
if ($c = count($completed)) {
print "Updated {$c} terms";
} else {
print "No terms updated";
}
if ($c = count($deleted)) {
print "Deleted {$c} node_image(s)";
} else {
print "No images deleted";
}
}