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


PHP AbstractWrapper::wrap方法代码示例

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


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

示例1: getClassAndId

 protected function getClassAndId($object)
 {
     $wrapped = AbstractWrapper::wrap($object, $this->getEntityManager());
     $id = $wrapped->getIdentifier();
     $class = $wrapped->getRootObjectName();
     return array('id' => $id, 'class' => $class);
 }
开发者ID:fcpauldiaz,项目名称:IbrowsLoggableBundle,代码行数:7,代码来源:LogRepository.php

示例2: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], ':slug'));
     $qb->setParameter('slug', $slug . '%');
     // use the unique_base to restrict the uniqueness check
     if ($config['unique'] && isset($config['unique_base'])) {
         if (($ubase = $wrapped->getPropertyValue($config['unique_base'])) && !array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $qb->andWhere('rec.' . $config['unique_base'] . ' = :unique_base');
             $qb->setParameter(':unique_base', $ubase);
         } elseif (array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $associationMappings = $wrapped->getMetadata()->getAssociationMappings();
             $qb->join($associationMappings[$config['unique_base']]['targetEntity'], 'unique_' . $config['unique_base']);
         } else {
             $qb->andWhere($qb->expr()->isNull('rec.' . $config['unique_base']));
         }
     }
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:33,代码来源:ORM.php

示例3: getLogsByObject

 public function getLogsByObject($object, $searchChild = true, $searchOnlyChild = false)
 {
     $wrapped = AbstractWrapper::wrap($object, $this->getEntityManager());
     $id = $wrapped->getIdentifier();
     $class = $wrapped->getRootObjectName();
     return $this->getLogsByClassId($class, $id, $searchChild, $searchOnlyChild);
 }
开发者ID:fcpauldiaz,项目名称:IbrowsLoggableBundle,代码行数:7,代码来源:LogMany2ManyRepository.php

示例4: removeNode

 /**
  * {@inheritdoc}
  */
 public function removeNode($om, $meta, $config, $node)
 {
     $uow = $om->getUnitOfWork();
     $wrapped = AbstractWrapper::wrap($node, $om);
     // Remove node's children
     $results = $om->createQueryBuilder()->find($meta->name)->field($config['path'])->equals(new \MongoRegex('/^' . preg_quote($wrapped->getPropertyValue($config['path'])) . '.?+/'))->getQuery()->execute();
     foreach ($results as $node) {
         $uow->scheduleForDelete($node);
     }
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:13,代码来源:MaterializedPath.php

示例5: removeNode

 /**
  * {@inheritdoc}
  */
 public function removeNode($om, $meta, $config, $node)
 {
     $uow = $om->getUnitOfWork();
     $wrapped = AbstractWrapper::wrap($node, $om);
     $path = addcslashes($wrapped->getPropertyValue($config['path']), '%');
     // Remove node's children
     $qb = $om->createQueryBuilder();
     $qb->select('e')->from($config['useObjectClass'], 'e')->where($qb->expr()->like('e.' . $config['path'], $qb->expr()->literal($path . '%')));
     $results = $qb->getQuery()->execute();
     foreach ($results as $node) {
         $uow->scheduleForDelete($node);
     }
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:16,代码来源:MaterializedPath.php

示例6: replaceInverseRelative

 /**
  * This query can cause some data integrity failures since it does not
  * execute atomically
  *
  * {@inheritDoc}
  */
 public function replaceInverseRelative($object, array $config, $target, $replacement)
 {
     $dm = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $dm);
     $meta = $dm->getClassMetadata($config['useObjectClass']);
     $q = $dm->createQueryBuilder($config['useObjectClass'])->field($config['mappedBy'] . '.' . $meta->identifier)->equals($wrapped->getIdentifier())->getQuery();
     $q->setHydrate(false);
     $result = $q->execute();
     if ($result instanceof Cursor) {
         $result = $result->toArray();
         foreach ($result as $targetObject) {
             $slug = preg_replace("@^{$replacement}@smi", $target, $targetObject[$config['slug']]);
             $dm->createQueryBuilder()->update($config['useObjectClass'])->field($config['slug'])->set($slug)->field($meta->identifier)->equals($targetObject['_id'])->getQuery()->execute();
         }
     }
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:22,代码来源:ODM.php

示例7: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], $qb->expr()->literal($slug . '%')));
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:20,代码来源:ORM.php

