本文整理汇总了PHP中Object::add_extension方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::add_extension方法的具体用法?PHP Object::add_extension怎么用?PHP Object::add_extension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::add_extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_up_constraints
/**
* Set up constraints via _config.php
*/
public static function set_up_constraints()
{
$constraints = Config::inst()->forClass("Discount")->constraints;
foreach ($constraints as $constraint) {
Object::add_extension("Discount", $constraint);
}
}
示例2: setUp
function setUp()
{
parent::setUp();
Object::add_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
FilesystemPublisher::$domain_based_caching = false;
}
示例3: setUp
function setUp()
{
parent::setUp();
Object::add_extension("SiteTree", "FilesystemPublisher('assets/HomepageForDomainTest-static-folder/')");
HomepageForDomainExtension::$write_homepage_map = false;
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
FilesystemPublisher::$domain_based_caching = false;
}
示例4: tearDown
public function tearDown()
{
// TODO This shouldn't need all arguments included
if ($this->orig['File_searchable']) {
Object::add_extension('File', 'FulltextSearchable(\'"Filename","Title","Content"\')');
}
parent::tearDown();
}
示例5: add_weight
public static function add_weight($weight)
{
self::$weights[] = $weight;
$class = "NewsWeight{$weight}";
if (ClassInfo::exists($class)) {
Object::add_extension('NewsHolder', $class);
}
}
示例6: add
/**
* Adds commenting to a {@link DataObject}
*
* @param string classname to add commenting to
* @param array $setting Settings. See {@link self::$default_config} for
* available settings
*
* @throws InvalidArgumentException
*/
public static function add($class, $settings = false)
{
if ($settings && !is_array($settings)) {
throw new InvalidArgumentException('$settings needs to be an array or null', E_USER_ERROR);
}
self::$enabled_classes[$class] = $settings;
Object::add_extension($class, 'CommentsExtension');
}
示例7: tearDown
function tearDown()
{
// TODO This shouldn't need all arguments included
if ($this->orig['File_searchable']) {
Object::add_extension('File', 'FulltextSearchable(\'Filename,Title,Content\')');
}
if ($this->orig['SiteTree_searchable']) {
Object::add_extension('SiteTree', 'FulltextSearchable(\'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords\')');
}
parent::tearDown();
}
示例8: tear_down_once
static function tear_down_once()
{
if (self::$origTranslatableSettings['has_extension']) {
Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');
}
Translatable::set_default_locale(self::$origTranslatableSettings['default_locale']);
Translatable::set_current_locale(self::$origTranslatableSettings['default_locale']);
self::kill_temp_db();
self::create_temp_db();
parent::tear_down_once();
}
示例9: enable
/**
* Enable the default configuration of MySQL full-text searching on the given data classes.
*/
static function enable($searchableClasses = array('SiteTree', 'File'))
{
$defaultColumns = array('SiteTree' => 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords', 'File' => 'Filename,Title,Content');
if (!is_array($searchableClasses)) {
$searchableClasses = array($searchableClasses);
}
foreach ($searchableClasses as $class) {
if (isset($defaultColumns[$class])) {
Object::add_extension($class, "FulltextSearchable('{$defaultColumns[$class]}')");
} else {
throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '{$class}'");
}
}
Object::add_extension("ContentController", "ContentControllerSearchExtension");
}
示例10: setupSteps
/**
* Set up CheckoutPage_Controller decorators for managing steps
*/
public static function setupSteps($steps = null)
{
if (!is_array($steps)) {
//default steps
$steps = array('membership' => 'CheckoutStep_Membership', 'contactdetails' => 'CheckoutStep_ContactDetails', 'shippingaddress' => 'CheckoutStep_Address', 'billingaddress' => 'CheckoutStep_Address', 'paymentmethod' => 'CheckoutStep_PaymentMethod', 'summary' => 'CheckoutStep_Summary');
}
CheckoutPage::config()->steps = $steps;
if (!CheckoutPage::config()->first_step) {
reset($steps);
CheckoutPage::config()->first_step = key($steps);
}
//initiate extensions
Object::add_extension("CheckoutPage_Controller", "SteppedCheckout");
foreach ($steps as $action => $classname) {
Object::add_extension("CheckoutPage_Controller", $classname);
}
}
示例11: testExtraFieldsViaExtension
public function testExtraFieldsViaExtension()
{
// This extends ManyManyListTest_Secondary with the secondary extension that adds the relationship back
// to the primary. The instance from the fixture is ManyManyListTest_SecondarySub, deliberately a sub-class of
// the extended class.
Object::add_extension('ManyManyListTest_Secondary', 'ManyManyListTest_IndirectSecondaryExtension');
// Test from the primary (not extended) to the secondary (which is extended)
$primary = $this->objFromFixture('ManyManyListTest_IndirectPrimary', 'manymany_extra_primary');
$secondaries = $primary->Secondary();
$extraFields = $secondaries->getExtraFields();
$this->assertTrue(count($extraFields) > 0, 'has extra fields');
$this->assertTrue(isset($extraFields['DocumentSort']), 'has DocumentSort');
// Test from the secondary (which is extended) to the primary (not extended)
$secondary = $this->objFromFixture('ManyManyListTest_SecondarySub', 'manymany_extra_secondary');
$primaries = $secondary->Primary();
$extraFields = $primaries->getExtraFields();
$this->assertTrue(count($extraFields) > 0, 'has extra fields');
$this->assertTrue(isset($extraFields['DocumentSort']), 'has DocumentSort');
}
示例12: testAddExtensionLoadsStatics
/**
* Test {@link Object::add_extension()} has loaded DataExtension statics correctly.
*/
function testAddExtensionLoadsStatics()
{
// Object::add_extension() will load DOD statics directly, so let's try adding a extension on the fly
Object::add_extension('DataExtensionTest_Player', 'DataExtensionTest_PlayerExtension');
// Now that we've just added the extension, we need to rebuild the database
$this->resetDBSchema(true);
// Create a test record with extended fields, writing to the DB
$player = new DataExtensionTest_Player();
$player->setField('Name', 'Joe');
$player->setField('DateBirth', '1990-5-10');
$player->Address = '123 somewhere street';
$player->write();
unset($player);
// Pull the record out of the DB and examine the extended fields
$player = DataObject::get_one('DataExtensionTest_Player', "\"Name\" = 'Joe'");
$this->assertEquals($player->DateBirth, '1990-05-10');
$this->assertEquals($player->Address, '123 somewhere street');
$this->assertEquals($player->Status, 'Goalie');
}
示例13: set_up_once
static function set_up_once()
{
// needs to recreate the database schema with language properties
self::kill_temp_db();
// store old defaults
self::$origTranslatableSettings['has_extension'] = singleton('SiteTree')->hasExtension('Translatable');
self::$origTranslatableSettings['default_locale'] = Translatable::default_locale();
// overwrite locale
Translatable::set_default_locale("en_US");
// refresh the decorated statics - different fields in $db with Translatable enabled
if (!self::$origTranslatableSettings['has_extension']) {
Object::add_extension('SiteTree', 'Translatable');
}
Object::add_extension('TranslatableTest_DataObject', 'Translatable');
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild()
global $_SINGLETONS;
$_SINGLETONS = array();
// recreate database with new settings
$dbname = self::create_temp_db();
DB::set_alternative_database_name($dbname);
parent::set_up_once();
}
示例14: enable
/**
* Enable the default configuration of MySQL full-text searching on the given data classes.
* It can be used to limit the searched classes, but not to add your own classes.
* For this purpose, please use {@link Object::add_extension()} directly:
* <code>
* Object::add_extension('MyObject', "FulltextSearchable('MySearchableField,'MyOtherField')");
* </code>
*
* Caution: This is a wrapper method that should only be used in _config.php,
* and only be called once in your code.
*
* @param Array $searchableClasses The extension will be applied to all DataObject subclasses
* listed here. Default: {@link SiteTree} and {@link File}.
*/
static function enable($searchableClasses = array('SiteTree', 'File'))
{
$defaultColumns = array('SiteTree' => 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords', 'File' => 'Filename,Title,Content');
if (!is_array($searchableClasses)) {
$searchableClasses = array($searchableClasses);
}
foreach ($searchableClasses as $class) {
if (!class_exists($class)) {
continue;
}
if (isset($defaultColumns[$class])) {
Config::inst()->update($class, 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
Object::add_extension($class, "FulltextSearchable('{$defaultColumns[$class]}')");
} else {
throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '{$class}'");
}
}
self::$searchable_classes = $searchableClasses;
if (class_exists("ContentController")) {
Object::add_extension("ContentController", "ContentControllerSearchExtension");
}
}
示例15: enable
/**
* Enable the default configuration of Zend Search Lucene searching on the
* given data classes.
*
* @param Array $searchableClasses An array of classnames to scan. Can
* choose from SiteTree and/or File.
* To not scan any classes, for example
* if we will define custom fields to scan,
* pass in an empty array.
* Defaults to scan SiteTree and File.
*/
public static function enable($searchableClasses = array('SiteTree', 'File'))
{
// We can't enable the search engine if we don't have QueuedJobs installed.
if (!ClassInfo::exists('QueuedJobService')) {
die('<strong>' . _t('ZendSearchLucene.ERROR', 'Error') . '</strong>: ' . _t('ZendSearchLucene.QueuedJobsRequired', 'Lucene requires the Queued jobs module. See ' . '<a href="http://www.silverstripe.org/queued-jobs-module/">' . 'http://www.silverstripe.org/queued-jobs-module/</a>.'));
}
if (!is_array($searchableClasses)) {
$searchableClasses = array($searchableClasses);
}
foreach ($searchableClasses as $class) {
if (isset(self::$defaultColumns[$class])) {
Object::add_extension($class, "ZendSearchLuceneSearchable('" . self::$defaultColumns[$class] . "')");
} else {
user_error("I don't know the default search columns for class '{$class}'");
return;
}
}
Object::add_extension('ContentController', 'ZendSearchLuceneContentController');
DataObject::add_extension('SiteConfig', 'ZendSearchLuceneSiteConfig');
Object::add_extension('LeftAndMain', 'ZendSearchLuceneCMSDecorator');
Object::add_extension('StringField', 'ZendSearchLuceneTextHighlightDecorator');
// Set up default encoding and analyzer
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding(ZendSearchLuceneSearchable::$encoding);
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
}