Пример #1
0
    /**
     * @param BlockInterface $block
     *
     * @return string
     */
    public function repeatScript(BlockInterface $block)
    {
        $deepCopy = new DeepCopy();
        /** @var BlockInterface|FieldInterface|RenderableInterface $childCopy */
        $childCopy = $deepCopy->copy($block->getRepeatObject());
        $childCopy->clear();
        $childCopy->setParent($block);
        /** @var BlockInterface|FieldInterface $child */
        $child = $block->child(0);
        $res = '<script>
$(document).ready(function(e){
    $("[' . $this->containerSelector() . ']").repeatContainer({
        containerSelector : \'[' . $this->containerSelector() . ']\',
        blockSelector : \'[' . $this->blockSelector() . ']\',
        actionsSelector : \'[' . $this->actionsBlockSelector() . '="' . $block->getName() . '"]\',
        addSelector : \'[' . $this->addActionSelector() . ']\',
        deleteSelector : \'[' . $this->deleteActionSelector() . ']\',
        dummyObject: \'' . $childCopy . '\',
        addButton: \'' . $this->addButton($block, false) . '\',
        deleteButton: \'' . $this->deleteButton($block, false) . '\',
        fullActionsBlock: \'' . $this->actions($child, false) . '\'
    });
});
</script>';
        return $res;
    }
