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


PHP Craft::app方法代码示例

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


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

示例1: actionIndex

 /**
  * Exports the Craft datamodel.
  *
  * @param string $file    file to write the schema to
  * @param array  $exclude Data to not export
  *
  * @return int
  */
 public function actionIndex($file = 'craft/config/schema.yml', array $exclude = null)
 {
     $dataTypes = Schematic::getExportableDataTypes();
     // If there are data exclusions.
     if ($exclude !== null) {
         // Find any invalid data to exclude.
         $invalidExcludes = array_diff($exclude, $dataTypes);
         // If any invalid exclusions were specified.
         if (count($invalidExcludes) > 0) {
             $errorMessage = 'Invalid exlude';
             if (count($invalidExcludes) > 1) {
                 $errorMessage .= 's';
             }
             $errorMessage .= ': ' . implode(', ', $invalidExcludes) . '.';
             $errorMessage .= ' Valid exclusions are ' . implode(', ', $dataTypes);
             // Output an error message outlining what invalid exclusions were specified.
             echo "\n" . $errorMessage . "\n\n";
             return 1;
         }
         // Remove any explicitly excluded data types from the list of data types to export.
         $dataTypes = array_diff($dataTypes, $exclude);
     }
     Craft::app()->schematic->exportToYaml($file, $dataTypes);
     Craft::log(Craft::t('Exported schema to {file}', ['file' => $file]));
     return 0;
 }
开发者ID:itmundi,项目名称:schematic,代码行数:34,代码来源:ExportCommand.php

示例2: getCraft

 /**
  * @return ConsoleApp|WebApp
  */
 protected function getCraft()
 {
     if (!$this->craft) {
         $this->craft = Craft::app();
     }
     return $this->craft;
 }
开发者ID:nerds-and-company,项目名称:craft-unit-test-suite,代码行数:10,代码来源:AbstractTest.php

示例3: import

 /**
  * Import asset source definitions.
  *
  * @param array $assetSourceDefinitions
  * @param bool  $force
  *
  * @return Result
  */
 public function import(array $assetSourceDefinitions, $force = false)
 {
     Craft::log(Craft::t('Importing Asset Sources'));
     foreach ($assetSourceDefinitions as $assetHandle => $assetSourceDefinition) {
         $assetSource = $this->populateAssetSource($assetHandle, $assetSourceDefinition);
         if (!Craft::app()->assetSources->saveSource($assetSource)) {
             $this->addErrors($assetSource->getAllErrors());
         }
     }
     return $this->getResultModel();
 }
开发者ID:ostark,项目名称:schematic,代码行数:19,代码来源:AssetSources.php

示例4: populate

 /**
  * @param array                $fieldDefinition
  * @param FieldModel           $field
  * @param string               $fieldHandle
  * @param FieldGroupModel|null $group
  */
 public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null)
 {
     parent::populate($fieldDefinition, $field, $fieldHandle, $group);
     $settings = $fieldDefinition['settings'];
     $defaultUploadLocationSourceId = $settings['defaultUploadLocationSource'];
     $defaultUploadLocationSource = Craft::app()->schematic_assetSources->getSourceTypeByHandle($defaultUploadLocationSourceId);
     $settings['defaultUploadLocationSource'] = $defaultUploadLocationSource ? $defaultUploadLocationSource->id : '';
     $singleUploadLocationSourceId = $settings['singleUploadLocationSource'];
     $singleUploadLocationSource = Craft::app()->schematic_assetSources->getSourceTypeByHandle($singleUploadLocationSourceId);
     $settings['singleUploadLocationSource'] = $singleUploadLocationSource ? $singleUploadLocationSource->id : '';
     $field->settings = $settings;
 }
开发者ID:ostark,项目名称:schematic,代码行数:18,代码来源:AssetsField.php

