Creates new instance based on the discriminator of source entity.

@param Localization $localization
@param string $name
@param PlaceHolder $source
@return PlaceHolder
168735
public static function factory(Localization $localization, $name, PlaceHolder $source = null)
	{
		$placeHolder = null;
		
		switch ($localization::DISCRIMINATOR) {
			case self::TEMPLATE_DISCR:
				$placeHolder = new TemplatePlaceHolder($name);
				break;
			case self::PAGE_DISCR:
			case self::APPLICATION_DISCR:
				$placeHolder = new PagePlaceHolder($name);
				break;
			default:
				throw new \LogicException("Not recognized discriminator value for entity [{$localization}]");
		}
		
		if ($source !== null) {
			foreach ($source->getBlocks() as $block) {
				if (! $block->getLocked()) {
					$placeHolder->addBlock(Block::factory($localization, $block));
				}
			}
		}

		return $placeHolder;
	}
1213497
public function createBaseRole($name, $translationKey, $isReadOnly = true, $makeGroup = false)
    {
        $role = new Role();
        $role->setName($name);
        $role->setTranslationKey($translationKey);
        $role->setReadOnly($isReadOnly);
        $role->setPersonalWorkspaceCreationEnabled(true);
        $role->setType(Role::PLATFORM_ROLE);
        $this->om->persist($role);

        if ($makeGroup) {
            $group = new Group();
            $group->setName($name);
            $group->setReadOnly($isReadOnly);
            $group->addRole($role);
            $this->om->persist($group);
        }

        $this->om->flush();

        return $role;
    }
21793
public static function factory(Localization $base, Block $source = null)
	{
		$block = null;

		switch ($base::DISCRIMINATOR) {
			case self::TEMPLATE_DISCR:
				$block = new TemplateBlock();
				break;
			case self::PAGE_DISCR:
			case self::APPLICATION_DISCR:
				$block = new PageBlock();
				break;
			default:
				throw new \LogicException("Not recognized discriminator value for entity [{$base}].");
		}

		if ($source !== null) {
			$block->setComponentClass($source->getComponentClass());
			$block->setPosition($source->getPosition());

			foreach ($source->getBlockProperties() as $blockProperty) {
				/* @var $blockProperty BlockProperty */

				$newBlockProperty = clone $blockProperty;

				$newBlockProperty->setLocalization($base);
				$newBlockProperty->setBlock($block);

				$block->getBlockProperties()
						->add($newBlockProperty);
			}
		}

		return $block;
	}
217056
protected function translateCategory(Locale $locale, CategoryInterface $category, $name)
    {
        /**
         * @var $translation \WellCommerce\Bundle\CategoryBundle\Entity\CategoryTranslation
         */
        $translation = $category->translate($locale->getCode());
        $slug        = $this->getLocaleSlug($locale, $name);
        $translation->setName($name);
        $translation->setSlug($slug);
        $category->mergeNewTranslations();
    }
809605
protected function createPlaceholder(string $name, string &$blockID = null): string
    {
        $blockID = $name . '-' . $this->compiler->generateID();

        //Short block declaration syntax (match with syntax)?
        return '${' . $blockID . '}';
    }
1174417
protected function createOrUpdateArticle(
        ArticleDocument $document,
        $locale,
        $localizationState = LocalizationState::LOCALIZED
    ) {
        $article = $this->findOrCreateViewDocument($document, $locale, $localizationState);
        if (!$article) {
            return;
        }

        $structureMetadata = $this->structureMetadataFactory->getStructureMetadata(
            'article',
            $document->getStructureType()
        );

        $article->setTitle($document->getTitle());
        $article->setRoutePath($document->getRoutePath());
        $this->setParentPageUuid($document, $article);
        $article->setChanged($document->getChanged());
        $article->setCreated($document->getCreated());
        $article->setAuthored($document->getAuthored());
        if ($document->getAuthor() && $author = $this->contactRepository->find($document->getAuthor())) {
            $article->setAuthorFullName($author->getFullName());
            $article->setAuthorId($author->getId());
        }
        if ($document->getChanger() && $changer = $this->userManager->getUserById($document->getChanger())) {
            $article->setChangerFullName($changer->getFullName());
            $article->setChangerContactId($changer->getContact()->getId());
        }
        if ($document->getCreator() && $creator = $this->userManager->getUserById($document->getCreator())) {
            $article->setCreatorFullName($creator->getFullName());
            $article->setCreatorContactId($creator->getContact()->getId());
        }
        $article->setType($this->getType($structureMetadata));
        $article->setStructureType($document->getStructureType());
        $article->setPublished($document->getPublished());
        $article->setPublishedState(WorkflowStage::PUBLISHED === $document->getWorkflowStage());
        $article->setTypeTranslation($this->getTypeTranslation($this->getType($structureMetadata)));
        $article->setLocalizationState(
            new LocalizationStateViewObject(
                $localizationState,
                (LocalizationState::LOCALIZED === $localizationState) ? null : $document->getLocale()
            )
        );

        $extensions = $document->getExtensionsData()->toArray();
        if (array_key_exists('excerpt', $extensions)) {
            $article->setExcerpt($this->excerptFactory->create($extensions['excerpt'], $document->getLocale()));
        }
        if (array_key_exists('seo', $extensions)) {
            $article->setSeo($this->seoFactory->create($extensions['seo']));
        }
        if ($structureMetadata->hasPropertyWithTagName('sulu.teaser.description')) {
            $descriptionProperty = $structureMetadata->getPropertyByTagName('sulu.teaser.description');
            $article->setTeaserDescription(
                $document->getStructure()->getProperty($descriptionProperty->getName())->getValue()
            );
        }
        if ($structureMetadata->hasPropertyWithTagName('sulu.teaser.media')) {
            $mediaProperty = $structureMetadata->getPropertyByTagName('sulu.teaser.media');
            $mediaData = $document->getStructure()->getProperty($mediaProperty->getName())->getValue();
            if (null !== $mediaData && array_key_exists('ids', $mediaData)) {
                $article->setTeaserMediaId(reset($mediaData['ids']) ?: null);
            }
        }

        $article->setContentData(json_encode($document->getStructure()->toArray()));

        $article->setMainWebspace($this->webspaceResolver->resolveMainWebspace($document));
        $article->setAdditionalWebspaces($this->webspaceResolver->resolveAdditionalWebspaces($document));

        $this->mapPages($document, $article);

        return $article;
    }