Пример #2
0
 /**
  * @param Serializer|null $child
  *
  * @return $this|Serializer
  */
 public function child(Serializer $child = null)
 {
     if ($child) {
         $deepCopy = new DeepCopy();
         $this->child = $deepCopy->copy($child);
         $this->child->bind('', $this);
         return $this;
     }
     return $this->child;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     /* @var \Cawa\Renderer\PhtmlHtmlContainer $clone */
     $deepcopy = new DeepCopy();
     $clone = $deepcopy->copy($this);
     $content = $clone->content ?: $clone->containerRender();
     $clone->addData('content', $content);
     $clone->content = $clone->phtmlRender();
     $clone->clear();
     return $clone->renderClone();
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function apply($element)
 {
     $newElement = clone $element;
     if ($element instanceof \SplDoublyLinkedList) {
         // Replace each element in the list with a deep copy of itself
         for ($i = 1; $i <= $newElement->count(); $i++) {
             $newElement->push($this->deepCopy->copy($newElement->shift()));
         }
     }
     return $newElement;
 }
 /**
  * Copy portfolio.
  *
  * @param Portfolio $portfolio
  *
  * @see https://github.com/myclabs/DeepCopy
  **/
 public function copyPortfolio($portfolio)
 {
     // instantiate DeepCopy
     $deepCopy = new DeepCopy();
     // https://github.com/myclabs/DeepCopy#doctrinecollectionfilter
     $deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\\Common\\Collections\\Collection'));
     // perform copy
     $copiedPortfolio = $deepCopy->copy($portfolio);
     // persist copied portfolio
     $this->getEntityManager()->persist($copiedPortfolio);
     $this->getEntityManager()->flush();
     // return copied portfolio
     return $copiedPortfolio;
 }
Пример #6
0
 /**
  * @since Method available since Release 3.5.4
  */
 protected function handleDependencies()
 {
     if (!empty($this->dependencies) && !$this->inIsolation) {
         $className = get_class($this);
         $passed = $this->result->passed();
         $passedKeys = array_keys($passed);
         $numKeys = count($passedKeys);
         for ($i = 0; $i < $numKeys; $i++) {
             $pos = strpos($passedKeys[$i], ' with data set');
             if ($pos !== false) {
                 $passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
             }
         }
         $passedKeys = array_flip(array_unique($passedKeys));
         foreach ($this->dependencies as $dependency) {
             $clone = false;
             if (strpos($dependency, 'clone ') === 0) {
                 $clone = true;
                 $dependency = substr($dependency, strlen('clone '));
             } elseif (strpos($dependency, '!clone ') === 0) {
                 $clone = false;
                 $dependency = substr($dependency, strlen('!clone '));
             }
             if (strpos($dependency, '::') === false) {
                 $dependency = $className . '::' . $dependency;
             }
             if (!isset($passedKeys[$dependency])) {
                 $this->result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
                 return false;
             }
             if (isset($passed[$dependency])) {
                 if ($passed[$dependency]['size'] != PHPUnit_Util_Test::UNKNOWN && $this->getSize() != PHPUnit_Util_Test::UNKNOWN && $passed[$dependency]['size'] > $this->getSize()) {
                     $this->result->addError($this, new PHPUnit_Framework_SkippedTestError('This test depends on a test that is larger than itself.'), 0);
                     return false;
                 }
                 if ($clone) {
                     $deepCopy = new DeepCopy();
                     $deepCopy->skipUncloneable(false);
                     $this->dependencyInput[$dependency] = $deepCopy->copy($passed[$dependency]['result']);
                 } else {
                     $this->dependencyInput[$dependency] = $passed[$dependency]['result'];
                 }
             } else {
                 $this->dependencyInput[$dependency] = null;
             }
         }
     }
     return true;
 }
Пример #7
0
 /**
  * @param mixed $object
  * @return mixed
  * @throws InvalidArgumentException
  */
 public function makeSnapshotOf($object)
 {
     return $this->cloner->copy($object);
 }
Пример #8
0
 /**
  * @param Heading $node
  * @return Node[]
  */
 protected function cloneChildren(Heading $node)
 {
     $firstClone = clone $node;
     // We have no choice but to hack into the
     // system to reset the parent, previous and next
     $this->setNull($firstClone, 'parent');
     $this->setNull($firstClone, 'previous');
     $this->setNull($firstClone, 'next');
     // Also, the child elements need to know the next parents
     foreach ($firstClone->children() as $subnode) {
         $method = new ReflectionMethod(get_class($subnode), 'setParent');
         $method->setAccessible(true);
         $method->invoke($subnode, $firstClone);
     }
     $deepCopy = new DeepCopy();
     return $deepCopy->copy($firstClone)->children();
 }
Пример #9
0
 /**
  * @param Heading $node
  * @return Node[]
  */
 protected function cloneChildren(Heading $node)
 {
     $deepCopy = new DeepCopy();
     $firstClone = clone $node;
     // We have no choice but to hack into the system to reset the parent, to avoid cloning the complete tree
     $method = new ReflectionMethod(get_class($firstClone), 'setParent');
     $method->setAccessible(true);
     $method->invoke($firstClone, null);
     return $deepCopy->copy($firstClone)->children();
 }
Пример #10
0
 /**
  * @return string
  */
 public function render()
 {
     if ($this->dataCallable) {
         $this->getTable()->setData(call_user_func($this->dataCallable, $this));
     }
     $data = $this->getTable()->getData();
     $this->getTable()->setData([]);
     /* @var Grid $clone */
     $deepcopy = new DeepCopy();
     $clone = $deepcopy->copy($this);
     $clone->getTable()->setData($data);
     return $clone->renderClone();
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function export() : array
 {
     /* @var \Cawa\Bootstrap\Forms\Form $clone */
     $deepcopy = new DeepCopy();
     $clone = $deepcopy->copy($this);
     $clone->alterBeforeRender();
     return $clone->exportClone();
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $deepcopy = new DeepCopy();
     /** @var MultipleGroup $clone */
     $clone = $deepcopy->copy($this);
     $fullRender = $clone->parentRender();
     $this->newContainer->getOptions()->addData('clone', $fullRender);
     return parent::render();
 }
Пример #13
0
 /**
  * @param DeepCopy $deepCopy
  * @param EntityManager $entityManager
  * @return DeepCopy
  */
 private function addDeepCopyCommonFilters(DeepCopy $deepCopy, EntityManager $entityManager)
 {
     $keepFilter = new KeepFilter();
     $nullifyFilter = new SetNullFilter();
     // Matches RedirectTargetPage::$page property.
     // Keeps the $page property redirect target is referencing to.
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(RedirectTargetPage::CN(), 'page'));
     // Matches PageLocalization::$template.
     // Prevents the template to be cloned.
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(PageLocalization::CN(), 'template'));
     // Matches Localization::$path
     // Keeps the value since it is cloned manually (see PageLocalization::__clone());
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(Localization::CN(), 'path'));
     // Matches Block::$blockProperties collection.
     // Replaces with empty collection, since block properties can be obtained via Localization::$blockProperties.
     $deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher(Block::CN(), 'blockProperties'));
     // Matches Localization::$lock.
     // Nullifies editing lock entity.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'lock'));
     // Matches Localization::$publishedRevision.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishedRevision'));
     // Matches Localization::$publishTime.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishTime'));
     // Matches Entity Collection.
     // Creates Copy and persists the elements in it.
     $deepCopy->addFilter(new DoctrineCollectionFilter($entityManager), new PropertyTypeMatcher('Doctrine\\Common\\Collections\\Collection'));
     // Matches any Entity.
     // Creates copy and persists it.
     $deepCopy->addFilter(new DoctrineEntityFilter($entityManager), new PropertyTypeMatcher(Entity::CN()));
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 public function mockMove(MoveInterface $move, BoardInterface $board)
 {
     $deepCopy = new DeepCopy();
     /** @var BoardInterface $futureBoard */
     $futureBoard = $deepCopy->copy($board);
     $fromSquare = $futureBoard->getSquare($move->getFrom());
     $fromPiece = $fromSquare->getPiece();
     $fromSquare->setPiece(null);
     $futureBoard->getSquare($move->getTo())->setPiece($fromPiece);
     return $futureBoard;
 }