示例8: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $dm = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $dm);
     $qb = $dm->createQueryBuilder($config['useObjectClass']);
     if (($identifier = $wrapped->getIdentifier()) && !$meta->isIdentifier($config['slug'])) {
         $qb->field($meta->identifier)->notEqual($identifier);
     }
     $qb->field($config['slug'])->equals(new \MongoRegex('/^' . preg_quote($slug, '/') . '/'));
     $q = $qb->getQuery();
     $q->setHydrate(false);
     $result = $q->execute();
     if ($result instanceof Cursor) {
         $result = $result->toArray();
     }
     return $result;
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:20,代码来源:ODM.php

示例9: prepareForDisplay

 /**
  * prepare object for display
  * 
  * 
  * @access public
  * @param array $objectsArray
  * @param mixed $sampleObject object used to get expected properties when $objectsArray is array of arrays not array of objects ,default is null
  * @param int $depthLevel ,default is 0
  * @param int $maxDepthLevel depth level including first object level ,default is 3
  * @return array objects prepared for display
  */
 public function prepareForDisplay($objectsArray, $sampleObject = null, $depthLevel = 0, $maxDepthLevel = 3)
 {
     $depthLevel++;
     foreach ($objectsArray as &$object) {
         $notObject = false;
         // support array of arrays instead of array of objects
         if (is_array($object)) {
             $object = (object) $object;
             $notObject = true;
         }
         $objectProperties = $this->prepareForStatusDisplay($object);
         if (($notObject === false || $notObject === true && !is_null($sampleObject)) && $depthLevel == 1) {
             if (is_null($sampleObject)) {
                 $sampleObjectForWrapper = $object;
             } else {
                 $sampleObjectForWrapper = $sampleObject;
             }
             $wrapped = AbstractWrapper::wrap($sampleObjectForWrapper, $this->query->entityManager);
             $meta = $wrapped->getMetadata();
         }
         foreach ($objectProperties as $objectPropertyName => $objectPropertyValue) {
             if (is_string($objectPropertyValue) && strlen($objectPropertyValue) <= 5) {
                 $textObjectPropertyName = $objectPropertyName . "Text";
                 if (array_key_exists($objectPropertyValue, $this->languages)) {
                     $object->{$textObjectPropertyName} = $this->languages[$objectPropertyValue];
                 } elseif (strlen($objectPropertyValue) == 2 && array_key_exists($objectPropertyValue, $this->countries)) {
                     $object->{$textObjectPropertyName} = $this->countries[$objectPropertyValue];
                 }
             } elseif ($objectPropertyValue instanceof \DateTime) {
                 $formattedString = $objectPropertyValue->format("D, d M Y");
                 if ($formattedString == Time::UNIX_DATE_STRING) {
                     $formattedString = $objectPropertyValue->format("H:i");
                 }
                 $object->{$objectPropertyName} = $formattedString;
             } elseif (is_object($objectPropertyValue) && $depthLevel != $maxDepthLevel) {
                 $objectsPropertyValue = $this->prepareForDisplay(array($objectPropertyValue), $sampleObject, $depthLevel, $maxDepthLevel);
                 $object->{$objectPropertyName} = reset($objectsPropertyValue);
             } elseif (is_array($objectPropertyValue) && array_key_exists("id", $objectPropertyValue) && isset($meta) && $meta->isSingleValuedAssociation($objectPropertyName)) {
                 $object->{$objectPropertyName} = $this->query->find($meta->getAssociationMapping($objectPropertyName)["targetEntity"], $objectPropertyValue["id"]);
             }
         }
     }
     return $objectsArray;
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:55,代码来源:Object.php

示例10: onSlugCompletion

 /**
  * {@inheritDoc}
  */
 public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
 {
     $this->om = $ea->getObjectManager();
     $isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
     if (!$isInsert) {
         $options = $config['handlers'][get_called_class()];
         $wrapped = AbstractWrapper::wrap($object, $this->om);
         $oldSlug = $wrapped->getPropertyValue($config['slug']);
         $mappedByConfig = $this->sluggable->getConfiguration($this->om, $options['relationClass']);
         if ($mappedByConfig) {
             $meta = $this->om->getClassMetadata($options['relationClass']);
             if (!$meta->isSingleValuedAssociation($options['mappedBy'])) {
                 throw new InvalidMappingException("Unable to find " . $wrapped->getMetadata()->name . " relation - [{$options['mappedBy']}] in class - {$meta->name}");
             }
             if (!isset($mappedByConfig['slugs'][$options['inverseSlugField']])) {
                 throw new InvalidMappingException("Unable to find slug field - [{$options['inverseSlugField']}] in class - {$meta->name}");
             }
             $mappedByConfig['slug'] = $mappedByConfig['slugs'][$options['inverseSlugField']]['slug'];
             $mappedByConfig['mappedBy'] = $options['mappedBy'];
             $ea->replaceInverseRelative($object, $mappedByConfig, $slug, $oldSlug);
             $uow = $this->om->getUnitOfWork();
             // update in memory objects
             foreach ($uow->getIdentityMap() as $className => $objects) {
                 // for inheritance mapped classes, only root is always in the identity map
                 if ($className !== $mappedByConfig['useObjectClass']) {
                     continue;
                 }
                 foreach ($objects as $object) {
                     if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
                         continue;
                     }
                     $oid = spl_object_hash($object);
                     $objectSlug = $meta->getReflectionProperty($mappedByConfig['slug'])->getValue($object);
                     if (preg_match("@^{$oldSlug}@smi", $objectSlug)) {
                         $objectSlug = str_replace($oldSlug, $slug, $objectSlug);
                         $meta->getReflectionProperty($mappedByConfig['slug'])->setValue($object, $objectSlug);
                         $ea->setOriginalObjectProperty($uow, $oid, $mappedByConfig['slug'], $objectSlug);
                     }
                 }
             }
         }
     }
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:46,代码来源:InversedRelativeSlugHandler.php

示例11: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], ':slug'));
     $qb->setParameter('slug', $slug . '%');
     // use the unique_base to restrict the uniqueness check
     if ($config['unique'] && isset($config['unique_base'])) {
         $ubase = $wrapped->getPropertyValue($config['unique_base']);
         if (array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $mapping = $wrapped->getMetadata()->getAssociationMapping($config['unique_base']);
         } else {
             $mapping = false;
         }
         if ($ubase && !$mapping) {
             $qb->andWhere('rec.' . $config['unique_base'] . ' = :unique_base');
             $qb->setParameter(':unique_base', $ubase);
         } elseif ($ubase && $mapping && in_array($mapping['type'], array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE))) {
             $mappedAlias = 'mapped_' . $config['unique_base'];
             $wrappedUbase = AbstractWrapper::wrap($ubase, $em);
             $qb->innerJoin('rec.' . $config['unique_base'], $mappedAlias);
             foreach (array_keys($mapping['targetToSourceKeyColumns']) as $i => $mappedKey) {
                 $mappedProp = $wrappedUbase->getMetadata()->fieldNames[$mappedKey];
                 $qb->andWhere($qb->expr()->eq($mappedAlias . '.' . $mappedProp, ':assoc' . $i));
                 $qb->setParameter(':assoc' . $i, $wrappedUbase->getPropertyValue($mappedProp));
             }
         } else {
             $qb->andWhere($qb->expr()->isNull('rec.' . $config['unique_base']));
         }
     }
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:45,代码来源:ORM.php

