当前位置: 首页>>代码示例>>PHP>>正文


PHP Helper::ensureArray方法代码示例

本文整理汇总了PHP中Helper::ensureArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::ensureArray方法的具体用法?PHP Helper::ensureArray怎么用?PHP Helper::ensureArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Helper的用法示例。


在下文中一共展示了Helper::ensureArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copyAssets

 /**
  * Copies folders
  * 
  * @return void
  */
 public function copyAssets()
 {
     foreach (Helper::ensureArray($this->config['copy']) as $folder) {
         $folder = str_replace('{theme}', Config::getTheme(), $folder);
         $full_from_path = Path::assemble(BASE_PATH, $folder);
         $full_to_path = Path::assemble(BASE_PATH, $this->config['destination'], $folder);
         Folder::copy($full_from_path, $full_to_path);
     }
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:14,代码来源:core.generator.php

示例2: render

	public function render()
	{
		// Let's make sure they set an upload destination
		if (array_get($this->field_config, 'destination', false) === false) {
			throw new Exception("You need to set a destination for your File field.");
		}

		// Normalize the destination
		$this->destination = trim(array_get($this->field_config, 'destination'), '/') . '/';

		// Allow a string or an array, but we want an array
		$has_data = ($this->field_data != '');
		$this->field_data = Helper::ensureArray($this->field_data);

		// Clean up {{ _site_root }} and lack of leading slash existence
		foreach ($this->field_data as $i => $file) {
			$this->field_data[$i] = URL::tidy('/' . str_replace('{{ _site_root }}', '', $file));
		}

		// Whether or not to allow the browse existing files functionality
		$allow_browse = array_get($this->field_config, 'browse', true);

		// Resizing config
		if ($resize = array_get($this->field_config, 'resize')) {
			$resize['resize'] = true;
			$resize = http_build_query($resize);
		}

		// If we're in a subdirectory, prepend it to all the filenames
		if (($site_root = Config::getSiteRoot()) != '/') {
			foreach ($this->field_data as $i => $file) {
				$this->field_data[$i] = URL::assemble($site_root, $file);
			}
		}

		// Send data to the view
		$vars = array(
			'field_id'     => $this->field_id,
			'field_name'   => $this->fieldname,
			'tabindex'     => $this->tabindex,
			'has_data'     => $has_data,
			'field_data'   => $this->field_data,
			'field_config' => $this->field_config,
			'destination'  => $this->destination,
			'allow_browse' => $allow_browse,
			'server_files' => ($allow_browse) ? json_encode($this->tasks->generateModal($this->field_config, $this->destination)) : null,
			'file_thumb'   => URL::assemble(Config::getSiteRoot(), Config::get('admin_path'), 'themes', Config::get('admin_theme'), '/img/file.png'),
			'resize'       => $resize
		);
		$template = File::get($this->getAddonLocation() . 'views/fieldtype.html');

		return Parse::template($template, $vars);
	}
开发者ID:jalmelb,项目名称:24hl2015,代码行数:53,代码来源:ft.file.php

示例3: render

 public function render()
 {
     $options = array_get($this->field_config, 'options', array());
     $html = '<input type="hidden" name="' . $this->fieldname . '" value="false" />';
     foreach ($options as $key => $option) {
         $attributes = array('name' => $this->fieldname . '[]', 'id' => $this->field_id . '_' . $key, 'class' => 'checkbox', 'tabindex' => $this->tabindex, 'value' => $key, 'checked' => '');
         if ($this->field_data && in_array($key, Helper::ensureArray($this->field_data))) {
             $attributes['checked'] = 'checked';
         }
         $html .= '<div class="checkbox-block">';
         $html .= HTML::makeInput('checkbox', $attributes, $this->is_required);
         $html .= '<label for="' . $this->field_id . '_' . $key . '">' . $option . '</label>';
         $html .= '</div>';
     }
     return $html;
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:16,代码来源:ft.checkboxes.php

示例4: render

 public function render()
 {
     // Generate a hash unique to this field's config and data
     $hash = Helper::makeHash($this->field_config, $this->field_data);
     // If we've already saved the output, grab it from blink's cache
     // and avoid further processing.
     if ($this->blink->exists($hash)) {
         $html = $this->blink->get($hash);
         return $this->renderFieldReplacements($html);
     }
     // Let's make sure they set an upload destination
     if (array_get($this->field_config, 'destination', false) === false) {
         throw new Exception("You need to set a destination for your File field.");
     }
     // Normalize the destination
     $this->destination = trim(array_get($this->field_config, 'destination'), '/') . '/';
     // Allow a string or an array, but we want an array
     $has_data = $this->field_data != '';
     $this->field_data = Helper::ensureArray($this->field_data);
     // Clean up {{ _site_root }} and lack of leading slash existence
     foreach ($this->field_data as $i => $file) {
         $this->field_data[$i] = URL::tidy('/' . str_replace('{{ _site_root }}', '', $file));
     }
     // Whether or not to allow the browse existing files functionality
     $allow_browse = array_get($this->field_config, 'browse', true);
     // Resizing config
     if ($resize = array_get($this->field_config, 'resize')) {
         $resize['resize'] = true;
         $resize = http_build_query($resize);
     }
     // If we're in a subdirectory, prepend it to all the filenames
     if (($site_root = Config::getSiteRoot()) != '/') {
         foreach ($this->field_data as $i => $file) {
             $this->field_data[$i] = URL::assemble($site_root, $file);
         }
     }
     // Send data to the view
     $vars = array('field_id' => $this->field_id, 'field_name' => $this->fieldname, 'tabindex' => $this->tabindex, 'has_data' => $has_data, 'field_data' => $this->field_data, 'field_config' => $this->field_config, 'destination' => $this->destination, 'allow_browse' => $allow_browse, 'browse_url' => URL::assemble(Config::getSiteRoot(), Config::get('admin_path') . '.php/files?config=' . rawurlencode(Helper::encrypt(serialize($this->field_config)))), 'file_thumb' => $this->tasks->defaultFileThumbnail(), 'resize' => $resize);
     // Get the view template from the file
     $template = File::get($this->getAddonLocation() . 'views/fieldtype.html');
     // Parse it
     $html = Parse::template($template, $vars);
     // Save it to cache for other similar fields
     $this->blink->set($hash, $html);
     // Output!
     return $this->renderFieldReplacements($html);
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:47,代码来源:ft.file.php

示例5: array_get

/**
 * Get an item from an array using "colon" notation.
 *
 * <code>
 *    // Get the $array['user']['name'] value from the array
 *    $name = array_get($array, 'user:name');
 *
 *    // Return a default from if the specified item doesn't exist
 *    $name = array_get($array, 'user:name', 'Batman');
 * 
 *    // Return the first found key, otherwise a default
 *    $name = array_get($array, array('user:name', 'user:first_name'), 'Bruce');
 * </code>
 *
 * @param  array   $array
 * @param  string|array  $key
 * @param  mixed   $default
 * @return mixed
 */
function array_get($array, $key, $default = null) {
    if (is_null($key)) return $array;
    $keys = Helper::ensureArray($key);
    
    // short-circuit
    if (!is_array($array)) {
        return Helper::resolveValue($default);
    }
    
    // a flag to remember whether something has been found or not
    $found = false;

    // To retrieve the array item using dot syntax, we'll iterate through
    // each segment in the key and look for that value. If it exists, we
    // will return it, otherwise we will set the depth of the array and
    // look for the next segment.
    foreach ($keys as $key) {
        foreach (explode(':', $key) as $segment) {
            if (!is_array($array) || !array_key_exists($segment, $array)) {
                // did we not find something? mark `found` as `false`
                $found = false;
                break;
            }

            // we found something, although not sure if this is the last thing,
            // mark `found` as `true` and let the outer loop handle it if this
            // *is* the last thing in the list
            $found = true;
            $array = $array[$segment];
        }
        
        // if `found` is `true`, the inner loop found something worth returning,
        // which means that we're done here
        if ($found) {
            break;
        }
    }
    
    if ($found) {
        // `found` is `true`, we found something, return that
        return $array;
    } else {
        // `found` isn't `true`, return the default
        return Helper::resolveValue($default);
    }
}
开发者ID:jalmelb,项目名称:24hl2015,代码行数:65,代码来源:functions.php

示例6: fetchParam

 /**
  * Fetches a value from the user-passed parameters
  *
  * @param mixed  $keys  Key of value to retrieve, an array will allow fallback param names
  * @param mixed  $default  Default value if no value is found
  * @param callable  $validity_check  Allows a callback function to validate parameter
  * @param boolean  $is_boolean  Indicates parameter is boolean
  * @param boolean  $force_lower  Force the parameter's value to be lowercase?
  * @return mixed
  */
 protected function fetchParam($keys, $default = NULL, $validity_check = NULL, $is_boolean = FALSE, $force_lower = TRUE)
 {
     $keys = Helper::ensureArray($keys);
     foreach ($keys as $key) {
         if (isset($this->attributes[$key])) {
             $value = $force_lower ? strtolower($this->attributes[$key]) : $this->attributes[$key];
             if (!$validity_check || $validity_check && is_callable($validity_check) && $validity_check($value) === TRUE) {
                 // account for yes/no parameters
                 if ($is_boolean === TRUE) {
                     return !in_array(strtolower($value), array("no", "false", "0", "", "-1"));
                 }
                 // otherwise, standard return
                 return $value;
             }
         }
     }
     return $default;
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:28,代码来源:plugin.php

示例7: deleteByKey

 /**
  * Delete one or more keys' hashes
  * 
  * @param string|array  $keys  Key or keys whose hashes should be deleted
  * @return bool
  */
 public function deleteByKey($keys)
 {
     $keys = Helper::ensureArray($keys);
     foreach ($keys as $key) {
         if (!$this->cache->exists('keys/' . $key)) {
             continue;
         }
         // grab the hashes to invalidate
         $hashes = $this->cache->getYAML('keys/' . $key);
         foreach ($hashes as $hash) {
             // delete it
             if ($this->cache->exists('troves/' . $hash)) {
                 $this->cache->delete('troves/' . $hash);
             }
         }
     }
     return true;
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:24,代码来源:core.cache.php

示例8: filter

 /**
  * Filter
  *
  * @param array  $filters  Filter list
  * @return void
  */
 public function filter($filters)
 {
     $folders = array();
     $min_count = 0;
     if (isset($filters['folders'])) {
         $folders = Helper::ensureArray($filters['folders']);
     }
     if (isset($filters['min_count'])) {
         $min_count = (int) $filters['min_count'];
     }
     $data = $this->data;
     foreach ($data as $value => $parts) {
         $filters = array('folders' => $folders);
         $parts['content']->filter($filters);
         $parts['count'] = $parts['content']->count();
         if ($parts['count'] < $min_count) {
             unset($data[$value]);
         }
     }
     $this->data = $data;
 }
开发者ID:nob,项目名称:joi,代码行数:27,代码来源:taxonomyset.php

示例9: filter

 /**
  * Filter
  *
  * @param array  $filters  Filter list
  * @return void
  */
 public function filter($filters)
 {
     $min_count = 0;
     $given_filters = $filters;
     $filters = array('min_count' => isset($given_filters['min_count']) ? $given_filters['min_count'] : null, 'show_drafts' => isset($given_filters['show_drafts']) ? $given_filters['show_drafts'] : null, 'show_hidden' => isset($given_filters['show_hidden']) ? $given_filters['show_hidden'] : null, 'since' => isset($given_filters['since']) ? $given_filters['since'] : null, 'until' => isset($given_filters['until']) ? $given_filters['until'] : null, 'show_past' => isset($given_filters['show_past']) ? $given_filters['show_past'] : null, 'show_future' => isset($given_filters['show_future']) ? $given_filters['show_future'] : null, 'type' => isset($given_filters['type']) ? strtolower($given_filters['type']) : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'where' => isset($given_filters['where']) ? $given_filters['where'] : null, 'folders' => isset($given_filters['folders']) ? $given_filters['folders'] : null, 'located' => isset($given_filters['located']) ? $given_filters['located'] : null);
     // fix folders to be an array
     if (!is_null($filters['folders'])) {
         $filters['folders'] = Helper::ensureArray($filters['folders']);
     }
     if (!is_null($filters['min_count'])) {
         $min_count = (int) $filters['min_count'];
     }
     $data = $this->data;
     foreach ($data as $value => $parts) {
         $parts['content']->filter($filters);
         $parts['count'] = $parts['content']->count();
         if ($parts['count'] < $min_count) {
             unset($data[$value]);
         }
     }
     $this->data = $data;
     // re-tally results
     $this->tallyResults();
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:30,代码来源:taxonomyset.php

示例10: process

    public function process($settings)
    {
        // If empty, save as null
        if ($this->field_data === '') {
            return null;
        }

        // If we're forcing lowercase taxonomies (which we are by default), save them as lower too
        if (array_get($settings, 'taxonomy', false) && Config::get('taxonomy_force_lowercase', false)) {
            $this->field_data = Helper::ensureArray($this->field_data);
            
            foreach ($this->field_data as $key => $value) {
                $this->field_data[$key] = strtolower($value);
            }
        }

        return $this->field_data;
    }
开发者ID:jalmelb,项目名称:24hl2015,代码行数:18,代码来源:ft.suggest.php

示例11: metricTally

 private function metricTally($config, $data)
 {
     $field = $config['field'];
     $metrics = array();
     foreach ($data as $item) {
         $values = Helper::ensureArray($item['fields'][$field]);
         foreach ($values as $value) {
             if (array_get($metrics, $value)) {
                 $metrics[$value] = $metrics[$value] + 1;
             } else {
                 $metrics[$value] = 1;
             }
         }
     }
     if ($sort_by = array_get($config, 'sort_by')) {
         if ($sort_by === 'key') {
             ksort($metrics);
         } elseif ($sort_by === 'value') {
             arsort($metrics);
         }
         if (array_get($config, 'sort_dir') === 'desc') {
             $metrics = array_reverse($metrics, true);
         }
     }
     $config['metrics'] = $metrics;
     return $config;
 }
开发者ID:Synergy23,项目名称:RealEstate,代码行数:27,代码来源:tasks.raven.php

示例12: supplement

 /**
  * Supplements the content in the set
  *
  * @param array  $context  Context for supplementing
  * @return void
  */
 public function supplement($context = array())
 {
     $hash = Debug::markStart('content', 'supplementing');
     if ($this->supplemented) {
         return;
     }
     $this->supplemented = true;
     $context = Helper::ensureArray($context);
     // determine context
     $given_context = $context;
     $context = array('locate_with' => isset($given_context['locate_with']) ? $given_context['locate_with'] : null, 'center_point' => isset($given_context['center_point']) ? $given_context['center_point'] : null, 'list_helpers' => isset($given_content['list_helpers']) ? $given_context['list_helpers'] : true, 'context_urls' => isset($given_context['context_urls']) ? $given_context['context_urls'] : true, 'total_found' => isset($given_context['total_found']) ? $given_context['total_found'] : null, 'group_by_date' => isset($given_context['group_by_date']) ? $given_context['group_by_date'] : null, 'inherit_folder_data' => isset($given_context['inherit_folder_data']) ? $given_context['inherit_folder_data'] : true, 'merge_with_data' => isset($given_context['merge_with_data']) ? $given_context['merge_with_data'] : true);
     // set up helper variables
     $center_point = false;
     if ($context['center_point'] && preg_match(Pattern::COORDINATES, $context['center_point'], $matches)) {
         $center_point = array($matches[1], $matches[2]);
     }
     // contextual urls are based on current page, not individual data records
     // we can figure this out once and then set it with each one
     if ($context['context_urls']) {
         $raw_url = Request::getResourceURI();
         $page_url = Path::tidy($raw_url);
     }
     // iteration memory
     $last_date = null;
     // loop through content, supplementing each record with data
     foreach ($this->content as $content_key => $data) {
         // locate
         if ($context['locate_with']) {
             $location_data = isset($data[$context['locate_with']]) ? $data[$context['locate_with']] : null;
             // check that location data is fully set
             if (is_array($location_data) && isset($location_data['latitude']) && $location_data['latitude'] && isset($location_data['longitude']) && $location_data['longitude']) {
                 $data['latitude'] = $location_data['latitude'];
                 $data['longitude'] = $location_data['longitude'];
                 $data['coordinates'] = $location_data['latitude'] . "," . $location_data['longitude'];
                 // get distance from center
                 if ($center_point) {
                     $location = array($data['latitude'], $data['longitude']);
                     $data['distance_km'] = Math::getDistanceInKilometers($center_point, $location);
                     $data['distance_mi'] = Math::convertKilometersToMiles($data['distance_km']);
                 }
             }
         }
         // contextual urls
         if ($context['context_urls']) {
             $data['raw_url'] = $raw_url;
             $data['page_url'] = $page_url;
         }
         // total entries
         if ($context['total_found']) {
             $data['total_found'] = (int) $context['total_found'];
         }
         // group by date
         if ($context['group_by_date'] && $data['datestamp']) {
             $formatted_date = Date::format($context['group_by_date'], $data['datestamp']);
             if ($formatted_date !== $last_date) {
                 $last_date = $formatted_date;
                 $data['grouped_date'] = $formatted_date;
             } else {
                 $data['grouped_date'] = '';
             }
         }
         // loop through content to add data for variables that are arrays
         foreach ($data as $key => $value) {
             // Only run on zero indexed arrays/loops
             if (is_array($value) && isset($value[0]) && !is_array($value[0])) {
                 // list helpers
                 if ($context['list_helpers']) {
                     // make automagic lists
                     $data[$key . "_list"] = join(", ", $value);
                     $data[$key . "_spaced_list"] = join(" ", $value);
                     $data[$key . "_option_list"] = join("|", $value);
                     $data[$key . "_ordered_list"] = "<ol><li>" . join("</li><li>", $value) . "</li></ol>";
                     $data[$key . "_unordered_list"] = "<ul><li>" . join("</li><li>", $value) . "</li></ul>";
                     $data[$key . "_sentence_list"] = Helper::makeSentenceList($value);
                     $data[$key . "_ampersand_sentence_list"] = Helper::makeSentenceList($value, "&", false);
                     // handle taxonomies
                     if (Taxonomy::isTaxonomy($key)) {
                         $url_list = array_map(function ($item) use($data, $key, $value) {
                             return '<a href="' . Taxonomy::getURL($data['_folder'], $key, $item) . '">' . $item . '</a>';
                         }, $value);
                         $data[$key . "_url_list"] = join(", ", $url_list);
                         $data[$key . "_spaced_url_list"] = join(" ", $url_list);
                         $data[$key . "_ordered_url_list"] = "<ol><li>" . join("</li><li>", $url_list) . "</li></ol>";
                         $data[$key . "_unordered_url_list"] = "<ul><li>" . join("</li><li>", $url_list) . "</li></ul>";
                         $data[$key . "_sentence_url_list"] = Helper::makeSentenceList($url_list);
                         $data[$key . "_ampersand_sentence_url_list"] = Helper::makeSentenceList($url_list, "&", false);
                     }
                 }
             }
         }
         // update content with supplemented data merged with global config data
         if ($context['merge_with_data'] || $context['inherit_folder_data']) {
             $folder_data = array();
             $all_config = array();
//.........这里部分代码省略.........
开发者ID:zane-insight,项目名称:WhiteLaceInn,代码行数:101,代码来源:contentset.php

示例13: getContentTree

 /**
  * Gets a tree of content information
  *
  * @param string  $base_url  URL for the base of the tree to load
  * @param int  $depth  Number of levels deep to return
  * @param boolean  $folders_only  Folders only
  * @param boolean  $include_entries  Should we include entries in our tree?
  * @param boolean  $show_hidden  Should we not include hidden content
  * @param boolean  $include_content  Should we include content from the found info?
  * @param mixed  $exclude  Array of URLs to exclude
  * @return array
  */
 public static function getContentTree($base_url, $depth = 12, $folders_only = true, $include_entries = false, $show_hidden = false, $include_content = false, $exclude = false)
 {
     // load structure and set up variables
     self::loadStructure();
     $output = array();
     // exclude URLs
     $exclude = Helper::ensureArray($exclude);
     // no depth asked for
     if ($depth == 0) {
         return array();
     }
     // make sure we can find the requested URL in the structure
     if (!isset(self::$structure[$base_url])) {
         Log::debug('Could not find URL in structure cache.', 'core', 'ContentService');
         return array();
     }
     // depth measurements
     $starting_depth = self::$structure[$base_url]['depth'] + 1;
     // start one deeper than the base URL's depth
     $current_depth = $starting_depth;
     // recursively grab the tree
     foreach (self::$structure as $url => $data) {
         // is this the right depth and not the 404 page?
         if ($data['depth'] !== $current_depth || $url == "/404") {
             continue;
         }
         // is this under the appropriate parent?
         if (!Pattern::startsWith(Path::tidy($data['parent'] . '/'), Path::tidy($base_url . '/'))) {
             continue;
         }
         // is this hidden?
         if ($data['is_draft'] || !$show_hidden && $data['is_hidden']) {
             continue;
         }
         // is this an entry when we don't want them?
         if (!$include_entries && $data['is_entry'] && !$data['is_page']) {
             continue;
         }
         // is this a non-folder when all we want is folders?
         if ($folders_only && $data['type'] != 'folder') {
             continue;
         }
         // is this in the excluded URLs list?
         if (in_array($url, $exclude)) {
             continue;
         }
         // get parent url
         $parent_url = substr($url, 0, strrpos($url, '/'));
         $parent_url = $parent_url == "" ? Config::getSiteRoot() : $parent_url;
         // look up parent data in cache
         if (!isset(self::$parent_cache[$parent_url])) {
             // doesn't exist, load it up
             $parent_data = Content::get($parent_url, $include_content, false);
             if ($include_content) {
                 // give them everything
                 $parent = $parent_data;
             } else {
                 // just the bare necessities
                 $parent = array('title' => isset($parent_data['title']) ? $parent_data['title'] : '', 'url' => isset($parent_data['url']) ? $parent_data['url'] : '');
             }
             // now stick this in the cache for next time
             self::$parent_cache[$parent_url] = $parent;
         }
         // get information
         $content = Content::get($url, $include_content, false);
         // data to be returned to the tree
         $for_output = array('type' => $data['type'], 'title' => isset($content['title']) ? $content['title'] : '', 'slug' => $content['slug'], 'url' => $url, 'depth' => $current_depth, 'children' => self::getContentTree($url, $depth - 1, $folders_only, $include_entries, $show_hidden, $include_content, $exclude), 'is_current' => URL::getCurrent() == $url, 'is_parent' => URL::getCurrent() != $url && Pattern::startsWith(URL::getCurrent(), $url . '/'), 'is_entry' => $data['is_entry'], 'is_page' => $data['is_page'], 'is_folder' => $data['type'] == 'folder', 'order_key' => $data['order_key'], 'sub_order_key' => $data['sub_order_key'], 'parent' => array(self::$parent_cache[$parent_url]));
         // if we're including content, merge that in
         if ($include_content) {
             $for_output = $content + $for_output;
         }
         // add it to the list
         $output[] = $for_output;
     }
     // now we need to sort the nav items
     uasort($output, function ($a, $b) {
         // sort on order_key
         $result = Helper::compareValues($a['order_key'], $b['order_key']);
         // if those matched, sort on sub_order_key
         if ($result === 0) {
             $result = Helper::compareValues($a['sub_order_key'], $b['sub_order_key']);
         }
         // return 1 or 0 or -1, whatever we ended up with
         return $result;
     });
     // re-key the array
     $output = array_values($output);
     // return what we know
//.........这里部分代码省略.........
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:101,代码来源:contentservice.php

示例14: hasRole

 /**
  * Checks to see if this member has a given $role
  * 
  * @param mixed  $role  Role to check
  * @return boolean
  */
 public function hasRole($role)
 {
     $role = array_map('strtolower', Helper::ensureArray($role));
     $member_roles = array_map('strtolower', $this->get('roles'));
     // check for intersection
     $matches = array_intersect($member_roles, $role);
     return (bool) count($matches);
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:14,代码来源:member.php

示例15: update


//.........这里部分代码省略.........
             $files_changed = true;
             // get URL
             $url = isset($cache['content'][$folder][$path]['url']) ? $cache['content'][$folder][$path]['url'] : null;
             // only remove from URLs list if not in changed URLs list
             if (!isset($changed_urls[$url]) && !is_null($url)) {
                 // remove from url cache
                 unset($cache['urls'][$url]);
             }
             // remove from content cache
             unset($cache['content'][$folder][$path]);
         }
     }
     // build taxonomy cache
     // only happens if files were added, updated, or deleted above
     if ($files_changed) {
         $taxonomies = Config::getTaxonomies();
         $force_lowercase = Config::getTaxonomyForceLowercase();
         $case_sensitive = Config::getTaxonomyCaseSensitive();
         $cache['taxonomies'] = array();
         // rebuild taxonomies
         if (count($taxonomies)) {
             // set up taxonomy array
             foreach ($taxonomies as $taxonomy) {
                 $cache['taxonomies'][$taxonomy] = array();
             }
             // loop through content to build cached array
             foreach ($cache['content'] as $pages) {
                 foreach ($pages as $item) {
                     $data = $item['data'];
                     // loop through the types of taxonomies
                     foreach ($taxonomies as $taxonomy) {
                         // if this file contains this type of taxonomy
                         if (isset($data[$taxonomy])) {
                             $values = Helper::ensureArray($data[$taxonomy]);
                             // add the file name to the list of found files for a given taxonomy value
                             foreach ($values as $value) {
                                 if (!$value) {
                                     continue;
                                 }
                                 $key = !$case_sensitive ? strtolower($value) : $value;
                                 if (!isset($cache['taxonomies'][$taxonomy][$key])) {
                                     $cache['taxonomies'][$taxonomy][$key] = array('name' => $force_lowercase ? strtolower($value) : $value, 'files' => array());
                                 }
                                 array_push($cache['taxonomies'][$taxonomy][$key]['files'], $data['url']);
                             }
                         }
                     }
                 }
             }
         }
         // build structure cache
         $structure = array();
         $home = Path::tidy('/' . Config::getSiteRoot() . '/');
         foreach ($cache['content'] as $pages) {
             foreach ($pages as $item) {
                 // set up base variables
                 $parent = null;
                 // Trim off home and any /page.md ending so that all URLs are treated
                 // equally regardless of page type.
                 $order_key = str_replace('/page.md', '', str_replace($home, '', $item['path']));
                 $sub_order_key = $item['data']['_order_key'];
                 // does this have a parent (and if so, what is it?)
                 if ($item['url'] !== $home) {
                     $parent = $home;
                     $depth = substr_count(str_replace($home, '/', $item['url']), '/');
                     $last_slash = strrpos($item['url'], '/', 1);
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:67,代码来源:_cache.php


注:本文中的Helper::ensureArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。