"Fossies" - the Fresh Open Source Software Archive

Member "neos-development-collection-7.0.1/Neos.ContentRepository/Classes/Migration/Service/NodeTransformation.php" (23 Feb 2021, 4626 Bytes) of package /linux/www/neos-development-collection-7.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "NodeTransformation.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 namespace Neos\ContentRepository\Migration\Service;
    3 
    4 /*
    5  * This file is part of the Neos.ContentRepository package.
    6  *
    7  * (c) Contributors of the Neos Project - www.neos.io
    8  *
    9  * This package is Open Source Software. For the full copyright and license
   10  * information, please view the LICENSE file which was distributed with this
   11  * source code.
   12  */
   13 
   14 use Neos\Flow\Annotations as Flow;
   15 use Neos\Flow\ObjectManagement\ObjectManagerInterface;
   16 use Neos\Utility\ObjectAccess;
   17 use Neos\ContentRepository\Domain\Model\NodeData;
   18 use Neos\ContentRepository\Migration\Exception\MigrationException;
   19 use Neos\ContentRepository\Migration\Transformations\TransformationInterface;
   20 
   21 /**
   22  * Service that executes a series of configured transformations on a node.
   23  *
   24  * @Flow\Scope("singleton")
   25  */
   26 class NodeTransformation
   27 {
   28     /**
   29      * @Flow\Inject
   30      * @var ObjectManagerInterface
   31      */
   32     protected $objectManager;
   33 
   34     /**
   35      * @var array<\Neos\ContentRepository\Migration\Transformations\TransformationInterface>
   36      */
   37     protected $transformationConjunctions = [];
   38 
   39     /**
   40      * Executes all configured transformations starting on the given node.
   41      *
   42      * @param NodeData $nodeData
   43      * @param array $transformationConfigurations
   44      * @return void
   45      */
   46     public function execute(NodeData $nodeData, array $transformationConfigurations)
   47     {
   48         $transformationConjunction = $this->buildTransformationConjunction($transformationConfigurations);
   49         foreach ($transformationConjunction as $transformation) {
   50             if ($transformation->isTransformable($nodeData)) {
   51                 $transformation->execute($nodeData);
   52             }
   53         }
   54     }
   55 
   56     /**
   57      * @param array $transformationConfigurations
   58      * @return array<\Neos\ContentRepository\Migration\Transformations\TransformationInterface>
   59      */
   60     protected function buildTransformationConjunction(array $transformationConfigurations)
   61     {
   62         $conjunctionIdentifier = md5(serialize($transformationConfigurations));
   63         if (isset($this->transformationConjunctions[$conjunctionIdentifier])) {
   64             return $this->transformationConjunctions[$conjunctionIdentifier];
   65         }
   66 
   67         $conjunction = [];
   68         foreach ($transformationConfigurations as $transformationConfiguration) {
   69             $conjunction[] = $this->buildTransformationObject($transformationConfiguration);
   70         }
   71         $this->transformationConjunctions[$conjunctionIdentifier] = $conjunction;
   72 
   73         return $conjunction;
   74     }
   75 
   76     /**
   77      * Builds a transformation object from the given configuration.
   78      *
   79      * @param array $transformationConfiguration
   80      * @return TransformationInterface
   81      * @throws MigrationException if a given setting is not supported
   82      */
   83     protected function buildTransformationObject($transformationConfiguration)
   84     {
   85         $transformationClassName = $this->resolveTransformationClassName($transformationConfiguration['type']);
   86         $transformation = new $transformationClassName();
   87 
   88         if (isset($transformationConfiguration['settings']) && is_array($transformationConfiguration['settings'])) {
   89             foreach ($transformationConfiguration['settings'] as $settingName => $settingValue) {
   90                 if (!ObjectAccess::setProperty($transformation, $settingName, $settingValue)) {
   91                     throw new MigrationException('Cannot set setting "' . $settingName . '" on transformation "' . $transformationClassName . '" , check your configuration.', 1343293094);
   92                 }
   93             }
   94         }
   95 
   96         return $transformation;
   97     }
   98 
   99     /**
  100      * Tries to resolve the given transformation name into a class name.
  101      *
  102      * The name can be a fully qualified class name or a name relative to the
  103      * Neos\ContentRepository\Migration\Transformations namespace.
  104      *
  105      * @param string $transformationName
  106      * @return string
  107      * @throws MigrationException
  108      */
  109     protected function resolveTransformationClassName($transformationName)
  110     {
  111         $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName($transformationName);
  112         if ($resolvedObjectName !== null) {
  113             return $resolvedObjectName;
  114         }
  115 
  116         $resolvedObjectName = $this->objectManager->getCaseSensitiveObjectName('Neos\ContentRepository\Migration\Transformations\\' . $transformationName);
  117         if ($resolvedObjectName !== null) {
  118             return $resolvedObjectName;
  119         }
  120 
  121         throw new MigrationException('A transformation with the name "' . $transformationName . '" could not be found.', 1343293064);
  122     }
  123 }