/**
  * @param MenuItem $menu
  * @param array $options
  * @param int $depth
  */
 protected function prepareItems(MenuItem $menu, array $options = [], $depth = 1)
 {
     $menu->setChildrenAttribute('class', 'integrated-website-menu-list');
     if (1 === $depth) {
         $menu->setChildrenAttribute('data-json', json_encode($menu->toArray(false)));
     }
     /** @var MenuItem $child */
     foreach ($menu->getChildren() as $child) {
         $child->setAttributes(['class' => 'integrated-website-menu-item', 'data-action' => 'integrated-website-menu-item-edit', 'data-json' => json_encode($child->toArray(false))]);
         $this->prepareItems($child, $options, $depth + 1);
         // recursion
     }
     if (isset($options['depth']) && $depth <= (int) $options['depth']) {
         $uuid = $this->generator->generateV5($this->generator->generateV4(), uniqid(rand(), true));
         $child = $menu->addChild('+', ['uri' => '#', 'attributes' => ['class' => 'integrated-website-menu-item', 'data-action' => 'integrated-website-menu-item-add']]);
         $child->setId($uuid);
         $child->setAttribute('data-json', json_encode($child->toArray(false)));
     }
 }
예제 #2
0
 private function completeIdGeneratorMapping(ClassMetadataInfo $class)
 {
     $idGenOptions = $class->generatorOptions;
     switch ($class->generatorType) {
         case ClassMetadata::GENERATOR_TYPE_AUTO:
             $class->setIdGenerator(new AutoGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_INCREMENT:
             $incrementGenerator = new IncrementGenerator();
             if (isset($idGenOptions['key'])) {
                 $incrementGenerator->setKey($idGenOptions['key']);
             }
             if (isset($idGenOptions['collection'])) {
                 $incrementGenerator->setCollection($idGenOptions['collection']);
             }
             $class->setIdGenerator($incrementGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_UUID:
             $uuidGenerator = new UuidGenerator();
             isset($idGenOptions['salt']) && $uuidGenerator->setSalt($idGenOptions['salt']);
             $class->setIdGenerator($uuidGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_ALNUM:
             $alnumGenerator = new AlnumGenerator();
             if (isset($idGenOptions['pad'])) {
                 $alnumGenerator->setPad($idGenOptions['pad']);
             }
             if (isset($idGenOptions['chars'])) {
                 $alnumGenerator->setChars($idGenOptions['chars']);
             } elseif (isset($idGenOptions['awkwardSafe'])) {
                 $alnumGenerator->setAwkwardSafeMode($idGenOptions['awkwardSafe']);
             }
             $class->setIdGenerator($alnumGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_CUSTOM:
             if (empty($idGenOptions['class'])) {
                 throw MappingException::missingIdGeneratorClass($class->name);
             }
             $customGenerator = new $idGenOptions['class']();
             unset($idGenOptions['class']);
             if (!$customGenerator instanceof AbstractIdGenerator) {
                 throw MappingException::classIsNotAValidGenerator(get_class($customGenerator));
             }
             $methods = get_class_methods($customGenerator);
             foreach ($idGenOptions as $name => $value) {
                 $method = 'set' . ucfirst($name);
                 if (!in_array($method, $methods)) {
                     throw MappingException::missingGeneratorSetter(get_class($customGenerator), $name);
                 }
                 $customGenerator->{$method}($value);
             }
             $class->setIdGenerator($customGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_NONE:
             break;
         default:
             throw new MappingException('Unknown generator type: ' . $class->generatorType);
     }
 }
예제 #3
0
 public function generate(DocumentManager $dm, $document)
 {
     return "RENDEZVOUS-" . parent::generate($dm, $document);
 }