示例12: onSlugCompletion

 /**
  * {@inheritDoc}
  */
 public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
 {
     if (!$this->isInsert) {
         $options = $config['handlers'][get_called_class()];
         $wrapped = AbstractWrapper::wrap($object, $this->om);
         $meta = $wrapped->getMetadata();
         $target = $wrapped->getPropertyValue($config['slug']);
         $config['pathSeparator'] = $this->usedPathSeparator;
         $ea->replaceRelative($object, $config, $target . $config['pathSeparator'], $slug);
         $uow = $this->om->getUnitOfWork();
         // update in memory objects
         foreach ($uow->getIdentityMap() as $className => $objects) {
             // for inheritance mapped classes, only root is always in the identity map
             if ($className !== $wrapped->getRootObjectName()) {
                 continue;
             }
             foreach ($objects as $object) {
                 if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
                     continue;
                 }
                 $oid = spl_object_hash($object);
                 $objectSlug = $meta->getReflectionProperty($config['slug'])->getValue($object);
                 if (preg_match("@^{$target}{$config['pathSeparator']}@smi", $objectSlug)) {
                     $objectSlug = str_replace($target, $slug, $objectSlug);
                     $meta->getReflectionProperty($config['slug'])->setValue($object, $objectSlug);
                     $ea->setOriginalObjectProperty($uow, $oid, $config['slug'], $objectSlug);
                 }
             }
         }
     }
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:34,代码来源:TreeSlugHandler.php

示例13: setTranslationValue

 /**
  * {@inheritDoc}
  */
 public function setTranslationValue($object, $field, $value)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $meta = $wrapped->getMetadata();
     $type = Type::getType($meta->getTypeOfField($field));
     $value = $type->convertToPHPValue($value, $em->getConnection()->getDatabasePlatform());
     $wrapped->setPropertyValue($field, $value);
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:12,代码来源:ORM.php