示例5: actionIndex

 /**
  * Imports the Craft datamodel.
  *
  * @param string $file          yml file containing the schema definition
  * @param string $override_file yml file containing the override values
  * @param bool   $force         if set to true items not in the import will be deleted
  *
  * @return int
  */
 public function actionIndex($file = 'craft/config/schema.yml', $override_file = 'craft/config/override.yml', $force = false)
 {
     if (!IOHelper::fileExists($file)) {
         $this->usageError(Craft::t('File not found.'));
     }
     $result = Craft::app()->schematic->importFromYaml($file, $override_file, $force);
     if (!$result->hasErrors()) {
         Craft::log(Craft::t('Loaded schema from {file}', ['file' => $file]));
         return 0;
     }
     Craft::log(Craft::t('There was an error loading schema from {file}', ['file' => $file]));
     print_r($result->getErrors());
     return 1;
 }
开发者ID:ostark,项目名称:schematic,代码行数:23,代码来源:ImportCommand.php

示例6: import

 /**
  * Attempt to import user settings.
  *
  * @param array $user_settings
  * @param bool  $force         If set to true user settings not included in the import will be deleted
  *
  * @return Result
  */
 public function import(array $user_settings, $force = true)
 {
     Craft::log(Craft::t('Importing Users'));
     // always delete existing fieldlayout first
     Craft::app()->fields->deleteLayoutsByType(ElementType::User);
     if (isset($user_settings['fieldLayout'])) {
         $fieldLayoutDefinition = (array) $user_settings['fieldLayout'];
     } else {
         $fieldLayoutDefinition = [];
     }
     $fieldLayout = Craft::app()->schematic_fields->getFieldLayout($fieldLayoutDefinition);
     $fieldLayout->type = ElementType::User;
     if (!Craft::app()->fields->saveLayout($fieldLayout)) {
         // Save fieldlayout via craft
         $this->addErrors($fieldLayout->getAllErrors());
     }
     return $this->getResultModel();
 }
开发者ID:ostark,项目名称:schematic,代码行数:26,代码来源:Users.php

示例7: isInstalled

 /**
  * Determines if Craft is installed by checking if the info table exists.
  *
  * @return bool
  */
 public function isInstalled()
 {
     if (!isset($this->_isInstalled)) {
         try {
             // First check to see if DbConnection has even been initialized, yet.
             if (Craft::app()->getComponent('db')) {
                 // If the db config isn't valid, then we'll assume it's not installed.
                 if (!Craft::app()->getIsDbConnectionValid()) {
                     return false;
                 }
             } else {
                 return false;
             }
         } catch (\Exception $e) {
             return false;
         }
         $this->_isInstalled = Craft::app()->db->tableExists('info', false);
     }
     return $this->_isInstalled;
 }
开发者ID:itmundi,项目名称:schematic,代码行数:25,代码来源:Schematic.php

示例8: testUsersServiceImportWithImportError

 /**
  * Test users service import.
  *
  * @covers ::import
  */
 public function testUsersServiceImportWithImportError()
 {
     $mockFieldsService = $this->getMockFieldServiceForImport(false);
     $mockSchematicFieldsService = $this->getMockSchematicFieldServiceForImport(true);
     $this->setComponent(Craft::app(), 'fields', $mockFieldsService);
     $this->setComponent(Craft::app(), 'schematic_fields', $mockSchematicFieldsService);
     $import = $this->schematicUsersService->import([]);
     $this->assertTrue($import instanceof Result);
     $this->assertTrue($import->hasErrors('errors'));
 }
开发者ID:itmundi,项目名称:schematic,代码行数:15,代码来源:UsersTest.php

示例9: testExport

 /**
  * Test export functionality.
  *
  * @covers ::export
  */
 public function testExport()
 {
     $data = $this->getLocaleData();
     $locales = [];
     foreach ($data as $id) {
         $locales[] = new LocaleModel($id);
     }
     $mockLocalizationService = $this->getMockLocalizationService($data, $locales);
     $this->setComponent(Craft::app(), 'i18n', $mockLocalizationService);
     $export = $this->schematicLocalesService->export();
     $this->assertEquals($data, $export);
 }
