/** * Replaces an object by another. * * @param object $existingObject The existing object * @param object $newObject The new object * @return void * @api */ public function replace($existingObject, $newObject) { if (!$existingObject instanceof $this->objectType) { throw new Tx_Extbase_Persistence_Exception_IllegalObjectType('The existing object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363434); } if (!$newObject instanceof $this->objectType) { throw new Tx_Extbase_Persistence_Exception_IllegalObjectType('The new object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363439); } $backend = $this->persistenceManager->getBackend(); $session = $this->persistenceManager->getSession(); $uuid = $backend->getIdentifierByObject($existingObject); if ($uuid !== NULL) { $backend->replaceObject($existingObject, $newObject); $session->unregisterReconstitutedObject($existingObject); $session->registerReconstitutedObject($newObject); if ($this->removedObjects->contains($existingObject)) { $this->removedObjects->detach($existingObject); $this->removedObjects->attach($newObject); } } elseif ($this->addedObjects->contains($existingObject)) { $this->addedObjects->detach($existingObject); $this->addedObjects->attach($newObject); } else { throw new Tx_Extbase_Persistence_Exception_UnknownObject('The "existing object" is unknown to the persistence backend.', 1238068475); } }
/** * Call the view helper associated with this object. * * First, it evaluates the arguments of the view helper. * * If the view helper implements Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface, * it calls setChildNodes(array childNodes) on the view helper. * * Afterwards, checks that the view helper did not leave a variable lying around. * * @param Tx_Fluid_Core_Rendering_RenderingContextInterface $renderingContext * @return object evaluated node after the view helper has been called. * @author Sebastian Kurfürst <*****@*****.**> * @author Karsten Dambekalns <*****@*****.**> * @todo check recreation of viewhelper when revisiting caching */ public function evaluate(Tx_Fluid_Core_Rendering_RenderingContextInterface $renderingContext) { $objectManager = $renderingContext->getObjectManager(); $contextVariables = $renderingContext->getTemplateVariableContainer()->getAllIdentifiers(); if ($this->viewHelpersByContext->contains($renderingContext)) { $viewHelper = $this->viewHelpersByContext[$renderingContext]; } else { $viewHelper = clone $this->uninitializedViewHelper; $this->viewHelpersByContext->attach($renderingContext, $viewHelper); } $evaluatedArguments = array(); $renderMethodParameters = array(); if (count($viewHelper->prepareArguments())) { foreach ($viewHelper->prepareArguments() as $argumentName => $argumentDefinition) { if (isset($this->arguments[$argumentName])) { $argumentValue = $this->arguments[$argumentName]; $evaluatedArguments[$argumentName] = $this->convertArgumentValue($argumentValue, $argumentDefinition->getType(), $renderingContext); } else { $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue(); } if ($argumentDefinition->isMethodParameter()) { $renderMethodParameters[$argumentName] = $evaluatedArguments[$argumentName]; } } } $viewHelperArguments = $objectManager->create('Tx_Fluid_Core_ViewHelper_Arguments', $evaluatedArguments); $viewHelper->setArguments($viewHelperArguments); $viewHelper->setTemplateVariableContainer($renderingContext->getTemplateVariableContainer()); if ($renderingContext->getControllerContext() !== NULL) { $viewHelper->setControllerContext($renderingContext->getControllerContext()); } $viewHelper->setViewHelperVariableContainer($renderingContext->getViewHelperVariableContainer()); $viewHelper->setViewHelperNode($this); $viewHelper->setRenderingContext($renderingContext); if ($viewHelper instanceof Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface) { $viewHelper->setChildNodes($this->childNodes); } $output = $viewHelper->initializeArgumentsAndRender($renderMethodParameters); return $output; }
/** * @test */ public function removeParticipationFromObjectStorageHoldingParticipations() { $participation = new Tx_Nbowishlist_Domain_Model_Participation(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($participation); $localObjectStorage->detach($participation); $this->fixture->addParticipation($participation); $this->fixture->removeParticipation($participation); $this->assertEquals($localObjectStorage, $this->fixture->getParticipations()); }
/** * @test */ public function removeTrackFromObjectStorageHoldingTrack() { $track = new Tx_Nbomn_Domain_Model_Track(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($track); $localObjectStorage->detach($track); $this->fixture->addTrack($track); $this->fixture->removeTrack($track); $this->assertEquals( $localObjectStorage, $this->fixture->getTrack() ); }
/** * @test */ public function removeVideoFromObjectStorageHoldingVideos() { $video = new Tx_WinkelVideolist_Domain_Model_Video(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($video); $localObjectStorage->detach($video); $this->fixture->addVideo($video); $this->fixture->removeVideo($video); $this->assertEquals($localObjectStorage, $this->fixture->getVideos()); }
/** * Test if related links can be set * * @test * @return void */ public function relatedLinksCanBeSet() { $link = new Tx_News_Domain_Model_Link(); $link->setTitle('fo'); $related = new Tx_Extbase_Persistence_ObjectStorage(); $related->attach($link); $this->newsDomainModelInstance->setRelatedLinks($related); $this->assertEquals($related, $this->newsDomainModelInstance->getRelatedLinks()); }
/** * @test */ public function removeCompanyFromObjectStorageHoldingCompanies() { $company = new Tx_Nbomn_Domain_Model_Company(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($company); $localObjectStorage->detach($company); $this->fixture->addCompany($company); $this->fixture->removeCompany($company); $this->assertEquals( $localObjectStorage, $this->fixture->getCompanies() ); }
/** * @test */ public function setFieldsForObjectStorageContainingTx_Powermail_Domain_Model_FieldsSetsFields() { $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $field = new Tx_Powermail_Domain_Model_Fields(); $field->setSorting(42); $objectStorage->attach($field); $this->fixture->setFields($objectStorage); $this->assertSame( array( 42 => $field, ), $this->fixture->getFields() ); }
/** * @test */ public function removeContactFromObjectStorageHoldingContacts() { $contact = new Tx_WinkelAddress_Domain_Model_Contact(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($contact); $localObjectStorage->detach($contact); $this->fixture->addContact($contact); $this->fixture->removeContact($contact); $this->assertEquals($localObjectStorage, $this->fixture->getContacts()); }
/** * @test */ public function removeSubscriberFromObjectStorageHoldingSubscribers() { $subscriber = new Tx_WoehrlSeminare_Domain_Model_Subscriber(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($subscriber); $localObjectStorage->detach($subscriber); $this->fixture->addSubscriber($subscriber); $this->fixture->removeSubscriber($subscriber); $this->assertEquals($localObjectStorage, $this->fixture->getSubscribers()); }
/** * Commits new objects and changes to objects in the current persistence * session into the backend * * @return void * @api */ public function persistAll() { $aggregateRootObjects = new Tx_Extbase_Persistence_ObjectStorage(); $removedObjects = new Tx_Extbase_Persistence_ObjectStorage(); // fetch and inspect objects from all known repositories foreach ($this->repositoryClassNames as $repositoryClassName) { $repository = $this->objectManager->get($repositoryClassName); $aggregateRootObjects->addAll($repository->getAddedObjects()); $removedObjects->addAll($repository->getRemovedObjects()); } foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) { if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) { $aggregateRootObjects->attach($reconstitutedObject); } } // hand in only aggregate roots, leaving handling of subobjects to // the underlying storage layer $this->backend->setAggregateRootObjects($aggregateRootObjects); $this->backend->setDeletedObjects($removedObjects); $this->backend->commit(); // this needs to unregister more than just those, as at least some of // the subobjects are supposed to go away as well... // OTOH those do no harm, changes to the unused ones should not happen, // so all they do is eat some memory. foreach ($removedObjects as $removedObject) { $this->session->unregisterReconstitutedObject($removedObject); } }
/** * Maps the given properties to the target object WITHOUT VALIDATING THE RESULT. * If the properties could be set, this method returns TRUE, otherwise FALSE. * Returning TRUE does not mean that the target object is valid and secure! * * Only use this method if you're sure that you don't need validation! * * @param array $propertyNames Names of the properties to map. * @param mixed $source Source containing the properties to map to the target object. Must either be an array, ArrayObject or any other object. * @param object $target The target object * @param array $optionalPropertyNames Names of optional properties. If a property is specified here and it doesn't exist in the source, no error is issued. * @return boolean TRUE if the properties could be mapped, otherwise FALSE * @see mapAndValidate() * @api */ public function map(array $propertyNames, $source, $target, $optionalPropertyNames = array()) { if (!is_object($source) && !is_array($source)) { throw new Tx_Extbase_Property_Exception_InvalidSource('The source object must be a valid object or array, ' . gettype($target) . ' given.', 1187807099); } if (is_string($target) && strpos($target, '_') !== FALSE) { return $this->transformToObject($source, $target, '--none--'); } if (!is_object($target) && !is_array($target)) { throw new Tx_Extbase_Property_Exception_InvalidTarget('The target object must be a valid object or array, ' . gettype($target) . ' given.', 1187807099); } $this->mappingResults = new Tx_Extbase_Property_MappingResults(); if (is_object($target)) { $targetClassSchema = $this->reflectionService->getClassSchema(get_class($target)); } else { $targetClassSchema = NULL; } foreach ($propertyNames as $propertyName) { $propertyValue = NULL; if (is_array($source) || $source instanceof ArrayAccess) { if (isset($source[$propertyName])) { $propertyValue = $source[$propertyName]; } } else { $propertyValue = Tx_Extbase_Reflection_ObjectAccess::getProperty($source, $propertyName); } if ($propertyValue === NULL && !in_array($propertyName, $optionalPropertyNames)) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Required property '{$propertyName}' does not exist.", 1236785359), $propertyName); } else { if ($targetClassSchema !== NULL && $targetClassSchema->hasProperty($propertyName)) { $propertyMetaData = $targetClassSchema->getProperty($propertyName); if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'Tx_Extbase_Persistence_ObjectStorage')) && (strpos($propertyMetaData['elementType'], '_') !== FALSE || $propertyValue === '')) { $objects = array(); if (is_array($propertyValue)) { foreach ($propertyValue as $value) { $objects[] = $this->transformToObject($value, $propertyMetaData['elementType'], $propertyName); } } // make sure we hand out what is expected if ($propertyMetaData['type'] === 'ArrayObject') { $propertyValue = new ArrayObject($objects); } elseif ($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage') { $propertyValue = new Tx_Extbase_Persistence_ObjectStorage(); foreach ($objects as $object) { $propertyValue->attach($object); } } else { $propertyValue = $objects; } } elseif ($propertyMetaData['type'] === 'DateTime' || strpos($propertyMetaData['type'], '_') !== FALSE) { $propertyValue = $this->transformToObject($propertyValue, $propertyMetaData['type'], $propertyName); if ($propertyValue === NULL) { continue; } } } elseif ($targetClassSchema !== NULL) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Property '{$propertyName}' does not exist in target class schema.", 1251813614), $propertyName); } if (is_array($target)) { $target[$propertyName] = $propertyValue; } elseif (Tx_Extbase_Reflection_ObjectAccess::setProperty($target, $propertyName, $propertyValue) === FALSE) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Property '{$propertyName}' could not be set.", 1236783102), $propertyName); } } } return !$this->mappingResults->hasErrors(); }
/** * @test */ public function removePageFromObjectStorageHoldingPages() { $page = new Tx_Hrinewsletter_Domain_Model_Pages(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($page); $localObjectStorage->detach($page); $this->fixture->addPage($page); $this->fixture->removePage($page); $this->assertEquals($localObjectStorage, $this->fixture->getPages()); }
/** * @test */ public function removeTagFromObjectStorageHoldingTags() { $tag = new Tx_Nxshowroom_Domain_Model_Tags(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($tag); $localObjectStorage->detach($tag); $this->fixture->addTag($tag); $this->fixture->removeTag($tag); $this->assertEquals($localObjectStorage, $this->fixture->getTags()); }
/** * @test */ public function removeShimFromObjectStorageHoldingShims() { $shim = new Tx_WinkelProducts_Domain_Model_Shim(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($shim); $localObjectStorage->detach($shim); $this->fixture->addShim($shim); $this->fixture->removeShim($shim); $this->assertEquals($localObjectStorage, $this->fixture->getShims()); }
/** * @see Tx_Extbase_Persistence_ObjectStorage::attach */ public function attach($object, $data = NULL) { $this->initialize(); parent::attach($object, $data); }
/** * Adds a new validator to the conjunction. * * @param Tx_Extbase_Validation_Validator_ValidatorInterface $validator The validator that should be added * @return void */ public function addValidator(Tx_Extbase_Validation_Validator_ValidatorInterface $validator) { $this->validators->attach($validator); }
/** * @test */ public function removeResourceFromObjectStorageHoldingResource() { $resource = new Tx_Nxshowroom_Domain_Model_Resource(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($resource); $localObjectStorage->detach($resource); $this->fixture->addResource($resource); $this->fixture->removeResource($resource); $this->assertEquals($localObjectStorage, $this->fixture->getResource()); }
/** * Returns the given result as property value of the specified property type. * * @param mixed $result The result could be an object or an ObjectStorage * @param array $propertyMetaData The property meta data * @param Tx_Extbase_Persistence_QueryResultInterface|Tx_Extbase_Persistence_LoadingStrategyInterface $result The result * @return void */ public function mapResultToPropertyValue(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $result) { if ($result instanceof Tx_Extbase_Persistence_LoadingStrategyInterface) { $propertyValue = $result; } else { $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName); $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'SplObjectStorage', 'Tx_Extbase_Persistence_ObjectStorage'))) { $elementType = $this->getType(get_class($parentObject), $propertyName); $objects = array(); foreach ($result as $value) { $objects[] = $value; } if ($propertyMetaData['type'] === 'ArrayObject') { $propertyValue = new ArrayObject($objects); } elseif ($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage') { $propertyValue = new Tx_Extbase_Persistence_ObjectStorage(); foreach ($objects as $object) { $propertyValue->attach($object); } $propertyValue->_memorizeCleanState(); } else { $propertyValue = $objects; } } elseif (strpos($propertyMetaData['type'], '_') !== FALSE) { if (is_object($result) && $result instanceof Tx_Extbase_Persistence_QueryResultInterface) { $propertyValue = $result->getFirst(); } else { $propertyValue = $result; } } } return $propertyValue; }
/** * @test */ public function removeParentcategoryFromObjectStorageHoldingParentcategory() { $parentcategory = new Tx_Nbomn_Domain_Model_Category(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($parentcategory); $localObjectStorage->detach($parentcategory); $this->fixture->addParentcategory($parentcategory); $this->fixture->removeParentcategory($parentcategory); $this->assertEquals( $localObjectStorage, $this->fixture->getParentcategory() ); }
/** * @test */ public function theStorageCanBeRetrievedAsArray() { $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $object1 = new StdClass(); $object2 = new StdClass(); $objectStorage->attach($object1, 'foo'); $objectStorage->attach($object2, 'bar'); $this->assertEquals($objectStorage->toArray(), array($object1, $object2)); }
/** * Registers a reconstituted object * * @param object $object * @return void */ public function registerReconstitutedObject(Tx_Extbase_DomainObject_DomainObjectInterface $object) { $this->reconstitutedObjects->attach($object); }
/** * @test */ public function removeStaticCountryFromObjectStorageHoldingStaticCountry() { $staticCountry = new Tx_Temp_Domain_Model_StaticCountry(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($staticCountry); $localObjectStorage->detach($staticCountry); $this->fixture->addStaticCountry($staticCountry); $this->fixture->removeStaticCountry($staticCountry); $this->assertEquals($localObjectStorage, $this->fixture->getStaticCountry()); }
/** * Test if tags can be set * * @test * @return void */ public function tagsCanBeSet() { $domainModelInstance = new Tx_News_Domain_Model_Dto_NewsDemand(); $tag1 = new Tx_News_Domain_Model_Tag(); $tag1->setTitle('Tag 1'); $tag2 = new Tx_News_Domain_Model_Tag(); $tag2->setTitle('Tag 2'); $tags = new Tx_Extbase_Persistence_ObjectStorage(); $tags->attach($tag1); $tags->attach($tag2); $domainModelInstance->setTags($tags); $this->assertEquals($tags, $domainModelInstance->getTags()); }
/** * @test */ public function removeParentFromObjectStorageHoldingParent() { $parent = new Tx_WoehrlSeminare_Domain_Model_Location(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($parent); $localObjectStorage->detach($parent); $this->fixture->addParent($parent); $this->fixture->removeParent($parent); $this->assertEquals($localObjectStorage, $this->fixture->getParent()); }
/** * Updates an existing Event and forwards to the list action afterwards. * * @param Tx_CalendarDisplay_Domain_Model_Event $event the Event to display * @dontvalidate $event * @validate $event Tx_CalendarDisplay_Domain_Validator_EventValidator * @return void */ public function updateAction(Tx_CalendarDisplay_Domain_Model_Event $event) { // get current login user if it have right then add the new event $currentUser = $this->feUserRepository->findByUid(intval($GLOBALS['TSFE']->fe_user->user['uid'])); $getPurchaserId = $event->getPurchaser() ? $event->getPurchaser()->getUid() : NULL; if ($currentUser->getUid() == $getPurchaserId || $currentUser->getTxCalendardisplayAdmin() == 1) { $bookings = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('booking'); $bookingAttached = new Tx_Extbase_Persistence_ObjectStorage(); foreach ($bookings as $key => $value) { if ($value) { $resouce = $this->resourceRepository->findByUid($key); if ($resouce) { $bookingObj = new Tx_CalendarDisplay_Domain_Model_Booking(); $resourceAttached = new Tx_Extbase_Persistence_ObjectStorage(); $resourceAttached->attach($resouce); $bookingObj->setResources($resourceAttached); $bookingObj->setNumber($value); $bookingAttached->attach($bookingObj); } } } $event->setBooking($bookingAttached); $this->eventRepository->update($event); $this->flashMessageContainer->add($this->getMessage('event_updated', $event)); } else { $this->flashMessageContainer->add(Tx_Extbase_Utility_Localization::translate('event_not_updated', 'CalendarDisplay')); } $this->redirect($this->request->getArgument('refererAction')); }
/** * @test */ public function removeAddressFromObjectStorageHoldingAddresses() { $address = new Tx_WinkelAddress_Domain_Model_Address(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($address); $localObjectStorage->detach($address); $this->fixture->addAddress($address); $this->fixture->removeAddress($address); $this->assertEquals($localObjectStorage, $this->fixture->getAddresses()); }
/** * @test */ public function removeWasherFromObjectStorageHoldingWasher() { $washer = new Tx_WinkelProducts_Domain_Model_Washer(); $localObjectStorage = new Tx_Extbase_Persistence_ObjectStorage(); $localObjectStorage->attach($washer); $localObjectStorage->detach($washer); $this->fixture->addWasher($washer); $this->fixture->removeWasher($washer); $this->assertEquals($localObjectStorage, $this->fixture->getWasher()); }