示例14: updateNode

 /**
  * Update the $node with a diferent $parent
  * destination
  *
  * @param EntityManager $em
  * @param object $node - target node
  * @param object $parent - destination node
  * @param string $position
  * @throws Gedmo\Exception\UnexpectedValueException
  * @return void
  */
 public function updateNode(EntityManager $em, $node, $parent, $position = 'FirstChild')
 {
     // die (1);
     $wrapped = AbstractWrapper::wrap($node, $em);
     $meta = $wrapped->getMetadata();
     $config = $this->listener->getConfiguration($em, $meta->name);
     $rootId = isset($config['root']) ? $wrapped->getPropertyValue($config['root']) : null;
     $identifierField = $meta->getSingleIdentifierFieldName();
     $nodeId = $wrapped->getIdentifier();
     $left = $wrapped->getPropertyValue($config['left']);
     $right = $wrapped->getPropertyValue($config['right']);
     $isNewNode = empty($left) && empty($right);
     if ($isNewNode) {
         $left = 1;
         $right = 2;
     }
     //   var_dump($node);
     //    var_dump($isNewNode);
     $oid = spl_object_hash($node);
     if (isset($this->nodePositions[$oid])) {
         $position = $this->nodePositions[$oid];
     }
     //  print "\n".$position." ".$node->getTitle()."(".$oid.")";
     $level = 0;
     $treeSize = $right - $left + 1;
     $newRootId = null;
     if ($parent) {
         $wrappedParent = AbstractWrapper::wrap($parent, $em);
         $parentRootId = isset($config['root']) ? $wrappedParent->getPropertyValue($config['root']) : null;
         $parentLeft = $wrappedParent->getPropertyValue($config['left']);
         $parentRight = $wrappedParent->getPropertyValue($config['right']);
         if (!$isNewNode && $rootId === $parentRootId && $parentLeft >= $left && $parentRight <= $right) {
             throw new UnexpectedValueException("Cannot set child as parent to node: {$nodeId}");
         }
         if (isset($config['level'])) {
             $level = $wrappedParent->getPropertyValue($config['level']);
         }
         switch ($position) {
             case self::PREV_SIBLING:
                 $newParent = $wrappedParent->getPropertyValue($config['parent']);
                 if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
                     throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
                 }
                 $wrapped->setPropertyValue($config['parent'], $newParent);
                 $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                 $start = $parentLeft;
                 break;
             case self::NEXT_SIBLING:
                 $newParent = $wrappedParent->getPropertyValue($config['parent']);
                 if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
                     throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
                 }
                 $wrapped->setPropertyValue($config['parent'], $newParent);
                 $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                 $start = $parentRight + 1;
                 break;
             case self::LAST_CHILD:
                 $start = $parentRight;
                 $level++;
                 break;
             case self::FIRST_CHILD:
             default:
                 $start = $parentLeft + 1;
                 $level++;
                 break;
         }
         $this->shiftRL($em, $config['useObjectClass'], $start, $treeSize, $parentRootId);
         if (!$isNewNode && $rootId === $parentRootId && $left >= $start) {
             $left += $treeSize;
             $wrapped->setPropertyValue($config['left'], $left);
         }
         if (!$isNewNode && $rootId === $parentRootId && $right >= $start) {
             $right += $treeSize;
             $wrapped->setPropertyValue($config['right'], $right);
         }
         $newRootId = $parentRootId;
     } elseif (!isset($config['root'])) {
         $start = isset($this->treeEdges[$meta->name]) ? $this->treeEdges[$meta->name] : $this->max($em, $config['useObjectClass']);
         $this->treeEdges[$meta->name] = $start + 2;
         $start++;
     } else {
         $start = 1;
         $newRootId = $nodeId;
     }
     // die ('Update Node');
     $diff = $start - $left;
     if (!$isNewNode) {
         $levelDiff = isset($config['level']) ? $level - $wrapped->getPropertyValue($config['level']) : null;
         $this->shiftRangeRL($em, $config['useObjectClass'], $left, $right, $diff, $rootId, $newRootId, $levelDiff);
//.........这里部分代码省略.........
开发者ID:khasinski,项目名称:Iphp,代码行数:101,代码来源:Nested.php

示例15: updateChildrenPath

 function updateChildrenPath($em, $node)
 {
     $wrapped = AbstractWrapper::wrap($node, $em);
     $meta = $wrapped->getMetadata();
     $config = $this->listener->getConfiguration($em, $meta->name);
     foreach ($em->getRepository($config['useObjectClass'])->children($node, false, $config['left']) as $child) {
         $this->updateNodePath($em, $child, $child->getParent());
     }
 }
开发者ID:hunter1271,项目名称:IphpTreeBundle,代码行数:9,代码来源:Nested.php


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