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


PHP singleton函数代码示例

本文整理汇总了PHP中singleton函数的典型用法代码示例。如果您正苦于以下问题:PHP singleton函数的具体用法?PHP singleton怎么用?PHP singleton使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 /**
  * @param Controller $controller
  * @param Job $job (optional)
  */
 public function __construct($controller, $job = null)
 {
     if ($job) {
         $fields = $job->getFields();
         $required = $job->getValidator();
     } else {
         $fields = singleton('Job')->getFields();
         $required = singleton('Job')->getValidator();
     }
     $fields->merge(new FieldList(new LiteralField('Conditions', $controller->TermsAndConditionsText), new HiddenField('BackURL', '', $controller->Link('thanks')), new HiddenField('EmailFrom', '', $controller->getJobEmailFromAddress()), new HiddenField('EmailSubject', '', $controller->getJobEmailSubject()), $jobId = new HiddenField('JobID')));
     if ($job) {
         $jobId->setValue($job->ID);
         $actions = new FieldList(new FormAction('doEditJob', _t('Jobboard.EDITLISTING', 'Edit Listing')));
     } else {
         $actions = new FieldList(new FormAction('doAddJob', _t('JobBoard.CONFIRM', 'Confirm')));
     }
     parent::__construct($controller, 'AddJobForm', $fields, $actions, $required);
     $this->setFormAction('JobBoardFormProcessor/doJobForm');
     $this->setFormMethod('POST');
     if ($job) {
         $this->loadDataFrom($job);
     } else {
         $this->enableSpamProtection();
     }
 }
开发者ID:helpfulrobot,项目名称:fullscreeninteractive-silverstripe-jobboard,代码行数:29,代码来源:JobBoardForm.php

