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


PHP ClassInfo::exists方法代码示例

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


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

示例1: onAfterWrite

 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this()->hasExtension(HasBlocks::class_name())) {
         /** @var \ManyManyList $existing */
         $existing = $this()->{HasBlocks::relationship_name()}();
         if ($this()->{self::SingleFieldName} || $this()->WasNew) {
             if ($defaultBlockClasses = $this->getDefaultBlockClasses()) {
                 // get class names along with count of each expected
                 $expected = array_count_values($defaultBlockClasses);
                 $sort = $existing->count() + 1;
                 foreach ($expected as $blockClass => $expectedCount) {
                     if (!\ClassInfo::exists($blockClass)) {
                         continue;
                     }
                     $existingCount = $existing->filter('ClassName', $blockClass)->count();
                     if ($existingCount < $expectedCount) {
                         for ($i = $existingCount; $i < $expectedCount; $i++) {
                             // generate a default title for the block from lang
                             // e.g. ContentBlock.DefaultTitle
                             $templateVars = ['pagetitle' => $this()->{Title::SingleFieldName}, 'singular' => singleton($blockClass)->i18n_singular_name(), 'index' => $i + 1];
                             // try the block class.DefaultTitle and then Block.DefaultTitle
                             $title = _t("{$blockClass}.DefaultTitle", _t('Block.DefaultTitle', '{pagetitle} {singular} - {index}', $templateVars), $templateVars);
                             /** @var Block $block */
                             $block = new $blockClass();
                             $block->update(['Title' => $title]);
                             $block->write();
                             $existing->add($block, ['Sort' => $sort++]);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-modular,代码行数:35,代码来源:AddDefaultBlocks.php

示例2: saveIntoDatabase

 /**
  * Mostly rewritten from parent, but allows circular dependencies - goes through the relation loop only after
  * the dictionary is fully populated.
  */
 public function saveIntoDatabase(DataModel $model)
 {
     // Custom plumbing: this has to be executed only once per fixture.
     $testDataTag = basename($this->fixtureFile);
     $this->latestVersion = DB::query("SELECT MAX(\"Version\") FROM \"TestDataTag\" WHERE \"FixtureFile\"='{$testDataTag}'")->value();
     // We have to disable validation while we import the fixtures, as the order in
     // which they are imported doesnt guarantee valid relations until after the
     // import is complete.
     $validationenabled = DataObject::get_validation_enabled();
     DataObject::set_validation_enabled(false);
     $parser = new Spyc();
     $fixtureContent = $parser->loadFile($this->fixtureFile);
     $this->fixtureDictionary = array();
     foreach ($fixtureContent as $dataClass => $items) {
         if (ClassInfo::exists($dataClass)) {
             $this->writeDataObject($model, $dataClass, $items);
         } else {
             $this->writeSQL($dataClass, $items);
         }
     }
     // Dictionary is now fully built, inject the relations.
     foreach ($fixtureContent as $dataClass => $items) {
         if (ClassInfo::exists($dataClass)) {
             $this->writeRelations($dataClass, $items);
         }
     }
     DataObject::set_validation_enabled($validationenabled);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-testdata,代码行数:32,代码来源:TestDataYamlFixture.php

示例3: getNestedController

 public function getNestedController()
 {
     if ($this->urlParams['URLSegment']) {
         $SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
         if (Translatable::is_enabled()) {
             $child = Translatable::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         } else {
             $child = DataObject::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         }
         if (!$child) {
             $child = $this->get404Page();
         }
         if ($child) {
             if (isset($_REQUEST['debug'])) {
                 Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
             }
             $controllerClass = "{$child->class}_Controller";
             if ($this->urlParams['Action'] && ClassInfo::exists($controllerClass . '_' . $this->urlParams['Action'])) {
                 $controllerClass = $controllerClass . '_' . $this->urlParams['Action'];
             }
             if (ClassInfo::exists($controllerClass)) {
                 $controller = new $controllerClass($child);
             } else {
                 $controller = $child;
             }
             $controller->setURLParams($this->urlParams);
             return $controller;
         } else {
             die("The requested page couldn't be found.");
         }
     } else {
         user_error("ModelAsController not geting a URLSegment.  It looks like the site isn't redirecting to home", E_USER_ERROR);
     }
 }
开发者ID:ramziammar,项目名称:websites,代码行数:34,代码来源:ModelAsController.php

示例4: assertException

 /**
  * @param callable $callback
  * @param string $expectedException
  * @param null $expectedCode
  * @param null $expectedMessage
  * @author VladaHejda
  */
 public static function assertException(callable $callback, $expectedException = 'Exception', $expectedCode = null, $expectedMessage = null)
 {
     $self = new SapphireTest();
     if (!ClassInfo::exists($expectedException)) {
         $self->fail(sprintf('An exception of type "%s" does not exist.', $expectedException));
     }
     try {
         $callback();
     } catch (\Exception $e) {
         $class = ClassInfo::class_name($e);
         $message = $e->getMessage();
         $code = $e->getCode();
         $errorMessage = 'Failed asserting the class of exception';
         if ($message && $code) {
             $errorMessage .= sprintf(' (message was %s, code was %d)', $message, $code);
         } elseif ($code) {
             $errorMessage .= sprintf(' (code was %d)', $code);
         }
         $errorMessage .= '.';
         $self->assertInstanceOf($expectedException, $e, $errorMessage);
         if ($expectedCode !== null) {
             $self->assertEquals($expectedCode, $code, sprintf('Failed asserting code of thrown %s.', $class));
         }
         if ($expectedMessage !== null) {
             $self->assertContains($expectedMessage, $message, sprintf('Failed asserting the message of thrown %s.', $class));
         }
         return;
     }
     $errorMessage = 'Failed asserting that exception';
     if (strtolower($expectedException) !== 'exception') {
         $errorMessage .= sprintf(' of type %s', $expectedException);
     }
     $errorMessage .= ' was thrown.';
     $self->fail($errorMessage);
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:42,代码来源:TestHelper.php

示例5: 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

示例6: updateSolrSearchableFields

 /**
  *	Retrieve the existing searchable fields, appending our custom search index to enable it.
  *	@return array
  */
 public function updateSolrSearchableFields(&$fields)
 {
     // Make sure the extension requirements have been met before enabling the custom search index.
     if (ClassInfo::exists('QueuedJob')) {
         $fields[$this->index] = true;
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-solr,代码行数:11,代码来源:SiteTreePermissionIndexExtension.php

示例7: getModifier

 /**
  * Retrieve a modifier of a given class for the order.
  * Modifier will be retrieved from database if it already exists,
  * or created if it is always required.
  *
  * @param string $className
  * @param boolean $forcecreate - force the modifier to be created.
  */
 public function getModifier($className, $forcecreate = false)
 {
     if (!ClassInfo::exists($className)) {
         user_error("Modifier class \"{$className}\" does not exist.");
     }
     //search for existing
     $modifier = $className::get()->filter("OrderID", $this->order->ID)->first();
     if ($modifier) {
         //remove if no longer valid
         if (!$modifier->valid()) {
             //TODO: need to provide feedback message - why modifier was removed
             $modifier->delete();
             $modifier->destroy();
             return null;
         }
         return $modifier;
     }
     $modifier = new $className();
     if ($modifier->required() || $forcecreate) {
         //create any modifiers that are required for every order
         $modifier->OrderID = $this->order->ID;
         $modifier->write();
         $this->order->Modifiers()->add($modifier);
         return $modifier;
     }
     return null;
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:35,代码来源:OrderTotalCalculator.php

示例8: getEditForm

 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $field = $form->Fields()->dataFieldByName($this->modelClass);
     if ($field) {
         $config = $field->getConfig();
         if (!ClassInfo::exists('GridFieldBetterButtonsItemRequest') && $this->IsEditingNews()) {
             $config->getComponentByType('GridFieldDetailForm')->setItemRequestClass('NewsGridFieldDetailForm_ItemRequest');
         }
         $singleton = singleton($this->modelClass);
         if (is_a($singleton, 'NewsPost') && ClassInfo::exists('GridFieldOrderableRows')) {
             $config->addComponent(new GridFieldOrderableRows('Sort'));
             $exportButton = $config->getComponentByType('GridFieldExportButton');
             if ($exportButton) {
                 $export = array('Title' => 'Title', 'DateTime' => 'DateTime', 'Author' => 'Author', 'ExportContent' => 'Content');
                 $this->extend('updateExportColumn', $export);
                 $exportButton->setExportColumns($export);
             }
         }
         $config->removeComponentsByType('GridFieldDeleteAction');
         $config->removeComponentsByType('GridFieldPaginator');
         $config->addComponent($pagination = new GridFieldPaginator(100));
     }
     return $form;
 }
开发者ID:silverstripers,项目名称:silverstripe-news,代码行数:25,代码来源:NewsAdmin.php

示例9: updateCMSFields

 public function updateCMSFields(FieldList $fields)
 {
     $sortable = singleton('CleanTeaser')->hasExtension('SortableDataExtension');
     $config = GridFieldConfig_RelationEditor::create();
     $config->addComponent($gridFieldForm = new GridFieldDetailForm());
     $dataFields = array();
     if (singleton('CleanTeaser')->hasExtension('CMSPublishableDataExtension')) {
         $dataFields['PublishIndicator'] = 'Published';
     }
     $dataFields = array_merge($dataFields, array('Thumbnail' => 'Thumbnail', 'Title' => 'Title', 'CleanDescription' => 'Description'));
     $config->getComponentByType('GridFieldDataColumns')->setDisplayFields($dataFields);
     $gridFieldForm->setTemplate('CMSGridFieldPopupForms');
     if ($sortable) {
         $config->addComponent(new GridFieldSortableRows('SortOrder'));
     }
     if (ClassInfo::exists('GridFieldBulkUpload')) {
         $iu = new GridFieldBulkUpload('ImageID');
         if (singleton('CleanTeaser')->hasExtension('ControlledFolderDataExtension')) {
             $iu->setUfConfig('folderName', singleton('CleanTeaser')->getUploadFolder());
         } else {
             $iu->setUfConfig('folderName', CleanTeaser::$upload_folder);
         }
         $config->addComponent($iu);
     }
     if ($sortable) {
         $data = $this->owner->CleanTeasers("ClassName = 'CleanTeaser'")->sort('SortOrder');
     } else {
         $data = $this->owner->CleanTeasers("ClassName = 'CleanTeaser'");
     }
     // $config->removeComponentsByType('GridFieldAddNewButton');
     // if (ClassInfo::exists('GridFieldBulkUpload')) {
     // 	$config->addComponent(new GridFieldAddNewMultiClass());
     // }
     $fields->addFieldToTab("Root.Teasers", GridField::create('CleanTeasers', 'CleanTeaser', $data, $config));
 }
开发者ID:arillo,项目名称:silverstripe-cleanutilities,代码行数:35,代码来源:CleanTeasersExtension.php

示例10: getRemoteObject

 protected function getRemoteObject($node)
 {
     $clazz = $node->nodeName;
     $object = null;
     // do we have this data object type?
     if (ClassInfo::exists($clazz)) {
         // we'll create one
         $object = new $clazz();
     } else {
         $object = new Page();
     }
     // track the name property and set it LAST again to handle special cases like file
     // that overwrite other properties when $name is set
     $name = null;
     foreach ($node->childNodes as $property) {
         if ($property instanceof DOMText) {
             continue;
         }
         $pname = $property->nodeName;
         if (isset($this->remap[$pname])) {
             $pname = $this->remap[$pname];
         }
         if ($pname == 'Filename') {
             $name = $property->nodeValue;
         }
         $object->{$pname} = $property->nodeValue;
     }
     $object->SourceClassName = $clazz;
     if (!is_null($name)) {
         $object->Filename = $name;
     }
     return $object;
 }
开发者ID:nyeholt,项目名称:silverstripe-connector,代码行数:33,代码来源:SilverStripeClient.php

示例11: process

 /**
  * To process this job, we need to get the next page whose ID is the next greater than the last
  * processed. This way we don't need to remember a bunch of data about what we've processed
  */
 public function process()
 {
     if (ClassInfo::exists('Subsite')) {
         Subsite::disable_subsite_filter();
     }
     $class = $this->reindexType;
     $pages = $class::get();
     $pages = $pages->filter(array('ID:GreaterThan' => $this->lastIndexedID));
     $pages = $pages->limit(Config::inst()->get(__CLASS__, 'at_a_time'));
     $pages = $pages->sort('ID ASC');
     if (ClassInfo::exists('Subsite')) {
         Subsite::$disable_subsite_filter = false;
     }
     if (!$pages || !$pages->count()) {
         $this->isComplete = true;
         return;
     }
     $mode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // index away
     $service = singleton('SolrSearchService');
     $live = array();
     $stage = array();
     $all = array();
     foreach ($pages as $page) {
         // Make sure the current page is not orphaned.
         if ($page->ParentID > 0) {
             $parent = $page->getParent();
             if (is_null($parent) || $parent === false) {
                 continue;
             }
         }
         // Appropriately index the current page, taking versioning into account.
         if ($page->hasExtension('Versioned')) {
             $stage[] = $page;
             $base = $page->baseTable();
             $idField = '"' . $base . '_Live"."ID"';
             $livePage = Versioned::get_one_by_stage($page->ClassName, 'Live', $idField . ' = ' . $page->ID);
             if ($livePage) {
                 $live[] = $livePage;
             }
         } else {
             $all[] = $page;
         }
         $this->lastIndexedID = $page->ID;
     }
     if (count($all)) {
         $service->indexMultiple($all);
     }
     if (count($stage)) {
         $service->indexMultiple($stage, 'Stage');
     }
     if (count($live)) {
         $service->indexMultiple($live, 'Live');
     }
     Versioned::set_reading_mode($mode);
     $this->lastIndexedID = $page->ID;
     $this->currentStep += $pages->count();
 }
开发者ID:nyeholt,项目名称:silverstripe-solr,代码行数:63,代码来源:SolrReindexJob.php

示例12: getCMSFields

 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if (ClassInfo::exists('GridFieldOrderableRows')) {
         $fields->dataFieldByName('Tasks')->getConfig()->addComponent(new GridFieldOrderableRows('Sort'));
     }
     return $fields;
 }
开发者ID:muskie9,项目名称:todo-list,代码行数:8,代码来源:TodoList.php

示例13: remove_weight

 public static function remove_weight($weight)
 {
     self::$weights = array_diff(self::$weights, array($weight));
     $class = "NewsWeight{$weight}";
     if (ClassInfo::exists($class)) {
         Object::remove_extension('NewsHolder', $class);
     }
 }
开发者ID:redema,项目名称:silverstripe-news,代码行数:8,代码来源:NewsPage.php

示例14: testRegularExpressionReplacement

 /**
  *	The test to ensure the regular expression replacement is correct.
  */
 public function testRegularExpressionReplacement()
 {
     // Instantiate a link mapping to use.
     $mapping = LinkMapping::create(array('LinkType' => 'Regular Expression', 'MappedLink' => '^www\\.wrong\\.com(/page)?/(index){1}\\.php$', 'RedirectLink' => 'https://www.correct.com$1'));
     $mapping->setMatchedURL('www.wrong.com/page/index.php');
     // Determine whether the regular expression replacement is correct.
     $this->assertEquals($mapping->getLink(), ClassInfo::exists('Multisites') ? 'https://www.correct.com/page?misdirected=1' : 'https://www.correct.com/page');
 }
开发者ID:nyeholt,项目名称:silverstripe-misdirection,代码行数:11,代码来源:MisdirectionUnitTests.php

示例15: setValue

 function setValue($value, $record = null)
 {
     $parts = explode(":", $value);
     if (!is_array($parts) || count($parts) != 2 || !ClassInfo::exists($parts[0]) || !is_numeric($parts[1])) {
         return;
     }
     $this->value = DataObject::get_by_id($parts[0], $parts[1]);
 }
开发者ID:helpfulrobot,项目名称:mrmorphic-neolayout,代码行数:8,代码来源:NLObjectReference.php


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