Пример #15
0
 /**
  * @inheritdoc
  */
 public function load($data = null)
 {
     TypeChecker::getInstance()->check($data, [SimpleTypes::ARR, SimpleTypes::NULL], 'data')->throwTypeErrorIfNotValid();
     if ($data === null && isset($_REQUEST[$this->getName()])) {
         $data = $_REQUEST[$this->getName()];
     } elseif ($data === null) {
         return false;
     }
     $deepCopy = new DeepCopy();
     foreach ($data as $name => $value) {
         $child = $this->child($name);
         if ($child instanceof FieldInterface) {
             $child->setValue($value);
         } elseif ($child instanceof BlockInterface && !$child->isRepeatableContainer()) {
             $child->load($value);
         } elseif ($child instanceof BlockInterface && $child->isRepeatableContainer()) {
             $value = array_values($value);
             $childrenCount = count($child->children());
             $childrenMaxIndex = $childrenCount - 1;
             $childrenDelta = count($value) - $childrenCount;
             if ($childrenDelta > 0) {
                 for ($i = 0; $i <= $childrenDelta; $i++) {
                     /** @var BlockInterface $objectClone */
                     $objectClone = $deepCopy->copy($child->getRepeatObject());
                     $objectValue = $objectClone->getValue();
                     if ($value[$i] == $objectValue) {
                         $childrenDelta--;
                         array_splice($value, $i, 1);
                         $i--;
                         continue;
                     }
                     $objectClone->setParent($child);
                     $objectClone->setName((string) ($childrenCount + $i));
                     $child->children()->add($objectClone);
                 }
             } elseif ($childrenDelta < 0) {
                 for ($i = 0; $i < abs($childrenDelta); $i++) {
                     $child->children()->delete($childrenMaxIndex - $i);
                 }
             } elseif ($childrenDelta == 0 && count($value) == 1 && !empty($value[0])) {
                 $objectClone = $deepCopy->copy($child->getRepeatObject());
                 $objectClone->setParent($child);
                 $objectClone->setName((string) count($child->children()));
                 $child->children()->add($objectClone);
             }
             $child->load($value);
         }
     }
     return true;
 }
Пример #16
0
 /**
  * @param mixed $document
  *
  * @return mixed
  */
 public function cloneDocument($document)
 {
     return $this->deepCopy->copy($document);
 }