开发者ID:ostark,项目名称:schematic,代码行数:17,代码来源:LocalesTest.php

示例10: setMockDbConnection

 /**
  * @return Mock|DbConnection
  */
 private function setMockDbConnection()
 {
     $mockDbConnection = $this->getMockBuilder(DbConnection::class)->disableOriginalConstructor()->setMethods(['createCommand'])->getMock();
     $mockDbConnection->autoConnect = false;
     // Do not auto connect
     $mockDbCommand = $this->getMockDbCommand();
     $mockDbConnection->expects($this->any())->method('createCommand')->willReturn($mockDbCommand);
     Craft::app()->setComponent('db', $mockDbConnection);
     return $mockDbConnection;
 }
开发者ID:itmundi,项目名称:schematic,代码行数:13,代码来源:TagGroupsTest.php

示例11: getAssetSourceDefinition

 /**
  * @param AssetSourceModel $assetSource
  *
  * @return array
  */
 private function getAssetSourceDefinition(AssetSourceModel $assetSource)
 {
     return ['type' => $assetSource->type, 'name' => $assetSource->name, 'sortOrder' => $assetSource->sortOrder, 'settings' => $assetSource->settings, 'fieldLayout' => Craft::app()->schematic_fields->getFieldLayoutDefinition($assetSource->getFieldLayout())];
 }
开发者ID:itmundi,项目名称:schematic,代码行数:9,代码来源:AssetSources.php

示例12: setCraftComponent

 /**
  * @param string $handle
  * @param Mock   $mock
  */
 private function setCraftComponent($handle, Mock $mock)
 {
     $this->setComponent(Craft::app(), $handle, $mock);
 }
开发者ID:ostark,项目名称:schematic,代码行数:8,代码来源:SchematicTest.php

示例13: setMockPluginsService

 /**
  * @param array $schematicFieldModels
  */
 private function setMockPluginsService(array $schematicFieldModels)
 {
     $mockPluginsService = $this->getMockBuilder(PluginsService::class)->disableOriginalConstructor()->getMock();
     $mockPluginsService->expects($this->exactly(1))->method('call')->with('registerSchematicFieldModels')->willReturn($schematicFieldModels);
     $this->setComponent(Craft::app(), 'plugins', $mockPluginsService);
 }
开发者ID:ostark,项目名称:schematic,代码行数:9,代码来源:FieldFactoryTest.php

示例14: populateGlobalSet

 /**
  * Populate globalset.
  *
  * @param GlobalSetModel $globalSet
  * @param array          $globalSetDefinition
  * @param string         $globalSetHandle
  */
 private function populateGlobalSet(GlobalSetModel $globalSet, array $globalSetDefinition, $globalSetHandle)
 {
     $globalSet->setAttributes(['handle' => $globalSetHandle, 'name' => $globalSetDefinition['name']]);
     $fieldLayout = Craft::app()->schematic_fields->getFieldLayout($globalSetDefinition['fieldLayout']);
     $globalSet->setFieldLayout($fieldLayout);
 }
开发者ID:itmundi,项目名称:schematic,代码行数:13,代码来源:GlobalSets.php

示例15: getPrepareFieldLayout

 /**
  * Get a prepared fieldLayout for the craft assembleLayout function.
  *
  * @param array $fieldLayoutDef
  *
  * @return array
  */
 private function getPrepareFieldLayout(array $fieldLayoutDef)
 {
     $layoutFields = [];
     $requiredFields = [];
     foreach ($fieldLayoutDef as $fieldHandle => $required) {
         $field = Craft::app()->fields->getFieldByHandle($fieldHandle);
         if ($field instanceof FieldModel) {
             $layoutFields[] = $field->id;
             if ($required) {
                 $requiredFields[] = $field->id;
             }
         }
     }
     return ['fields' => $layoutFields, 'required' => $requiredFields];
 }
开发者ID:itmundi,项目名称:schematic,代码行数:22,代码来源:Fields.php


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