本文整理汇总了PHP中Object::has_extension方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::has_extension方法的具体用法?PHP Object::has_extension怎么用?PHP Object::has_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::has_extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_homepage_link
/**
* Get the full form (e.g. /home/) relative link to the home page for the current HTTP_HOST value. Note that the
* link is trimmed of leading and trailing slashes before returning to ensure consistency.
*
* @return string
*/
public static function get_homepage_link()
{
if (!self::$cached_homepage_link) {
// TODO Move to 'homepagefordomain' module
if (class_exists('HomepageForDomainExtension')) {
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$SQL_host = Convert::raw2sql($host);
$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%{$SQL_host}%'");
if ($candidates) {
foreach ($candidates as $candidate) {
if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
}
}
}
}
if (!self::$cached_homepage_link) {
// TODO Move to 'translatable' module
if (class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable') && ($link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale()))) {
self::$cached_homepage_link = $link;
} else {
self::$cached_homepage_link = self::get_default_homepage_link();
}
}
}
return self::$cached_homepage_link;
}
示例2: create_slug
public static function create_slug($obj, $field)
{
if (!isset($_REQUEST[$field])) {
$title = $obj->{$field};
} else {
$title = $_REQUEST[$field];
}
$slug = singleton('SiteTree')->generateURLSegment($title);
$original_slug = $slug;
$i = 0;
$class = $obj->class;
if (!Object::has_extension($class, "Sluggable")) {
while ($parent = get_parent_class($obj)) {
if (Object::has_extension($parent, "Sluggable")) {
$class = $parent;
break;
} else {
$obj = singleton($parent);
}
}
}
while ($t = DataList::create($class)->filter(array("Slug" => "{$slug}"))->exclude(array("{$class}.ID" => $obj->ID))->first()) {
$i++;
$slug = $original_slug . "-{$i}";
}
$obj->Slug = $slug;
}
示例3: init
public function init() {
// set reading lang
if(Object::has_extension('SiteTree', 'Translatable') && !$this->request->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
}
parent::init();
Requirements::css(CMS_DIR . '/css/screen.css');
Requirements::combine_files(
'cmsmain.js',
array_merge(
array(
CMS_DIR . '/javascript/CMSMain.js',
CMS_DIR . '/javascript/CMSMain.EditForm.js',
CMS_DIR . '/javascript/CMSMain.AddForm.js',
CMS_DIR . '/javascript/CMSPageHistoryController.js',
CMS_DIR . '/javascript/CMSMain.Tree.js',
CMS_DIR . '/javascript/SilverStripeNavigator.js'
),
Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang', true, true)
)
);
CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive');
}
示例4: load_extra_statics
/**
* Load the extra static definitions for the given extension
* class name, called by {@link Object::add_extension()}
*
* @param string $class Class name of the owner class (or owner base class)
* @param string $extension Class name of the extension class
*/
public static function load_extra_statics($class, $extension)
{
if (!empty(self::$extra_statics_loaded[$class][$extension])) {
return;
}
self::$extra_statics_loaded[$class][$extension] = true;
// If the extension has been manually applied to a subclass, we should ignore that.
if (Object::has_extension(get_parent_class($class), $extension)) {
return;
}
$callable = array($extension, 'extraDBFields');
if (!is_callable($callable)) {
$callable = array($extension, 'extraStatics');
}
$statics = call_user_func($callable);
if ($statics) {
foreach ($statics as $name => $newVal) {
if (isset(self::$decoratable_statics[$name])) {
// Array to be merged
if (self::$decoratable_statics[$name]) {
$origVal = self::uninherited_static($class, $name);
// Can't use add_static_var() here as it would merge the array rather than replacing
self::set_static($class, $name, array_merge((array) $origVal, $newVal));
// Value to be overwritten
} else {
Object::set_static($class, $name, $newVal);
}
}
}
DataObject::$cache_has_own_table[$class] = null;
DataObject::$cache_has_own_table_field[$class] = null;
}
}
示例5: generateExtensionMap
private static function generateExtensionMap()
{
// get a list of classes
$classes = array_unique(array_merge(array_keys(ClassInfo::allClasses()), get_declared_classes()));
// die(print_r($classes,1));
// Silverstripe has broken clases floating around, we need to blacklist them or it's bad times
$blacklist = array('SapphireTestReporter', 'SapphireTest', 'SapphireTestSuite', 'CliTestReporter', 'SilverStripeListener', 'TeamCityListener', 'SS_TestListener');
$blacklistLC = array_map('strtolower', $blacklist);
// init some vars
$extMap = $dOClasses = $dODClasses = array();
// Sort Classes
foreach ($classes as $class) {
if (!in_array(strtolower($class), $blacklistLC)) {
// this breaks when we start looking at some of the broken requires in SapphireTest
if (is_subclass_of($class, 'DataObject')) {
$dOClasses[] = $class;
}
if (is_subclass_of($class, 'Extension')) {
$dODClasses[] = $class;
}
}
}
// Find out what is applied to what
foreach ($dODClasses as $dOD) {
foreach ($dOClasses as $dO) {
if (Object::has_extension($dO, $dOD)) {
$extMap[$dOD][] = $dO;
}
}
}
// Cache the map
self::$extensionMap = $extMap;
}
示例6: cache
/**
* FixMe: Currently only db and has_one fields are cached.
* @param string|int $identifier an identifier which will be used for key generation
* @param callable $callback the function which can be called to fetch the data
* @return DataObject
*/
protected function cache($identifier, $callback)
{
$serializer = CacheHelper::get_serializer();
// check for cacheable extension of data object class
$className = $this->dataClass;
if (Object::has_extension($className, 'CacheableExtension')) {
// search in cache
$cache = CacheHelper::get_cache();
$key = CacheHelper::to_key("{$className}.{$identifier}");
if ($data = $cache->load($key)) {
return $serializer->deserialize($data);
} else {
// if not found in cache, perform callback
$data = $callback();
if (!$data) {
// if result is empty, return null
return null;
}
$cachedFunctions = array_keys($data->hasOne());
foreach ($cachedFunctions as $fn) {
$data->{$fn}();
}
$cache->save($serializer->serialize($data), $key);
// return result
return $data;
}
} else {
return $callback();
}
}
示例7: getManagedModels
function getManagedModels()
{
$classes = $this->stat('managed_models');
if (is_string($classes)) {
$matches = explode(",", $classes);
foreach ($matches as $key => $value) {
$matches[$key] = substr($value, 10);
}
// remove "decorator:"
if (is_array($matches)) {
$classes = array();
foreach (ClassInfo::subclassesFor('DataObject') as $class) {
$add = false;
// used to guarantee that if multiple matches on a class it's not added multiple times.
foreach ($matches as $match) {
if (Object::has_extension($class, $match)) {
$add = true;
}
}
if ($add) {
$classes[] = $class;
}
}
if (count($class) > 1) {
array_unshift($classes, 'All');
}
} else {
$classes = array($classes);
}
}
return $classes;
}
示例8: testEnableWithCustomClasses
public function testEnableWithCustomClasses()
{
FulltextSearchable::enable(array('File'));
$this->assertTrue(Object::has_extension('File', 'FulltextSearchable'));
// TODO This shouldn't need all arguments included
Object::remove_extension('File', 'FulltextSearchable(\'"Filename","Title","Content"\')');
$this->assertFalse(Object::has_extension('File', 'FulltextSearchable'));
}
示例9: get_rules_class
/**
* Getter for the rules class
* Based on your needs, different rule classes could be used
* The module comes bundled with the base rules, and subsite rules
* TODO this could easily be amended to be configurable, so that custom rules could be used
*
* @return string
*/
public static function get_rules_class()
{
$class = 'UploadDirRules';
if (class_exists('Subsite') && Object::has_extension('Subsite', 'AssetsFolderExtension')) {
$class = 'SubsiteUploadDirRules';
}
return $class;
}
示例10: __construct
public function __construct(DataObject $original)
{
$class = $original->class;
if (TD_SS_COMPATIBILITY == TD_COMPAT_SS30X && !Object::has_extension($class, 'TranslatableDataObject') || TD_SS_COMPATIBILITY == TD_COMPAT_SS31X && !$class::has_extension('TranslatableDataObject')) {
trigger_error("Parameter given does not have the required 'TranslatableDataObject' extension", E_USER_ERROR);
}
$this->original = $original;
parent::__construct();
}
开发者ID:DrMartinGonzo,项目名称:translatable-dataobject,代码行数:9,代码来源:TranslatableFormFieldTransformation.php
示例11: getExtendedClasses
/**
* Find out which classes are extended by this extension.
*
* Originally from: http://stackoverflow.com/a/26148610/2754026
*
* @return array Array of strings
*/
public static function getExtendedClasses()
{
$classes = array();
foreach (ClassInfo::subclassesFor('Object') as $class_name) {
if (Object::has_extension($class_name, __CLASS__)) {
$classes[] = $class_name;
}
}
return $classes;
}
示例12: GetVersionedClass
static function GetVersionedClass()
{
$classes = array();
foreach (ClassInfo::subClassesFor('DataObject') as $class) {
if (Object::has_extension($class, 'Versioned')) {
$classes[] = $class;
}
}
return $classes;
}
示例13: synchroniseUDatabase
function synchroniseUDatabase()
{
$sync = parent::synchroniseUDatabase();
$sync = $sync && !(Object::has_extension('Product', 'ProductWithVariationDecorator') && $this->owner->HasVariations());
if ($sync) {
if (empty($this->owner->Title)) {
return $this->notifyError('SS_FIELDS_MISSING', 'Title');
}
return true;
}
}
示例14: init
public function init()
{
//setting the uploads directory to make sure images uploaded through the content
//editor are saved the right place
$curr = LeftAndMain::curr();
if ($curr) {
//Debug::dump(get_class($curr));
//Debug::dump(ClassInfo::ancestry($curr));
$currClass = null;
foreach (ClassInfo::ancestry($curr) as $class) {
foreach (self::$supported_classes as $supported_class) {
if ($class == $supported_class) {
$currClass = $class;
}
}
}
//Debug::dump($currClass);
//switch (get_class($curr)) {
switch ($currClass) {
//Page administration
case 'CMSPagesController':
case 'CMSPageEditController':
$page = $curr->currentPage();
if ($page && $page->hasExtension('AssetsFolderExtension')) {
Upload::config()->uploads_folder = $page->getAssetsFolderDirName();
}
//Debug::dump($page->Title);
break;
case 'ModelAdmin':
//For ModelAdmin we're falling back to cookies that we believe to have
//been set when setting the cms fields, see AssetFolderExtension::updateCMSFields()
//...as it seems to be almost impossible to figure out the current object elsewise
//see below for tries
//pull requests to fix this welcome!!!
//Debug::dump($this->owner->getURLParams());
//Debug::dump($this->owner->request->param('ModelClass'));
//Debug::dump($this->owner->request->remaining());
//Debug::dump($this->owner->request->getVars());
//Debug::dump($this->owner->request->params());
//Debug::dump($curr->currentPageID());
Upload::config()->uploads_folder = Cookie::get('cms-uploaddirrules-uploads-folder');
break;
//Settings
//Settings
case 'CMSSettingsController':
if (Object::has_extension('SiteConfig', 'AssetsFolderExtension')) {
$sc = SiteConfig::current_site_config();
Upload::config()->uploads_folder = $sc->getAssetsFolderDirName();
}
default:
}
}
}
示例15: is_sortable_class
public static function is_sortable_class($classname)
{
if (in_array($classname, self::$sortable_classes)) {
return true;
}
foreach (self::$sortable_classes as $class) {
if (is_subclass_of($classname, $class)) {
return true;
}
}
return Object::has_extension($classname, 'SortableDataObject');
}