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


PHP Handler::create方法代码示例

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


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

示例1: createContentType

 /**
  * Create a Content Type object.
  *
  * The content type is created in the state STATUS_DRAFT.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException In case when
  *         - array of content type groups does not contain at least one content type group
  *         - identifier or remoteId in the content type create struct already exists
  *         - there is a duplicate field identifier in the content type create struct
  *         - content type create struct does not contain at least one field definition create struct
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
  *         if a field definition in the $contentTypeCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeValidationException
  *         if a multiple field definitions of a same singular type are given
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $contentTypeGroups Required array of {@link ContentTypeGroup} to link type with (must contain one)
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
  */
 public function createContentType(APIContentTypeCreateStruct $contentTypeCreateStruct, array $contentTypeGroups)
 {
     // Prevent argument mutation
     $contentTypeCreateStruct = clone $contentTypeCreateStruct;
     $this->validateInputContentTypeCreateStruct($contentTypeCreateStruct);
     $this->validateInputContentTypeGroups($contentTypeGroups);
     $initialLanguageId = $this->repository->getContentLanguageService()->loadLanguage($contentTypeCreateStruct->mainLanguageCode)->id;
     try {
         $this->contentTypeHandler->loadByIdentifier($contentTypeCreateStruct->identifier);
         throw new InvalidArgumentException("\$contentTypeCreateStruct", "Another ContentType with identifier '{$contentTypeCreateStruct->identifier}' exists");
     } catch (APINotFoundException $e) {
         // Do nothing
     }
     if ($contentTypeCreateStruct->remoteId !== null) {
         try {
             $this->contentTypeHandler->loadByRemoteId($contentTypeCreateStruct->remoteId);
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Another ContentType with remoteId '{$contentTypeCreateStruct->remoteId}' exists");
         } catch (APINotFoundException $e) {
             // Do nothing
         }
     }
     $fieldDefinitionIdentifierSet = array();
     $fieldDefinitionPositionSet = array();
     foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
         // Check for duplicate identifiers
         if (!isset($fieldDefinitionIdentifierSet[$fieldDefinitionCreateStruct->identifier])) {
             $fieldDefinitionIdentifierSet[$fieldDefinitionCreateStruct->identifier] = true;
         } else {
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Argument contains duplicate field definition identifier '{$fieldDefinitionCreateStruct->identifier}'");
         }
         // Check for duplicate positions
         if (!isset($fieldDefinitionPositionSet[$fieldDefinitionCreateStruct->position])) {
             $fieldDefinitionPositionSet[$fieldDefinitionCreateStruct->position] = true;
         } else {
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Argument contains duplicate field definition position '{$fieldDefinitionCreateStruct->position}'");
         }
     }
     $allValidationErrors = array();
     $spiFieldDefinitions = array();
     $fieldTypeIdentifierSet = array();
     foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
         /** @var $fieldType \eZ\Publish\SPI\FieldType\FieldType */
         $fieldType = $this->repository->getFieldTypeService()->buildFieldType($fieldDefinitionCreateStruct->fieldTypeIdentifier);
         if ($fieldType->isSingular() && isset($fieldTypeIdentifierSet[$fieldDefinitionCreateStruct->fieldTypeIdentifier])) {
             throw new ContentTypeValidationException("FieldType '{$fieldDefinitionCreateStruct->fieldTypeIdentifier}' is singular and can't be repeated in a ContentType");
         }
         $fieldTypeIdentifierSet[$fieldDefinitionCreateStruct->fieldTypeIdentifier] = true;
         $fieldType->applyDefaultSettings($fieldDefinitionCreateStruct->fieldSettings);
         $fieldType->applyDefaultValidatorConfiguration($fieldDefinitionCreateStruct->validatorConfiguration);
         $validationErrors = $this->validateFieldDefinitionCreateStruct($fieldDefinitionCreateStruct, $fieldType);
         if (!empty($validationErrors)) {
             $allValidationErrors[$fieldDefinitionCreateStruct->identifier] = $validationErrors;
         }
         if (!empty($allValidationErrors)) {
             continue;
         }
         $spiFieldDefinitions[] = $this->buildSPIFieldDefinitionCreate($fieldDefinitionCreateStruct, $fieldType);
     }
     if (!empty($allValidationErrors)) {
         throw new ContentTypeFieldDefinitionValidationException($allValidationErrors);
     }
     $groupIds = array_map(function ($contentTypeGroup) {
         return $contentTypeGroup->id;
     }, $contentTypeGroups);
     if ($contentTypeCreateStruct->creatorId === null) {
         $contentTypeCreateStruct->creatorId = $this->repository->getCurrentUser()->id;
     }
     if ($contentTypeCreateStruct->creationDate === null) {
         $timestamp = time();
     } else {
         $timestamp = $contentTypeCreateStruct->creationDate->getTimestamp();
     }
     if ($contentTypeCreateStruct->remoteId === null) {
         $contentTypeCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentTypeCreateStruct);
     }
     $spiContentTypeCreateStruct = new SPIContentTypeCreateStruct(array("identifier" => $contentTypeCreateStruct->identifier, "name" => $contentTypeCreateStruct->names, "status" => APIContentType::STATUS_DRAFT, "description" => $contentTypeCreateStruct->descriptions === null ? array() : $contentTypeCreateStruct->descriptions, "created" => $timestamp, "modified" => $timestamp, "creatorId" => $contentTypeCreateStruct->creatorId, "modifierId" => $contentTypeCreateStruct->creatorId, "remoteId" => $contentTypeCreateStruct->remoteId, "urlAliasSchema" => $contentTypeCreateStruct->urlAliasSchema === null ? "" : $contentTypeCreateStruct->urlAliasSchema, "nameSchema" => $contentTypeCreateStruct->nameSchema === null ? "" : $contentTypeCreateStruct->nameSchema, "isContainer" => $contentTypeCreateStruct->isContainer === null ? false : $contentTypeCreateStruct->isContainer, "initialLanguageId" => $initialLanguageId, "sortField" => $contentTypeCreateStruct->defaultSortField === null ? Location::SORT_FIELD_PUBLISHED : $contentTypeCreateStruct->defaultSortField, "sortOrder" => $contentTypeCreateStruct->defaultSortOrder === null ? Location::SORT_ORDER_DESC : $contentTypeCreateStruct->defaultSortOrder, "groupIds" => $groupIds, "fieldDefinitions" => $spiFieldDefinitions, "defaultAlwaysAvailable" => $contentTypeCreateStruct->defaultAlwaysAvailable));
     $this->repository->beginTransaction();
     try {
         $spiContentType = $this->contentTypeHandler->create($spiContentTypeCreateStruct);
         $this->repository->commit();
//.........这里部分代码省略.........
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:101,代码来源:ContentTypeService.php

示例2: create

 /**
  * @param \eZ\Publish\SPI\Persistence\Content\Type\CreateStruct $createStruct
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Type
  */
 public function create(CreateStruct $createStruct)
 {
     $this->clearCache();
     return $this->innerHandler->create($createStruct);
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:10,代码来源:MemoryCachingHandler.php


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