1001369
public function findByName( $name, $locale = null )
    {
        return $this->getMapper()
                    ->findByName( $name, $locale ?: $this->locale );
    }
998659
public static function fromString(string $input, string $locale): Resource
    {
        $data = json_decode($input, true);
        if (json_last_error() !== \JSON_ERROR_NONE) {
            if (function_exists('json_last_error_msg')) {
                throw new \InvalidArgumentException(json_last_error_msg(), json_last_error());
            }
            throw new \InvalidArgumentException("Error parsing JSON.", json_last_error());
        }

        return static::fromArray($data, $locale);
    }
729618
public function loadSource($locale, $group, $namespace = '*')
    {
        $dotArray = $this->translationRepository->loadSource($locale, $namespace, $group);
        $undot    = [];
        foreach ($dotArray as $item => $text) {
            array_set($undot, $item, $text);
        }
        return $undot;
    }
987957
protected function replaceWith(
        /*# string */ $name,
        /*# string */ $placeholder,
        array &$context
    )/*# : string */ {
        // exact match
        if (isset($context[$name])) {
            return $this->getString($context[$name]);
        }

        // something like user.name
        $first = explode('.', $name)[0];
        if (false !== strpos($name, '.') && isset($context[$first])) {
            return $this->getSubPart($name, $placeholder, $context[$first]);
        }

        // not found
        return $placeholder;
    }
396330
public function getLocalization($locale)
	{
		$localization = parent::getLocalization($locale);
		
		// Create fake localization if not persisted
		if (is_null($localization)) {
			$localization = $this->createLocalization($locale);
		}
		
		return $localization;
	}
250018
public static function create(Entry $entry, Locale $locale)
    {
        $result = new static();
        $result->entry = $entry;
        $result->locale = $locale;
        $result->comments = '';

        return $result;
    }
890442
private function createUserDaoProvider($name, $provider, ContainerBuilder $container)
    {
        $name = $this->getUserProviderId($name);

        // Doctrine Entity and In-memory DAO provider are managed by factories
        foreach ($this->userProviderFactories as $factory) {
            $key = str_replace('-', '_', $factory->getKey());

            if (!empty($provider[$key])) {
                $factory->create($container, $name, $provider[$key]);

                return $name;
            }
        }

        // Existing DAO service provider
        if (isset($provider['id'])) {
            $container->setAlias($name, new Alias($provider['id'], false));

            return $provider['id'];
        }

        // Chain provider
        if (isset($provider['chain'])) {
            $providers = [];
            foreach ($provider['chain']['providers'] as $providerName) {
                $providers[] = new Reference($this->getUserProviderId($providerName));
            }

            $container
                ->setDefinition($name, new ChildDefinition('security.user.provider.chain'))
                ->addArgument(new IteratorArgument($providers));

            return $name;
        }

        throw new InvalidConfigurationException(sprintf('Unable to create definition for "%s" user provider', $name));
    }
493947
static function create( $localeString = false )
    {
        if ( $localeString === false )
        {
            $ini = eZINI::instance();
            $localeString = $ini->variable( 'RegionalSettings', 'Locale' );
        }
        return new eZLocale( $localeString );
    }
76765
public function setPlaceholder($placeholder)
    {
        if ($placeholder === null || $placeholder === '') {
            $this->placeholder = '';
            return $this;
        }

        $this->placeholder = $this->translator()->translation($placeholder);
        if ($this->placeholder instanceof Translation) {
            $this->placeholder->isRendered = false;
        } else {
            $this->placeholder = '';
        }

        return $this;
    }
172600
private function setLocaleIdentifier(?string $localeIdentifier): self
    {
        $this->updatePropertyValue(
            LocaleIdentifierFieldInterface::PROP_LOCALE_IDENTIFIER,
            $localeIdentifier
        );

        return $this;
    }
1343
protected function createAttributeValueTranslation($name, $locale)
    {
        $translation = new AttributeValueTranslation();
        $translation->setName($name);
        $translation->setLocale($locale);

        return $translation;
    }