示例2: init

 /**
  * Loads the requirements, checks perms, etc. If an ID is in the URL, that becomes the
  * current folder.
  */
 public function init()
 {
     parent::init();
     if (!Permission::check("ADMIN") && !Permission::check("CMS_ACCESS_BrowseFiles")) {
         return Security::permissionFailure($this, _t('KickAssets.PERMISSIONFAIL', 'You do not have permission to access this section of the CMS.'));
     }
     Requirements::clear();
     Requirements::css('kickassets/css/core.css');
     Requirements::css('kickassets/css/kickassets.css');
     Requirements::javascript('kickassets/javascript/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
     Requirements::javascript('kickassets/javascript/apprise/apprise-1.5.full.js');
     Requirements::javascript('kickassets/javascript/jquery.tooltip.js');
     Requirements::css('kickassets/javascript/apprise/apprise.css');
     Requirements::javascript('kickassets/javascript/kickassets_ui.js');
     Requirements::javascript('kickassets/javascript/chosen/chosen.jquery.js');
     Requirements::css('kickassets/javascript/chosen/chosen.css');
     Requirements::javascript('kickassets/javascript/jquery.form.js');
     Requirements::javascript('kickassets/javascript/kickassets.js');
     Requirements::css('kickassets/css/kickassets_ui.css');
     if ($this->getRequest()->param('ID')) {
         $this->currentFolder = DataObject::get_by_id("Folder", (int) $this->getRequest()->param('ID'));
         $this->currentPath = KickAssetUtil::relative_asset_dir($this->currentFolder->Filename);
     } else {
         $this->currentFolder = singleton('Folder');
         $this->currentPath = false;
     }
 }
开发者ID:heyday,项目名称:KickAssets,代码行数:32,代码来源:KickAssetAdmin.php

示例3: updateEditForm

 public function updateEditForm($form)
 {
     $singl = singleton($this->owner->modelClass);
     if ($singl->hasExtension('SoftDeletable')) {
         /* @var $gridfield GridField */
         $gridfield = $form->Fields()->dataFieldByName($this->owner->modelClass);
         $config = $gridfield->getConfig();
         $config->removeComponentsByType('GridFieldDeleteAction');
         if ($this->owner->config()->softdelete_from_list) {
             $config->addComponent(new GridFieldSoftDeleteAction());
         }
         $bulkManager = $config->getComponentByType('GridFieldBulkManager');
         if ($bulkManager && $this->owner->config()->softdelete_from_bulk) {
             $bulkManager->removeBulkAction('delete');
             $bulkManager->addBulkAction('softDelete', 'delete (soft)', 'GridFieldBulkSoftDeleteEventHandler');
         }
         if ($this->filtersOnDeleted()) {
             /* @var $cols GridFieldDataColumns */
             $cols = $gridfield->getConfig()->getComponentByType('GridFieldDataColumns');
             $displayedFields = $cols->getDisplayFields($gridfield);
             $displayedFields['Deleted'] = 'Deleted';
             $cols->setDisplayFields($displayedFields);
         }
     }
     return $form;
 }
开发者ID:lekoala,项目名称:silverstripe-softdelete,代码行数:26,代码来源:SoftDeleteModelAdmin.php

示例4: SearchForm

 /**
  * Manipulate search form to add some grouping.
  * 
  * @return void
  *
  * @author Sebastian Diel <sdiel@pixeltricks.de>
  * @since 25.06.2014
  */
 public function SearchForm()
 {
     $searchForm = parent::SearchForm();
     $fields = $searchForm->Fields();
     $order = singleton('SilvercartOrder');
     $basicLabelField = new HeaderField('BasicLabelField', $order->fieldLabel('BasicData'));
     $customerLabelField = new HeaderField('CustomerLabelField', $order->fieldLabel('CustomerData'));
     $positionLabelField = new HeaderField('PositionLabelField', $order->fieldLabel('OrderPositionData'));
     $miscLabelField = new HeaderField('MiscLabelField', $order->fieldLabel('MiscData'));
     $origOrderStatusField = $fields->dataFieldByName('q[SilvercartOrderStatus__ID]');
     $orderStatusField = new SilvercartMultiDropdownField('q[SilvercartOrderStatus__ID]', $origOrderStatusField->Title(), $origOrderStatusField->getSource());
     $positionQuantityField = new TextField('q[OrderPositionQuantity]', $order->fieldLabel('OrderPositionQuantity'));
     $positionIsLimitField = new CheckboxField('q[OrderPositionIsLimit]', $order->fieldLabel('OrderPositionIsLimit'));
     $limitField = new TextField('q[SearchResultsLimit]', $order->fieldLabel('SearchResultsLimit'));
     $fields->insertBefore($basicLabelField, 'q[OrderNumber]');
     $fields->insertAfter($fields->dataFieldByName('q[Created]'), 'q[OrderNumber]');
     $fields->insertAfter($orderStatusField, 'q[IsSeen]');
     $fields->insertBefore($customerLabelField, 'q[Member__CustomerNumber]');
     $fields->insertBefore($positionLabelField, 'q[SilvercartOrderPositions__ProductNumber]');
     $fields->insertAfter($positionQuantityField, 'q[SilvercartOrderPositions__ProductNumber]');
     $fields->insertAfter($positionIsLimitField, 'q[OrderPositionQuantity]');
     $fields->insertAfter($miscLabelField, 'q[OrderPositionIsLimit]');
     $fields->insertAfter($limitField, 'q[MiscLabelField]');
     $fields->dataFieldByName('q[SilvercartOrderStatus__ID]')->setEmptyString(_t('SilvercartOrderSearchForm.PLEASECHOOSE'));
     $fields->dataFieldByName('q[SilvercartPaymentMethod__ID]')->setEmptyString(_t('SilvercartOrderSearchForm.PLEASECHOOSE'));
     $fields->dataFieldByName('q[SilvercartShippingMethod__ID]')->setEmptyString(_t('SilvercartOrderSearchForm.PLEASECHOOSE'));
     $fields->dataFieldByName('q[SilvercartShippingAddress__SilvercartCountry__ID]')->setEmptyString(_t('SilvercartOrderSearchForm.PLEASECHOOSE'));
     return $searchForm;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:37,代码来源:SilvercartOrderAdmin.php

示例5: scaffoldFormField

 public function scaffoldFormField($title = null, $params = null)
 {
     if (empty($this->object)) {
         return null;
     }
     $relationName = substr($this->name, 0, -2);
     $hasOneClass = $this->object->hasOneComponent($relationName);
     if ($hasOneClass && singleton($hasOneClass) instanceof Image) {
         $field = new UploadField($relationName, $title);
         $field->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
     } elseif ($hasOneClass && singleton($hasOneClass) instanceof File) {
         $field = new UploadField($relationName, $title);
     } else {
         $titleField = singleton($hasOneClass)->hasField('Title') ? "Title" : "Name";
         $list = DataList::create($hasOneClass);
         // Don't scaffold a dropdown for large tables, as making the list concrete
         // might exceed the available PHP memory in creating too many DataObject instances
         if ($list->count() < 100) {
             $field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
             $field->setEmptyString(' ');
         } else {
             $field = new NumericField($this->name, $title);
         }
     }
     return $field;
 }
开发者ID:sledziator,项目名称:silverstripe-framework,代码行数:26,代码来源:ForeignKey.php

示例6: updateWiki

 /**
  * Updates the database of a calitrix wiki from beta 1 to beta 2.
  *
  * @author Johannes Klose <exe@calitrix.de>
  * @return void
  **/
 function updateWiki()
 {
     $tpl =& singleton('template');
     $setPath = isset($this->post['set_dir']) ? trim($this->post['set_dir']) : '';
     $dbFile = $setPath . '/dbconfig.php';
     $setFile = $setPath . '/stdconfig.php';
     if (!file_exists($dbFile) || !file_exists($setFile)) {
         $tpl->assign('isError', true);
         $tpl->assign('error', $this->lang['updateb1_config_failed']);
         return false;
     }
     include $dbFile;
     mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME);
     mysql_query('CREATE TABLE ' . DB_PREFIX . 'config(config_section VARCHAR(30) NOT NULL, config_item ' . 'VARCHAR(100) NOT NULL, config_value TEXT NOT NULL, PRIMARY KEY (config_section, config_item))');
     mysql_query('UPDATE ' . DB_PREFIX . 'users SET user_access_mask = -1 WHERE user_access_mask = 0');
     $cfg = $this->createConfigTable($setFile);
     $cfg = $this->createConfigFile($cfg, $setFile);
     if ($cfg === false) {
         $tpl->assign('isError', true);
         $tpl->assign('error', sprintf($this->lang['updateb1_update_failed'], mysql_error()));
         return false;
     }
     $this->lockInstaller();
     $tpl->assign('updated', true);
 }
开发者ID:BackupTheBerlios,项目名称:calitrixwiki,代码行数:32,代码来源:installer_updateb1.php

示例7: testHasDatabaseFieldOnDataObject

 public function testHasDatabaseFieldOnDataObject()
 {
     $obj = singleton('CompositeDBFieldTest_DataObject');
     $this->assertTrue($obj->hasDatabaseField('MyMoneyAmount'));
     $this->assertTrue($obj->hasDatabaseField('MyMoneyCurrency'));
     $this->assertFalse($obj->hasDatabaseField('MyMoney'));
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:7,代码来源:CompositeDBFieldTest.php

示例8: getDisplayFields

 /**
  * Get the DisplayFields
  * 
  * @return array
  * @see GridFieldDataColumns::setDisplayFields
  */
 public function getDisplayFields($gridField)
 {
     if (!$this->displayFields) {
         return singleton($gridField->getModelClass())->summaryFields();
     }
     return $this->displayFields;
 }
开发者ID:jareddreyer,项目名称:catalogue,代码行数:13,代码来源:GridFieldDataColumns.php

示例9: getCMSFields

 /**
  * Get the fieldset to display in the administration section
  */
 function getCMSFields()
 {
     $templateSource = singleton("NewsletterAdmin")->templateSource();
     $fields = new FieldSet(new TabSet("Root", new Tab(_t('NewsletterAdmin.NLSETTINGS', 'Newsletter Settings'), new TextField("Title", _t('NewsletterAdmin.NEWSLTYPE', 'Newsletter Type')), new TreeDropdownField('GroupID', _T('NewsletterAdmin.MAILINGGROUP', 'Mailing list group'), 'Group'), new TextField("FromEmail", _t('NewsletterAdmin.FROMEM', 'From email address')), new DropdownField("Template", _t('NewsletterAdmin.TEMPLATE', 'Template'), $templateSource))));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
开发者ID:nyeholt,项目名称:silverstripe-newsletter,代码行数:10,代码来源:NewsletterType.php

示例10: process

 public function process()
 {
     $object = $this->getDataObject();
     if ($object) {
         $object->onScheduledExecution();
         // figure out what our rescheduled date should be
         $timeStr = $object->ExecuteFree;
         if ($object->ExecuteEvery) {
             $executeInterval = $object->ExecuteInterval;
             if (!$executeInterval || !is_numeric($executeInterval)) {
                 $executeInterval = 1;
             }
             $timeStr = '+' . $executeInterval . ' ' . $object->ExecuteEvery;
         }
         $next = strtotime($timeStr);
         if ($next > time()) {
             // in the future
             $nextGen = date('Y-m-d H:i:s', $next);
             $nextId = singleton('QueuedJobService')->queueJob(new ScheduledExecutionJob($object, $this->timesExecuted + 1), $nextGen);
             $object->ScheduledJobID = $nextId;
             $object->write();
         }
     }
     $this->currentStep++;
     $this->isComplete = true;
 }
开发者ID:tim-lar,项目名称:silverstripe-queuedjobs,代码行数:26,代码来源:ScheduledExecutionJob.php

示例11: show_timeSheetItems

function show_timeSheetItems($template_name)
{
    global $date_to_view;
    $current_user =& singleton("current_user");
    global $TPL;
    $query = prepare("SELECT * \n                      FROM timeSheetItem \n                           LEFT JOIN timeSheet ON timeSheetItem.timeSheetID = timeSheet.timeSheetID\n                           LEFT JOIN project ON timeSheet.projectID = project.projectID\n                      WHERE dateTimeSheetItem='%s'\n                            AND timeSheet.personID=%d", date("Y-m-d", $date_to_view), $current_user->get_id());
    $db = new db_alloc();
    $db->query($query);
    while ($db->next_record()) {
        $timeSheetItem = new timeSheetItem();
        $timeSheetItem->read_db_record($db);
        $timeSheetItem->set_values();
        if ($timeSheetItem->get_value("unit") == "Hour") {
            $TPL["daily_hours_total"] += $timeSheetItem->get_value("timeSheetItemDuration");
        }
        $project = new project();
        $project->read_db_record($db);
        $project->set_values();
        if ($project->get_value("projectShortName")) {
            $TPL["item_description"] = $project->get_value("projectShortName");
        } else {
            $TPL["item_description"] = $project->get_value("projectName");
        }
        include_template($template_name);
    }
}
开发者ID:cjbayliss,项目名称:alloc,代码行数:26,代码来源:weeklyTime.php

示例12: create_gridfield_for

 /**
  * A simple Gridfield factory
  * @param  string $model
  * @param  string $relationname
  * @param  DataObject $reference
  * @return GridField
  */
 public static function create_gridfield_for($model, $relationname, $reference)
 {
     if ($relationname != null && ClassInfo::exists($model)) {
         $config = GridFieldConfig_RelationEditor::create();
         $config->addComponent($gridFieldForm = new GridFieldDetailForm());
         if ($items = $reference->{$relationname}()) {
             if (is_a($items, 'ManyManyList') && ClassInfo::exists('GridFieldManyRelationHandler')) {
                 $config->addComponent(new GridFieldManyRelationHandler(), 'GridFieldPaginator');
             } else {
                 $sortable = singleton($model)->hasExtension('SortableDataExtension');
                 if ($sortable) {
                     $config->addComponent(new GridFieldSortableRows('SortOrder'));
                 }
             }
             $gridfield = GridField::create($relationname, $model, $items, $config);
             $datacolumns = $gridfield->getConfig()->getComponentByType('GridFieldDataColumns');
             $cfields = singleton($model)->summaryFields();
             if (singleton($model)->hasExtension('CMSPublishableDataExtension') && !isset($cfields['PublishStatus'])) {
                 $cfields = array('PublishStatus' => 'PublishStatus') + $cfields;
             }
             $datacolumns->setDisplayFields($cfields);
             return $gridfield;
         } else {
             throw new InvalidArgumentException("Couldn't find relation.");
         }
     } else {
         throw new InvalidArgumentException("Couldn't create GridField because wrong parameters passed to the factory.");
     }
 }
开发者ID:helpfulrobot,项目名称:arillo-silverstripe-cleanutilities,代码行数:36,代码来源:CleanUtils.php

示例13: installDatabase

 /**
  * Installs the database.
  *
  * @author Johannes Klose <exe@calitrix.de>
  * @param  bool $defaultPages Enables installation of default wiki pages if set to true
  * @return void
  **/
 function installDatabase($defaultPages)
 {
     $tpl =& singleton('template');
     include CWIKI_INSTALL_DIR . '/mysql.php';
     include CWIKI_SET_DIR . '/dbconfig.php';
     mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME);
     foreach ($struct as $tbl => $sql) {
         if (!@mysql_query('CREATE TABLE ' . DB_PREFIX . $tbl . $sql)) {
             return false;
         }
     }
     if (count($tableConflict) > 0) {
         $tpl->assign('isError', true);
         $tpl->assign('error', sprintf($this->lang['install_conflict'], join(', ', $tableConflict)));
     }
     foreach ($data['groups'] as $sql) {
         if (!@mysql_query('INSERT INTO ' . DB_PREFIX . 'groups' . $sql)) {
             return false;
         }
     }
     unset($data['groups']);
     if ($defaultPages) {
         foreach ($data as $tbl => $stmts) {
             foreach ($stmts as $sql) {
                 if (!@mysql_query('INSERT INTO ' . DB_PREFIX . $tbl . $sql)) {
                     return false;
                 }
             }
         }
     }
     return $this->createConfigTable();
 }
开发者ID:BackupTheBerlios,项目名称:calitrixwiki,代码行数:40,代码来源:installer_install.php

示例14: updateImportForm

 function updateImportForm(Form $form)
 {
     /* @var $owner ModelAdmin */
     $owner = $this->owner;
     $class = $owner->modelClass;
     // Overwrite model imports
     $importerClasses = $owner->stat('model_importers');
     if (is_null($importerClasses)) {
         $models = $owner->getManagedModels();
         foreach ($models as $modelName => $options) {
             $importerClasses[$modelName] = 'ExcelBulkLoader';
         }
         $owner->set_stat('model_importers', $importerClasses);
     }
     $modelSNG = singleton($class);
     $modelName = $modelSNG->i18n_singular_name();
     $fields = $form->Fields();
     $content = _t('ModelAdminExcelExtension.DownloadSample', '<div class="field"><a href="{link}">Download sample file</a></div>', array('link' => $owner->Link($class . '/downloadsample')));
     $file = $fields->dataFieldByName('_CsvFile');
     if ($file) {
         $file->setDescription(ExcelImportExport::getValidExtensionsText());
         $file->getValidator()->setAllowedExtensions(ExcelImportExport::getValidExtensions());
     }
     $fields->removeByName("SpecFor{$modelName}");
     $fields->insertAfter('EmptyBeforeImport', new LiteralField("SampleFor{$modelName}", $content));
     if (!$modelSNG->canDelete()) {
         $fields->removeByName('EmptyBeforeImport');
     }
     $actions = $form->Actions();
     $import = $actions->dataFieldByName('action_import');
     if ($import) {
         $import->setTitle(_t('ModelAdminExcelExtension.ImportExcel', "Import from Excel"));
     }
 }
开发者ID:lekoala,项目名称:silverstripe-excel-import-export,代码行数:34,代码来源:ModelAdminExcelExtension.php

示例15: scaffoldFormField

 public function scaffoldFormField($title = null, $params = null)
 {
     if (empty($this->object)) {
         return null;
     }
     $relationName = substr($this->name, 0, -2);
     $hasOneClass = DataObject::getSchema()->hasOneComponent(get_class($this->object), $relationName);
     if (empty($hasOneClass)) {
         return null;
     }
     $hasOneSingleton = singleton($hasOneClass);
     if ($hasOneSingleton instanceof File) {
         $field = new UploadField($relationName, $title);
         if ($hasOneSingleton instanceof Image) {
             $field->setAllowedFileCategories('image/supported');
         }
         return $field;
     }
     // Build selector / numeric field
     $titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name";
     $list = DataList::create($hasOneClass);
     // Don't scaffold a dropdown for large tables, as making the list concrete
     // might exceed the available PHP memory in creating too many DataObject instances
     if ($list->count() < 100) {
         $field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
         $field->setEmptyString(' ');
     } else {
         $field = new NumericField($this->name, $title);
     }
     return $field;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:31,代码来源:DBForeignKey.php


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