Commit bad4016a authored by speedprogs_de's avatar speedprogs_de

added object builder

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51607 735d13b6-9817-0410-8766-e36946ffe9aa
parent 65bb0148
......@@ -161,10 +161,10 @@
/**
* Setter for lastUpload
*
* @param DataTime $lastUpload lastUpload
* @param DateTime $lastUpload lastUpload
* @return void
*/
public function setLastUpload($lastUpload) {
public function setLastUpload(DateTime $lastUpload) {
$this->lastUpload = $lastUpload;
}
......@@ -182,10 +182,10 @@
/**
* Setter for lastMaintained
*
* @param DataTime $lastMaintained lastMaintained
* @param DateTime $lastMaintained lastMaintained
* @return void
*/
public function setLastMaintained($lastMaintained) {
public function setLastMaintained(DateTime $lastMaintained) {
$this->lastMaintained = $lastMaintained;
}
......
......@@ -38,7 +38,7 @@
$query = $this->createQuery();
$query->setLimit((int) $limit);
// Workaround for random ordering until Extbase doesn't support this yet
// Workaround for random ordering while Extbase doesn't support this
// See: http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-July/005870.html
$backend = $this->objectManager->get('Tx_Extbase_Persistence_Storage_Typo3DbBackend');
$parameters = array();
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Extension provider using local files
*/
class Tx_TerFe2_Object_ObjectBuilder implements t3lib_Singleton {
/**
* @var Tx_Extbase_Persistence_Mapper_DataMapper
*/
protected $dataMapper;
/**
* @var Tx_Extbase_Persistence_Session
*/
protected $persistenceSession;
/**
* @var array
*/
protected $objects;
/**
* Injects the object storage
*
* @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
* @return void
*/
public function injectDataMapper(Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper) {
$this->dataMapper = $dataMapper;
}
/**
* Injects the persistence session
*
* @param Tx_Extbase_Persistence_Session $persistenceSession
* @return void
*/
public function injectPersistenceSession(Tx_Extbase_Persistence_Session $persistenceSession) {
$this->persistenceSession = $persistenceSession;
}
/**
* Create an object from given class and attributes
*
* @param string $className Name of the class
* @param string $identifier String to uniquely identify an object
* @param array $attributes Array of all class attributes
* @return void
*/
public function create($className, $identifier, array $attributes) {
if (empty($className) || empty($identifier) || empty($attributes)) {
throw new Exception('No valid params given to create an object');
}
if (!empty($this->objects[$className][$identifier])) {
return;
}
$object = reset($this->dataMapper->map($className, array($attributes)));
$this->objects[$className][$identifier] = $object;
$this->persistenceSession->unregisterReconstitutedObject($object);
}
/**
* Return a stored object
*
* @param string $className Name of the class
* @param string $identifier String to uniquely identify an object
* @return Tx_Extbase_DomainObject_DomainObjectInterface Stored object
*/
public function get($className, $identifier) {
if (empty($className) || empty($identifier)) {
throw new Exception('No valid params given to return an object');
}
if (!empty($this->objects[$className][$identifier])) {
return $this->objects[$className][$identifier];
}
return NULL;
}
/**
* Returns all objects
*
* @return array All objects
*/
public function getAll() {
return $this->objects;
}
}
?>
\ No newline at end of file
......@@ -78,6 +78,9 @@
// Load registry
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
// Load object builder
$this->objectBuilder = $this->objectManager->get('Tx_TerFe2_Object_ObjectBuilder');
}
......@@ -100,7 +103,8 @@
// Get extension structure from provider
$provider = $this->providerManager->getProvider($this->providerName);
$extensions = $provider->getExtensions($lastRun, $offset, $count);
//$extensions = $provider->getExtensions($lastRun, $offset, $count);
$extensions = array();
// Build models from extension structure
$this->createObjects($extensions);
......@@ -120,23 +124,23 @@
* @return void
*/
protected function createObjects(array $structure) {
t3lib_div::writeFile(PATH_site . 'debug.txt', print_r($structure, TRUE));
/**
* Ablauf:
* 1. Alle Autoren anlegen und in Array mit hash des autors als key und uid als value
* 2. Das selbe für relations
* 3. Das selbe für extensions
* 4. Versionen anlegen und uids nachtragen
*
tx_terfe2_domain_model_extension
tx_terfe2_domain_model_version
tx_terfe2_domain_model_relation
tx_terfe2_domain_model_author
*
$dataMapper = $this->objectManager->get('Tx_Extbase_Persistence_Mapper_DataMapper');
$rows = $dataMapper->map('Tx_TerFe2_Domain_Model_Version', array($extensions));
*/
* 1. Author Tx_TerFe2_Domain_Model_Author
* 2. Relation Tx_TerFe2_Domain_Model_Relation
* 3. Version Tx_TerFe2_Domain_Model_Version
* 4. Extension Tx_TerFe2_Domain_Model_Extension
*/
$structure = array(
'ext_key' => 'test'
);
$this->objectBuilder->create('Tx_TerFe2_Domain_Model_Extension', $structure['ext_key'], $structure);
$this->objectBuilder->get('Tx_TerFe2_Domain_Model_Extension', $structure['ext_key'])->setExtKey('blub');
$objects = $this->objectBuilder->getAll();
t3lib_div::writeFile(PATH_site . 'debug.txt', print_r($objects, TRUE));
}
......
......@@ -22,6 +22,7 @@
'tx_terfe2_extensionprovider_providerinterface' => $extensionClassesPath . 'ExtensionProvider/ProviderInterface.php',
'tx_terfe2_extensionprovider_providermanager' => $extensionClassesPath . 'ExtensionProvider/ProviderManager.php',
'tx_terfe2_extensionprovider_soapprovider' => $extensionClassesPath . 'ExtensionProvider/SoapProvider.php',
'tx_terfe2_object_objectbuilder' => $extensionClassesPath . 'Object/ObjectBuilder.php',
'tx_terfe2_persistence_abstractpersistence' => $extensionClassesPath . 'Persistence/AbstractPersistence.php',
'tx_terfe2_persistence_persistenceinterface' => $extensionClassesPath . 'Persistence/PersistenceInterface.php',
'tx_terfe2_persistence_registry' => $extensionClassesPath . 'Persistence/Registry.php',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment