nbproject
logs
+composer.lock
+vendor
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper;\r
+\r
+use Domain\Entities\IDivineEntity;\r
+use DataAccess\DataMapper\IDataMapper;\r
+use DataAccess\DataMapper\Helpers\AbstractPopulationHelper;\r
+use ReflectionClass;\r
+use PDO;\r
+\r
+class DataMapper implements IDataMapper\r
+{\r
+ private $_db;\r
+ private $_maps;\r
+ \r
+ public function __construct($maps)\r
+ {\r
+ //should probably do all this through a configuration object or something\r
+ $dsn = 'mysql:host=localhost;dbname=divinelegy;charset=utf8';\r
+ $username = 'root';\r
+ $password = 'toor';\r
+ $options = array(PDO::ATTR_EMULATE_PREPARES => false,\r
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);\r
+ \r
+ $this->_db = new PDO($dsn, $username, $password, $options); \r
+ $this->_maps = include $maps;\r
+ }\r
+ \r
+ public function find($id, $entity)\r
+ {\r
+ $statement = $this->_db->prepare(sprintf('SELECT * from %s WHERE id=%u',\r
+ $this->_maps[$entity]['table'],\r
+ $id));\r
+ $statement->execute();\r
+ $row = $statement->fetch();\r
+ \r
+ $className = $this->_maps[$entity]['class']; //the entity to instantiate and return\r
+ $constructors = AbstractPopulationHelper::getConstrutorArray($this->_maps, $entity, $row, $this->_db);\r
+ \r
+ if(count($constructors) == 0)\r
+ {\r
+ $class = new $className; \r
+ } else {\r
+ $r = new ReflectionClass($className);\r
+ $class = $r->newInstanceArgs($constructors);\r
+ }\r
+\r
+ $class->setId($row['id']);\r
+ return $class;\r
+ }\r
+ \r
+ public function save(IDivineEntity $entity)\r
+ {\r
+ $queries = AbstractPopulationHelper::generateUpdateSaveQuery($this->_maps, $entity, $entity->getId(), $this->_db);\r
+ echo '<pre>';\r
+ print_r($queries);\r
+ echo '</pre>';\r
+ }\r
+ \r
+ public function remove(IDivineEntity $entity) {\r
+ ;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+use DataAccess\DataMapper\Helpers\VOMapsHelper;\r
+use Domain\Entities\IDivineEntity;\r
+use Exception;\r
+\r
+class AbstractPopulationHelper\r
+{\r
+ \r
+ const REFERENCE_FORWARD = 1;\r
+ const REFERENCE_BACK = 2;\r
+ const REFERENCE_SELF = 3;\r
+ \r
+ static function getConstrutorArray($maps, $entity, $row, $db)\r
+ {\r
+ $constructors = array();\r
+ \r
+ foreach($maps[$entity]['maps'] as $constructor => $mapsHelper)\r
+ {\r
+ switch(get_class($mapsHelper))\r
+ {\r
+ case 'DataAccess\DataMapper\Helpers\IntMapsHelper':\r
+ case 'DataAccess\DataMapper\Helpers\VarcharMapsHelper':\r
+ $constructors[$constructor] = $row[$mapsHelper->getColumnName()];\r
+ break;\r
+ case 'DataAccess\DataMapper\Helpers\VOMapsHelper':\r
+ case 'DataAccess\DataMapper\Helpers\VOArrayMapsHelper':\r
+ case 'DataAccess\DataMapper\Helpers\EntityMapsHelper':\r
+ $constructors[$constructor] = $mapsHelper->populate($maps, $db, $entity, $row);\r
+ break;\r
+ }\r
+ }\r
+ \r
+ return $constructors;\r
+ }\r
+ \r
+ static function generateUpdateSaveQuery($maps, $entity, $id, $db, &$queries = array(), $extraColumns = array())\r
+ {\r
+ $entityMapsIndex = self::getMapsNameFromEntityObject($entity, $maps);\r
+ \r
+ if($id)\r
+ {\r
+ $query = sprintf('update %s set ', $maps[$entityMapsIndex]['table']); \r
+ } else {\r
+ $queryColumnNamesAndValues = array();\r
+ }\r
+ \r
+ foreach($maps[$entityMapsIndex]['maps'] as $mapsHelper)\r
+ {\r
+ $accessor = $mapsHelper->getAccessor();\r
+ $property = $entity->{$accessor}();\r
+\r
+ switch(get_class($mapsHelper))\r
+ {\r
+ case 'DataAccess\DataMapper\Helpers\VOMapsHelper':\r
+ //we have a vo. Determine which way the reference is\r
+ $voMapsIndex = self::getMapsNameFromEntityObject($property, $maps);\r
+ $refDir = self::getReferenceDirection(\r
+ $maps[$entityMapsIndex]['table'],\r
+ $maps[$voMapsIndex]['table'],\r
+ $entityMapsIndex,\r
+ $mapsHelper->getTableName(),\r
+ $db);\r
+ \r
+ switch($refDir)\r
+ {\r
+ // our table stores their ID, all we do is update\r
+ // our reference.\r
+ case self::REFERENCE_FORWARD:\r
+ $voTableId = self::findVOInDB($maps, $property, $db);\r
+ \r
+ if($id)\r
+ {\r
+ $query .= sprintf('%s=%u, ',\r
+ strtolower($mapsHelper->getVOName() . '_id'),\r
+ $voTableId);\r
+ } else {\r
+ // we have a forward reference to a value object.\r
+ // see if it exists first: \r
+ if($voTableId)\r
+ {\r
+ $queryColumnNamesAndValues[strtolower($mapsHelper->getTableName() . '_id')] = $voTableId;\r
+ } else {\r
+ //make a note that this field will need the id from another\r
+ self::generateUpdateSaveQuery($maps, $property, NULL, $db, $queries);\r
+ $queryColumnNamesAndValues[strtolower($mapsHelper->getTableName() . '_id')] = '%INDEX_REF_' . (count($queries)-1) . '%';\r
+ }\r
+ }\r
+\r
+ break;\r
+ case self::REFERENCE_SELF:\r
+ //no need to find ids, but we need the\r
+ //column names\r
+ $columns = self::resolveColumnNamesAndValues($maps, $property);\r
+ foreach($columns as $columnName=>$columnValue)\r
+ {\r
+ if($id)\r
+ {\r
+ //TODO: logic to determine what the value is? i.e., string, int etc?\r
+ $query .= sprintf('%s="%s, "',\r
+ $columnName,\r
+ $columnValue\r
+ );\r
+ } else {\r
+ $queryColumnNamesAndValues[$columnName] = $columnValue;\r
+ }\r
+ }\r
+\r
+ break;\r
+ case self::REFERENCE_BACK:\r
+ echo 'bleh';\r
+\r
+ $voId = self::findVOInDB($maps,\r
+ $property,\r
+ $db,\r
+ array(strtolower($entityMapsIndex . '_id') => $id));\r
+ if($voId)\r
+ {\r
+ self::generateUpdateSaveQuery($maps, $property, $voId, $db, $queries); \r
+ } else {\r
+ $extra = array(strtolower($entityMapsIndex . '_id') => '%MAIN_QUERY_ID%');\r
+ self::generateUpdateSaveQuery($maps, $property, NULL, $db, $queries, $extra);\r
+ }\r
+ break;\r
+ }\r
+\r
+ break;\r
+\r
+ // We should never update referenced entities, the db\r
+ // should always store an ID as a reference to them.\r
+ //\r
+ // In the case where we cannot find the entity in the database,\r
+ // throw an exception ?\r
+ case 'DataAccess\DataMapper\Helpers\EntityMapsHelper':\r
+ $subEntityMapsIndex = self::getMapsNameFromEntityObject($property, $maps);\r
+ $refDir = self::getReferenceDirection(\r
+ $maps[$entityMapsIndex]['table'],\r
+ $maps[$subEntityMapsIndex]['table'],\r
+ $entityMapsIndex,\r
+ $mapsHelper->getTableName(),\r
+ $db);\r
+\r
+ switch($refDir)\r
+ {\r
+ // our table stores their ID, all we do is update\r
+ // our reference.\r
+ case self::REFERENCE_FORWARD:\r
+ if($property->getId())\r
+ {\r
+ // we exist in db already, update our reference\r
+ if($id)\r
+ {\r
+ $query .= sprintf('%s=%u, ',\r
+ strtolower($mapsHelper->getEntityName() . '_id'),\r
+ $property->getId());\r
+ } else {\r
+ //not in db yet. make new ref\r
+ $queryColumnNamesAndValues[strtolower($mapsHelper->getEntityName() . '_id')] = $property->getId();\r
+ }\r
+ } else {\r
+ // The entity we care about references an entity that\r
+ // has not yet been saved.\r
+ //\r
+ // TODO: Should we _try_ to save it? Or should\r
+ // it be enforced that entites already exist in the db?\r
+ // In the case of something like referencing a user entity,\r
+ // then for sure the user should already be saved because\r
+ // it makes no sense to assign a user at the time of simfile\r
+ // upload, they should have already completed the process.\r
+ // but could there be other entities where it does make sense\r
+ // for them to be created at the time of something else ?\r
+ throw new Exception(sprintf(\r
+ 'Could not find referenced entity, %s, in the database. Has it been saved yet?',\r
+ $mapsHelper->getEntityName()));\r
+ }\r
+ break;\r
+ }\r
+ break;\r
+ case 'DataAccess\DataMapper\Helpers\IntMapsHelper':\r
+ if($id)\r
+ {\r
+ //easy case, plain values in our table.\r
+ $query .= sprintf('%s=%u, ',\r
+ $mapsHelper->getColumnName(),\r
+ $property); \r
+ } else {\r
+ if(is_bool($property))\r
+ {\r
+ $property = ($property) ? '1' : '0';\r
+ }\r
+ $queryColumnNamesAndValues[$mapsHelper->getColumnName()] = sprintf('%u', $property);\r
+ }\r
+ break;\r
+ case 'DataAccess\DataMapper\Helpers\VarcharMapsHelper':\r
+ if($id){\r
+ //easy case, plain values in our table.\r
+ $query .= sprintf('%s="%s", ',\r
+ $mapsHelper->getColumnName(),\r
+ $property); \r
+ } else {\r
+ $queryColumnNamesAndValues[$mapsHelper->getColumnName()] = sprintf('"%s"', $property);\r
+ }\r
+\r
+ break;\r
+\r
+ // I am making a bit of an assumption here. In my mind it only\r
+ // makes sense for an array of VOs to be stored in a different\r
+ // table in the DB since the main row can't possibly store\r
+ // different objects.\r
+ //\r
+ // in that regard, the way this works is that mapVOArrayToIds\r
+ // simply queries the DB and returns the VO ids in order then\r
+ // I assume that the object also has them in the same order\r
+ // (which it will if it is pulled out by this mapper.\r
+ //\r
+ // in the case of setting up a new entity, the VOs should never\r
+ // exist in the first place, so we just make them.\r
+ case 'DataAccess\DataMapper\Helpers\VOArrayMapsHelper':\r
+ if($id)\r
+ {\r
+ // If we assume that all elements in the array are the same then\r
+ // we can just use the first one to figure out which maps entry to use\r
+ $subEntityMapsIndex = self::getMapsNameFromEntityObject($property[0], $maps);\r
+ $voIds = self::mapVOArrayToIds($maps[$subEntityMapsIndex]['table'],\r
+ array(strtolower($entityMapsIndex . '_id'), $id),\r
+ $db);\r
+\r
+ foreach($property as $index => $propertyArrayElement)\r
+ {\r
+ self::generateUpdateSaveQuery($maps, $propertyArrayElement, $voIds[$index], $db, $queries);\r
+ }\r
+\r
+ break;\r
+ } else {\r
+ foreach($property as $propertyArrayElement)\r
+ {\r
+ // TODO: TRICKY! Since this is a back-reference, it\r
+ // needs the ID of the object we're trying to save\r
+ // to complete\r
+ $extra = array(strtolower($entityMapsIndex . '_id') => '%MAIN_QUERY_ID%');\r
+ self::generateUpdateSaveQuery($maps, $propertyArrayElement, NULL, $db, $queries, $extra);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ if($id)\r
+ {\r
+ $query = substr($query, 0, -2);\r
+ $query .= sprintf(' WHERE id=%u', $id);\r
+ } else {\r
+ $queryColumnNamesAndValues = array_merge($queryColumnNamesAndValues, $extraColumns);\r
+ $query = sprintf('INSERT INTO %s (%s) VALUES (%s)',\r
+ $maps[$entityMapsIndex]['table'],\r
+ implode(', ', array_keys($queryColumnNamesAndValues)),\r
+ implode(', ', $queryColumnNamesAndValues));\r
+ }\r
+ \r
+ $queries[] = $query;\r
+ return $queries;\r
+ }\r
+ \r
+ static private function getMapsNameFromEntityObject($entity, $maps)\r
+ {\r
+ //todo maybe check that $entity is vo or entity\r
+ \r
+ $classname = get_class($entity);\r
+ foreach ($maps as $entityName => $map)\r
+ {\r
+ if($map['class'] == $classname)\r
+ {\r
+ return $entityName;\r
+ }\r
+ }\r
+ }\r
+ \r
+ static private function getReferenceDirection($tableA, $tableB, $nameA, $nameB, $db)\r
+ {\r
+ //TODO: check if tables are the same and return a constant for that\r
+ //echo '!!! ' . $tableA . ' needs ' . $nameB . ' : ' . $tableB . ' needs ' . $nameA . ' !!!<br />';\r
+ \r
+ if($tableA === $tableB)\r
+ {\r
+ return self::REFERENCE_SELF;\r
+ }\r
+ \r
+ // first look in table A for a reference to B\r
+ $statement = $db->prepare(sprintf(\r
+ 'SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`="divinelegy" AND `TABLE_NAME`="%s"',\r
+ $tableA));\r
+\r
+ $statement->execute();\r
+ $rows = $statement->fetchAll();\r
+ \r
+ //print_r($rows);\r
+ \r
+ foreach($rows as $row)\r
+ {\r
+ if($row['COLUMN_NAME'] == strtolower($nameB . '_id'))\r
+ {\r
+ return self::REFERENCE_FORWARD;\r
+ }\r
+ }\r
+ \r
+ // now look in table b for a reference to a\r
+ $statement = $db->prepare(sprintf(\r
+ 'SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`="divinelegy" AND `TABLE_NAME`="%s"',\r
+ $tableB));\r
+\r
+ $statement->execute();\r
+ $rows = $statement->fetchAll();\r
+ \r
+ foreach($rows as $row)\r
+ {\r
+ if($row['COLUMN_NAME'] == strtolower($nameA . '_id'))\r
+ {\r
+ return self::REFERENCE_BACK;\r
+ }\r
+ }\r
+ }\r
+ \r
+ // can use this when we reference a VO\r
+ static public function findVOInDB($maps, $VO, $db, $extraColumns = array())\r
+ {\r
+ $mapsIndex = self::getMapsNameFromEntityObject($VO, $maps);\r
+ $table = $maps[$mapsIndex]['table'];\r
+ \r
+ $columns = array_merge(self::resolveColumnNamesAndValues($maps, $VO), $extraColumns);\r
+ \r
+ $query = "SELECT * FROM $table where ";\r
+ \r
+ foreach($columns as $columnName => $columnValue)\r
+ {\r
+ $query .= sprintf('%s="%s" AND ', $columnName, $columnValue);\r
+ }\r
+ \r
+ $query = substr($query, 0, -4);\r
+ $statement = $db->prepare($query);\r
+ $statement->execute();\r
+ $row = $statement->fetch();\r
+ \r
+ return $row['id'];\r
+ }\r
+ \r
+ // this will figure out what columns belong to an entity and\r
+ // map the column names to the current entity values\r
+ static public function resolveColumnNamesAndValues($maps, $entity, $originalTable = null, &$columnNamesAndValues = array())\r
+ {\r
+ $mapsIndex = self::getMapsNameFromEntityObject($entity, $maps);\r
+ \r
+ // This is the name of the table that the current object\r
+ // we are looking at belongs to. We need to compare this\r
+ // to original table to decide what to do.\r
+ $currentTable = $maps[$mapsIndex]['table'];\r
+ \r
+ if(!$originalTable)\r
+ {\r
+ // this will be the table that the VO we care about is stored in\r
+ // we check all future values to make sure they belong to this table.\r
+ // on the first pass we pull it out, and then on subsequent passes\r
+ // it should come in through the function call.\r
+ $originalTable = $currentTable;\r
+ }\r
+\r
+ foreach($maps[$mapsIndex]['maps'] as $mapsHelper)\r
+ {\r
+ switch(get_class($mapsHelper))\r
+ {\r
+ case 'DataAccess\DataMapper\Helpers\VOMapsHelper':\r
+ $accessor = $mapsHelper->getAccessor();\r
+ $VO = $entity->{$accessor}();\r
+ self::resolveColumnNamesAndValues($maps, $VO, $originalTable, $columnNamesAndValues);\r
+ break;\r
+ case 'DataAccess\DataMapper\Helpers\VarcharMapsHelper':\r
+ case 'DataAccess\DataMapper\Helpers\IntMapsHelper':\r
+ //is plain value.\r
+ \r
+ if($currentTable == $originalTable)\r
+ {\r
+ //It also keeps values in our table. Saving.\r
+ $accessor = $mapsHelper->getAccessor();\r
+ $value = $entity->{$accessor}();\r
+ \r
+ $columnNamesAndValues[$mapsHelper->getColumnName()] = $value;\r
+ } else {\r
+ //It does not store values in our table\r
+ //TODO: Should I try check if our table references the id of the record in the other table?\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ \r
+ return $columnNamesAndValues;\r
+ }\r
+ \r
+ // When we have VO arrays, it should be the case that there is another\r
+ // table that references us. If we assume entries are in the db in the\r
+ // same order they are in the array, it should be possible to map them up.\r
+ // This way we can update existing VO entries instead of deleting and\r
+ // making new ones. And if there are VOs where we can't get an ID, that\r
+ // means we have to make a new one.\r
+ //\r
+ // Assumption: Array contains entries of all the same type\r
+ static public function mapVOArrayToIds($voTable, $columnToMatch, $db)\r
+ {\r
+ $query = sprintf('SELECT id from %s WHERE %s=%u',\r
+ $voTable,\r
+ $columnToMatch[0],\r
+ $columnToMatch[1]);\r
+ \r
+ $statement = $db->prepare($query);\r
+ $statement->execute();\r
+ $rows = $statement->fetchAll();\r
+ \r
+ $map = array();\r
+ \r
+ foreach($rows as $row)\r
+ {\r
+ $map[] = $row['id'];\r
+ }\r
+ \r
+ return $map;\r
+ }\r
+}\r
+\r
+//go off and resolve all column names for this table recursively\r
+//do a check to make sure the VO we are investigating is in the same table\r
+// -if it is: good, record its column name and value\r
+// -if it isn't, we need to find this next VO in the db and record its ID as our column value \r
+// -assuming a forward reference (IE our table has a column called voname_id.\r
+// -if it doesn't, then we don't have to worry about it\r
+\r
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+use ReflectionClass;\r
+\r
+class EntityMapsHelper\r
+{\r
+ private $_entityName;\r
+ private $_tableName;\r
+ private $_accessor;\r
+ \r
+ public function __construct($entityName, $accessor, $tableName)\r
+ {\r
+ $this->_entityName = $entityName;\r
+ \r
+ if($tableName) {\r
+ $this->_tableName = $tableName;\r
+ } else {\r
+ $this->_tableName = strtolower($entityName);\r
+ }\r
+ \r
+ if($accessor)\r
+ {\r
+ $this->_accessor = $accessor;\r
+ } else\r
+ {\r
+ $this->_accessor = 'get'. str_replace('_', '', $entityName);\r
+ }\r
+ }\r
+ \r
+ public function getEntityName()\r
+ {\r
+ return $this->_entityName;\r
+ }\r
+ \r
+ public function getAccessor()\r
+ {\r
+ return $this->_accessor;\r
+ }\r
+ \r
+ public function getTableName()\r
+ {\r
+ return $this->_tableName;\r
+ }\r
+ \r
+ public function populate($maps, $db, $parent, $row)\r
+ {\r
+ $className = $maps[$this->_entityName]['class'];\r
+ $table = $maps[$this->_entityName]['table'];\r
+\r
+ // If the table we already have contains the id of a row we need in\r
+ // another table\r
+ if(isset($row[$this->_tableName . '_id'])) {\r
+ $join_id = $row[$this->_tableName . '_id'];\r
+ $statement = $db->prepare(sprintf('SELECT * from %s WHERE id=%u',\r
+ $table,\r
+ $join_id));\r
+ $statement->execute();\r
+ $row = $statement->fetch();\r
+ }\r
+ \r
+ $constructors = AbstractPopulationHelper::getConstrutorArray($maps, $this->_entityName, $row, $db);\r
+\r
+ if(count($constructors) == 0)\r
+ {\r
+ $class = new $className;\r
+ } else {\r
+ $r = new ReflectionClass($className);\r
+ $class = $r->newInstanceArgs($constructors);\r
+ }\r
+ \r
+ $class->setId($row['id']);\r
+ return $class;\r
+ }\r
+}\r
+\r
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+class IntMapsHelper\r
+{ \r
+ private $_mapIndex;\r
+ private $_tableName;\r
+ private $_accessor;\r
+ \r
+ public function __construct($mapIndex, $accessor, $tableName)\r
+ {\r
+ $this->_mapIndex = $mapIndex;\r
+ \r
+ if($tableName) {\r
+ $this->_tableName = $tableName;\r
+ } else {\r
+ $this->_tableName = strtolower($mapIndex);\r
+ }\r
+ \r
+ if($accessor)\r
+ {\r
+ $this->_accessor = $accessor;\r
+ } else\r
+ {\r
+ $this->_accessor = 'get'. str_replace('_', '', $mapIndex);\r
+ }\r
+ }\r
+\r
+ public function getAccessor()\r
+ {\r
+ return $this->_accessor;\r
+ }\r
+ \r
+ public function getTableName()\r
+ {\r
+ return $this->_tableName;\r
+ }\r
+\r
+ public function getColumnName()\r
+ {\r
+ return $this->_mapIndex;\r
+ } \r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+use ReflectionClass;\r
+\r
+class VOArrayMapsHelper\r
+{\r
+ private $_voName;\r
+ private $_tableName;\r
+ private $_accessor;\r
+ \r
+ public function __construct($voName, $accessor, $tableName)\r
+ {\r
+ $this->_voName = $voName;\r
+ \r
+ if($tableName) {\r
+ $this->_tableName = $tableName;\r
+ } else {\r
+ $this->_tableName = strtolower($voName);\r
+ }\r
+ \r
+ if($accessor)\r
+ {\r
+ $this->_accessor = $accessor;\r
+ } else\r
+ {\r
+ $this->_accessor = 'get'. str_replace('_', '', $voName);\r
+ }\r
+ }\r
+\r
+ public function getAccessor()\r
+ {\r
+ return $this->_accessor;\r
+ }\r
+ \r
+ public function getVOName()\r
+ {\r
+ return $this->_voName;\r
+ }\r
+ \r
+ public function getTableName()\r
+ {\r
+ return $this->_tableName;\r
+ }\r
+ \r
+ public function populate($maps, $db, $parent, $row)\r
+ {\r
+ $className = $maps[$this->_voName]['class'];\r
+ $table = $maps[$this->_voName]['table'];\r
+ $VOArray = array();\r
+ \r
+ // in this case we look in another table for this row's id\r
+ $join_id = $row['id']; \r
+ $statement = $db->prepare(sprintf('SELECT * from %s WHERE %s=%u',\r
+ $table,\r
+ strtolower($parent . '_id'),\r
+ $join_id\r
+ ));\r
+ \r
+ $statement->execute();\r
+ $rows = $statement->fetchAll();\r
+ \r
+ foreach($rows as $row)\r
+ { \r
+ $constructors = AbstractPopulationHelper::getConstrutorArray($maps, $this->_voName, $row, $db);\r
+ \r
+ if(count($constructors) == 0)\r
+ {\r
+ $VOArray[] = new $className;\r
+ } else {\r
+ $r = new ReflectionClass($className);\r
+ $VOArray[] = $r->newInstanceArgs($constructors);\r
+ }\r
+ }\r
+ \r
+ return $VOArray;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+use ReflectionClass;\r
+\r
+class VOMapsHelper\r
+{\r
+ private $_voName;\r
+ private $_tableName;\r
+ private $_accessor;\r
+ \r
+ public function __construct($voName, $accessor, $tableName)\r
+ {\r
+ $this->_voName = $voName;\r
+ \r
+ if($tableName) {\r
+ $this->_tableName = $tableName;\r
+ } else {\r
+ $this->_tableName = strtolower($voName);\r
+ }\r
+ \r
+ if($accessor)\r
+ {\r
+ $this->_accessor = $accessor;\r
+ } else\r
+ {\r
+ $this->_accessor = 'get'. str_replace('_', '', $voName);\r
+ }\r
+ }\r
+ \r
+ public function getAccessor()\r
+ {\r
+ return $this->_accessor;\r
+ }\r
+ \r
+ public function getVOName()\r
+ {\r
+ return $this->_voName;\r
+ }\r
+ \r
+ public function getTableName()\r
+ {\r
+ return $this->_tableName;\r
+ }\r
+ \r
+ public function populate($maps, $db, $parent, $row)\r
+ {\r
+ $className = $maps[$this->_voName]['class'];\r
+ $table = $maps[$this->_voName]['table'];\r
+\r
+ // If the table we already have contains the id of a row we need in\r
+ // another table \r
+ if(isset($row[$this->_tableName . '_id'])) {\r
+ $join_id = $row[$this->_tableName . '_id'];\r
+ $statement = $db->prepare(sprintf('SELECT * from %s WHERE id=%u',\r
+ $table,\r
+ $join_id));\r
+ \r
+ $statement->execute();\r
+ $row = $statement->fetch();\r
+ } elseif($maps[$this->_voName]['table'] != $maps[$parent]['table']) { \r
+ // in this case we look in another table for this row's id\r
+ $join_id = $row['id'];\r
+ $statement = $db->prepare(sprintf('SELECT * from %s WHERE %s=%u',\r
+ $table,\r
+ strtolower($parent . '_id'),\r
+ $join_id\r
+ ));\r
+ \r
+ $statement->execute();\r
+ $row = $statement->fetch();\r
+ }\r
+ \r
+ $constructors = AbstractPopulationHelper::getConstrutorArray($maps, $this->_voName, $row, $db);\r
+ \r
+ if(count($constructors) == 0)\r
+ {\r
+ return new $className;\r
+ } else {\r
+ $r = new ReflectionClass($className);\r
+ return $r->newInstanceArgs($constructors);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper\Helpers;\r
+\r
+class VarcharMapsHelper\r
+{ \r
+ private $_mapIndex;\r
+ private $_tableName;\r
+ private $_accessor;\r
+ \r
+ public function __construct($mapIndex, $accessor, $tableName)\r
+ {\r
+ $this->_mapIndex = $mapIndex;\r
+ \r
+ if($tableName) {\r
+ $this->_tableName = $tableName;\r
+ } else {\r
+ $this->_tableName = strtolower($mapIndex);\r
+ }\r
+ \r
+ if($accessor)\r
+ {\r
+ $this->_accessor = $accessor;\r
+ } else\r
+ {\r
+ $this->_accessor = 'get'. str_replace('_', '', $mapIndex);\r
+ }\r
+ }\r
+\r
+ public function getTableName()\r
+ {\r
+ return $this->_tableName;\r
+ }\r
+\r
+ public function getColumnName()\r
+ {\r
+ return $this->_mapIndex;\r
+ } \r
+ \r
+ public function getAccessor()\r
+ {\r
+ return $this->_accessor;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\DataMapper;\r
+\r
+use Domain\Entities\IDivineEntity;\r
+\r
+interface IDataMapper\r
+{\r
+ //find id in table and return it as an entity\r
+ public function find($id, $table);\r
+ //insert/update entity in table\r
+ public function save(IDivineEntity $entity);\r
+ //remove entity from table\r
+ public function remove(IDivineEntity $entity);\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace DataAccess\StepMania;\r
+\r
+use Domain\Entities\StepMania\Simfile;\r
+\r
+interface ISimfileRepository\r
+{\r
+ public function find($id);\r
+ public function save(Simfile $simfile);\r
+ public function remove(Simfile $simfile);\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace DataAccess;\r
+\r
+use DataAccess\DataMapper\Helpers\EntityMapsHelper;\r
+use DataAccess\DataMapper\Helpers\VOMapsHelper;\r
+use DataAccess\DataMapper\Helpers\VOArrayMapsHelper;\r
+use DataAccess\DataMapper\Helpers\IntMapsHelper;\r
+use DataAccess\DataMapper\Helpers\VarcharMapsHelper; \r
+\r
+function Entity($mapName, $accessor=null, $tableName = null)\r
+{\r
+ return new EntityMapsHelper($mapName, $accessor, $tableName);\r
+}\r
+\r
+function VO($mapName, $accessor=null, $tableName = null)\r
+{\r
+ return new VOMapsHelper($mapName, $accessor, $tableName);\r
+}\r
+\r
+function VOArray($mapName, $accessor=null, $tableName = null)\r
+{\r
+ return new VOArrayMapsHelper($mapName, $accessor, $tableName);\r
+}\r
+\r
+function Varchar($mapName, $accessor=null, $tableName = null)\r
+{\r
+ return new VarcharMapsHelper($mapName, $accessor, $tableName);\r
+}\r
+\r
+function Int($mapName, $accessor=null, $tableName = null)\r
+{\r
+ return new IntMapsHelper($mapName, $accessor, $tableName);\r
+}\r
+\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\ConstantsAndTypes;\r
+\r
+abstract class SimfileConstants\r
+{\r
+ const HAS_BPM_CHANGES = true;\r
+ const NO_BPM_CHANGES = false;\r
+ const HAS_FG_CHANGES = true;\r
+ const NO_FG_CHANGES = false;\r
+ const HAS_BG_CHANGES = true;\r
+ const NO_BG_CHANGES = false;\r
+ const HAS_STOPS = true;\r
+ const NO_STOPS = false;\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\Entities\IDivineEntity;\r
+\r
+abstract class AbstractEntity implements IDivineEntity\r
+{\r
+ protected $id;\r
+ \r
+ public function setId($id) {\r
+ if(isset($this->id)) {\r
+ // throw new Exception('ID already set.');\r
+ }\r
+ \r
+ $this->id = $id;\r
+ }\r
+ \r
+ public function getId() {\r
+ return $this->id;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+interface IDivineEntity\r
+{\r
+ public function getId();\r
+ public function setId($id);\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+interface IUser\r
+{\r
+ public function setId($id);\r
+ public function getId();\r
+ public function getName();\r
+ public function getTags();\r
+ public function getCountry();\r
+ public function getDisplayName();\r
+ public function getYearsStepArtist();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\VOs\ICountry;\r
+use Domain\VOs\IName;\r
+\r
+interface IUserBuilder\r
+{\r
+ public function With_Country(ICountry $country);\r
+ public function With_DisplayName($name);\r
+ public function With_Name(IName $name);\r
+ public function With_Tags(array $tags);\r
+ public function With_YearsStepArtist($years);\r
+ public function build();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+interface ISimfile\r
+{\r
+ public function getTitle();\r
+ public function getArtist();\r
+ public function getUploader();\r
+ public function getBPM();\r
+ public function hasBPMChanges();\r
+ public function hasStops();\r
+ public function hasFgChanges();\r
+ public function hasBgChanges();\r
+ \r
+ public function addStepChart(StepChart $stepChart);\r
+ public function getSteps();\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+use Domain\VOs\StepMania\IArtist;\r
+use Domain\VOs\StepMania\IBPM;\r
+use Domain\Entities\IUser;\r
+\r
+interface ISimfileBuilder\r
+{\r
+ public function With_Title($title);\r
+ public function With_Artist(IArtist $artist);\r
+ public function With_Uploader(IUser $uploader);\r
+ public function With_BPM(IBPM $bpm);\r
+ public function With_BpmChanges($const);\r
+ public function With_Stops($const);\r
+ public function With_FgChanges($const);\r
+ public function With_BgChanges($const);\r
+ public function With_Steps(array $steps);\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+use Domain\VOs\StepMania\IArtist;\r
+use Domain\VOs\StepMania\IBPM;\r
+use Domain\VOs\StepMania\IStepChart;\r
+use Domain\ConstantsAndTypes\SIMFILE_CONSTANT;\r
+use Domain\Exception\InvalidStepChartException;\r
+use Domain\Entities\StepMania\ISimfile;\r
+use Domain\Entities\IUser;\r
+use Domain\Entities\AbstractEntity;\r
+\r
+class Simfile extends AbstractEntity implements ISimfile\r
+{ \r
+ private $_title;\r
+ private $_artist;\r
+ private $_uploader;\r
+ private $_bpm;\r
+ private $_bpmChanges = false;\r
+ private $_stops = false;\r
+ private $_fgChanges = false;\r
+ private $_bgChanges = false;\r
+ private $_steps;\r
+ \r
+ public function __construct(\r
+ $title,\r
+ IArtist $artist,\r
+ IUser $uploader,\r
+ IBPM $bpm,\r
+ $bpmChanges,\r
+ $stops,\r
+ $fgChanges,\r
+ $bgChanges,\r
+ array $steps\r
+ ) {\r
+ $this->_title = $title;\r
+ $this->_artist = $artist;\r
+ $this->_uploader = $uploader;\r
+ $this->_bpm = $bpm;\r
+ $this->_bpmChanges = $bpmChanges;\r
+ $this->_stops = $stops;\r
+ $this->_fgChanges = $fgChanges;\r
+ $this->_bgChanges = $bgChanges;\r
+\r
+ foreach($steps as $stepChart) {\r
+ if(!$stepChart instanceof IStepChart) {\r
+ throw new InvalidStepChartException(sprintf('Invalid StepChart array. All array elements must be an instance of Stepchart.'));\r
+ }\r
+ }\r
+ \r
+ $this->_steps = $steps;\r
+ }\r
+ \r
+ public function getTitle()\r
+ {\r
+ return $this->_title;\r
+ }\r
+ \r
+ public function getArtist()\r
+ {\r
+ return $this->_artist;\r
+ }\r
+ \r
+ public function getUploader()\r
+ {\r
+ return $this->_uploader;\r
+ }\r
+ \r
+ public function getBPM()\r
+ {\r
+ return $this->_bpm;\r
+ }\r
+ \r
+ public function hasBPMChanges()\r
+ {\r
+ return $this->_bpmChanges;\r
+ }\r
+ \r
+ public function hasStops()\r
+ {\r
+ return $this->_stops;\r
+ }\r
+ \r
+ public function hasFgChanges()\r
+ {\r
+ return $this->_fgChanges;\r
+ }\r
+ \r
+ public function hasBgChanges()\r
+ {\r
+ return $this->_bgChanges;\r
+ }\r
+ \r
+ public function addStepChart(StepChart $stepChart) {\r
+ $this->_steps[] = $stepChart;\r
+ }\r
+ \r
+ public function getSteps()\r
+ {\r
+ return $this->_steps;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+use Domain\VOs\StepMania\IArtist;\r
+use Domain\VOs\StepMania\IBPM;\r
+use Domain\Entities\IUser;\r
+use Domain\Entities\StepMania\ISimfileFactory;\r
+use Domain\Entities\StepMania\ISimfileBuilder;\r
+\r
+class SimfileBuilder implements ISimfileBuilder \r
+{ \r
+ /* var $_simfileFactor Domain\Entities\StepMania\ISimfileFactory */\r
+ private $_simfileFactory;\r
+ private $_title;\r
+ private $_artist;\r
+ private $_uploader;\r
+ private $_bpm;\r
+ private $_bpmChanges;\r
+ private $_stops;\r
+ private $_fgChanges;\r
+ private $_bgChanges;\r
+ private $_steps;\r
+ \r
+ //override parent\r
+ public function __construct(ISimfileFactory $simfileFactory) {\r
+ $this->_simfileFactory = $simfileFactory;\r
+ }\r
+ \r
+ public function With_Title($title)\r
+ {\r
+ $this->_title = $title;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Artist(IArtist $artist) {\r
+ $this->_artist = $artist;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Uploader(IUser $uploader) {\r
+ $this->_uploader = $uploader;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_BPM(IBPM $bpm) {\r
+ $this->_bpm = $bpm;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_BpmChanges($const) {\r
+ $this->_bpmChanges = $const;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Stops($const) {\r
+ $this->_stops = $const;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_FgChanges($const) {\r
+ $this->_fgChanges = $const;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_BgChanges($const) {\r
+ $this->_bgChanges = $const;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Steps(array $steps) {\r
+ $this->_steps = $steps;\r
+ return $this;\r
+ }\r
+ \r
+ public function build() {\r
+ return $this->_simfileFactory\r
+ ->createInstance($this->_title,\r
+ $this->_artist,\r
+ $this->_uploader,\r
+ $this->_bpm,\r
+ $this->_bpmChanges,\r
+ $this->_stops,\r
+ $this->_fgChanges,\r
+ $this->_bgChanges,\r
+ $this->_steps);\r
+ }\r
+}\r
+\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+use Domain\VOs\StepMania\IArtist;\r
+use Domain\VOs\StepMania\IBPM;\r
+use Domain\Entities\StepMania\Simfile;\r
+use Domain\Entities\IUser;\r
+\r
+interface ISimfileFactory\r
+{\r
+ public function createInstance(\r
+ $title,\r
+ IArtist $artist,\r
+ IUser $uploader,\r
+ IBPM $bpm,\r
+ $bpmChanges,\r
+ $stops,\r
+ $fgChanges,\r
+ $bgChanges,\r
+ array $steps\r
+ );\r
+}\r
+\r
+class SimfileFactory implements ISimfileFactory\r
+{\r
+ public function createInstance(\r
+ $title,\r
+ IArtist $artist,\r
+ IUser $uploader,\r
+ IBPM $bpm,\r
+ $bpmChanges,\r
+ $stops,\r
+ $fgChanges,\r
+ $bgChanges,\r
+ array $steps\r
+ ) {\r
+ return new Simfile(\r
+ $title,\r
+ $artist,\r
+ $uploader, //TODO: will be user object\r
+ $bpm,\r
+ $bpmChanges,\r
+ $stops,\r
+ $fgChanges,\r
+ $bgChanges,\r
+ $steps\r
+ );\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities\StepMania;\r
+\r
+use Domain\ConstantsAndTypes\SIMFILE_CONSTANT;\r
+use Domain\VOs\StepMania\IArtist;\r
+use Domain\VOs\StepMania\IBPM;\r
+use Domain\Entities\StepMania\ISimfileBuilder;\r
+use Domain\Entities\IUser;\r
+\r
+interface ISimfileStepByStepBuilder\r
+{\r
+ public function With_Title($title);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_Title\r
+{\r
+ public function With_Artist(IArtist $artist);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_Artist\r
+{\r
+ public function With_Uploader(IUser $uploader); //TODO: Make user object\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_Uploader\r
+{\r
+ public function With_BPM(IBPM $bpm);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_BPM\r
+{\r
+ public function With_BpmChanges($const);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_BpmChanges\r
+{\r
+ public function With_Stops($const);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_Stops\r
+{\r
+ public function With_FgChanges($const);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_FgChanges\r
+{\r
+ public function With_BgChanges($const);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_BgChanges\r
+{\r
+ public function With_Steps(array $steps);\r
+}\r
+\r
+interface ISimfileStepByStepBuilder_With_Steps\r
+{\r
+ public function build();\r
+}\r
+\r
+\r
+abstract class AbstractSimfileStepByStepBuilder\r
+{\r
+ /* @var $_simfileBuilder Domain\Entities\StepMania\ISimfileBuilder */\r
+ protected $_simfileBuilder;\r
+ \r
+ public function __construct(ISimfileBuilder $builder)\r
+ {\r
+ $this->_simfileBuilder = $builder;\r
+ }\r
+}\r
+\r
+\r
+class SimfileStepByStepBuilder extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder\r
+{\r
+ public function With_Title($title) {\r
+ $this->_simfileBuilder->With_Title($title);\r
+ return new SimfileStepByStepBuilder_With_Title($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_Title extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_Title\r
+{ \r
+ public function With_Artist(IArtist $artist)\r
+ {\r
+ $this->_simfileBuilder->With_Artist($artist);\r
+ return new SimfileStepByStepBuilder_With_Artist($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_Artist extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_Artist\r
+{ \r
+ public function With_Uploader(IUser $uploader)\r
+ {\r
+ $this->_simfileBuilder->With_Uploader($uploader);\r
+ return new SimfileStepByStepBuilder_With_Uploader($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_Uploader extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_Uploader\r
+{\r
+ public function With_BPM(IBPM $bpm) {\r
+ $this->_simfileBuilder->With_BPM($bpm);\r
+ return new SimfileStepByStepBuilder_With_BPM($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_BPM extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_BPM\r
+{\r
+ public function With_BpmChanges($const) {\r
+ $this->_simfileBuilder->With_BpmChanges($const);\r
+ return new SimfileStepByStepBuilder_With_BpmChanges($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_BpmChanges extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_BpmChanges\r
+{\r
+ public function With_Stops($const) {\r
+ $this->_simfileBuilder->With_Stops($const);\r
+ return new SimfileStepByStepBuilder_With_Stops($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_Stops extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_Stops\r
+{\r
+ public function With_FgChanges($const) {\r
+ $this->_simfileBuilder->With_FgChanges($const);\r
+ return new SimfileStepByStepBuilder_With_FgChanges($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_FgChanges extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_FgChanges\r
+{\r
+ public function With_BgChanges($const) {\r
+ $this->_simfileBuilder->With_BgChanges($const);\r
+ return new SimfileStepByStepBuilder_With_BgChanges($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_BgChanges extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_BgChanges\r
+{\r
+ public function With_Steps(array $steps) {\r
+ $this->_simfileBuilder->With_Steps($steps);\r
+ return new SimfileStepByStepBuilder_With_Steps($this->_simfileBuilder);\r
+ }\r
+}\r
+\r
+class SimfileStepByStepBuilder_With_Steps extends AbstractSimfileStepByStepBuilder implements ISimfileStepByStepBuilder_With_Steps\r
+{\r
+ public function build() {\r
+ return $this->_simfileBuilder\r
+ ->build();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\Entities\IUser;\r
+use Domain\Entities\AbstractEntity;\r
+use Domain\VOs\ICountry;\r
+use Domain\VOs\IName;\r
+\r
+class User extends AbstractEntity implements IUser\r
+{\r
+ private $_id;\r
+ private $_country;\r
+ private $_displayName;\r
+ private $_name;\r
+ private $_tags;\r
+ private $_yearsStepArtist;\r
+ \r
+ public function __construct(\r
+ ICountry $country,\r
+ $displayName,\r
+ IName $name,\r
+ array $tags\r
+ ) {\r
+ $this->_country = $country;\r
+ $this->_displayName = $displayName;\r
+ $this->_name = $name;\r
+ $this->_tags = $tags;\r
+ }\r
+ \r
+ public function getCountry() {\r
+ return $this->_country;\r
+ }\r
+ \r
+ public function getDisplayName() {\r
+ return $this->_displayName;\r
+ }\r
+ \r
+ public function getName() {\r
+ return $this->_name;\r
+ }\r
+ \r
+ public function getTags() {\r
+ return $this->_tags;\r
+ }\r
+ \r
+ public function getYearsStepArtist() {\r
+ return $this->_yearsStepArtist;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\VOs\ICountry;\r
+use Domain\VOs\IName;\r
+use Domain\Entities\IUserFactory;\r
+use Domain\Entities\IUserBuilder;\r
+\r
+class UserBuilder implements IUserBuilder\r
+{\r
+ private $_userFactory;\r
+ private $_country;\r
+ private $_displayName;\r
+ private $_name;\r
+ private $_tags;\r
+ private $_yearsStepArtist;\r
+ \r
+ public function __construct(IUserFactory $userFactory)\r
+ {\r
+ $this->_userFactory = $userFactory;\r
+ }\r
+ \r
+ public function With_Country(ICountry $country) {\r
+ $this->_country = $country;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_DisplayName($name) {\r
+ $this->_displayName = $name;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Name(IName $name) {\r
+ $this->_name = $name;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_Tags(array $tags) {\r
+ $this->_tags = $tags;\r
+ return $this;\r
+ }\r
+ \r
+ public function With_YearsStepArtist($years) {\r
+ $this->_yearsStepArtist = $years;\r
+ return $this;\r
+ }\r
+ \r
+ public function build() {\r
+ return $this->_userFactory\r
+ ->createInstance($this->_country,\r
+ $this->_displayName,\r
+ $this->_name,\r
+ $this->_tags,\r
+ $this->_yearsStepArtist);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\VOs\ICountry;\r
+use Domain\VOs\IName;\r
+use Domain\Entities\User;\r
+\r
+interface IUserFactory\r
+{\r
+ public function createInstance(\r
+ ICountry $country,\r
+ $displayName,\r
+ IName $name,\r
+ array $tags,\r
+ $yearsStepArtist\r
+ );\r
+}\r
+\r
+class UserFactory implements IUserFactory\r
+{\r
+ public function createInstance(\r
+ ICountry $country,\r
+ $displayName,\r
+ IName $name,\r
+ array $tags,\r
+ $yearsStepArtist\r
+ ) {\r
+ return new User(\r
+ $country,\r
+ $displayName,\r
+ $name,\r
+ $tags,\r
+ $yearsStepArtist\r
+ );\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Entities;\r
+\r
+use Domain\VOs\ICountry;\r
+use Domain\Vos\IName;\r
+use Domain\Entities\IUser;\r
+\r
+interface IUserStepByStepBuilder\r
+{\r
+ public function With_Country(ICountry $country);\r
+}\r
+\r
+interface IUserStepByStepBuilder_With_Country\r
+{\r
+ public function With_DisplayName($name);\r
+}\r
+\r
+interface IUserStepByStepBuilder_With_DisplayName\r
+{\r
+ public function With_Name(IName $name);\r
+}\r
+\r
+interface IUserStepByStepBuilder_With_Name\r
+{\r
+ public function With_Tags(array $tags);\r
+}\r
+\r
+interface IUserStepByStepBuilder_With_Tags\r
+{\r
+ public function With_YearsStepArtist($years); //not going to make this mandatory as it is kind of a joke\r
+ public function build();\r
+}\r
+ \r
+abstract class AbstractUserStepByStepBuilder\r
+{\r
+ protected $_userBuilder;\r
+ \r
+ public function __construct(IUserBuilder $builder)\r
+ {\r
+ $this->_userBuilder = $builder;\r
+ }\r
+}\r
+\r
+class UserStepByStepBuilder extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder\r
+{\r
+ public function With_Country(ICountry $country) {\r
+ $this->_userBuilder->With_Country($country);\r
+ return new UserStepByStepBuilder_With_Country($this->_userBuilder);\r
+ }\r
+}\r
+\r
+class UserStepByStepBuilder_With_Country extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder_With_Country\r
+{\r
+ public function With_DisplayName($name) {\r
+ $this->_userBuilder->With_DisplayName($name);\r
+ return new UserStepByStepBuilder_With_DisplayName($this->_userBuilder);\r
+ }\r
+}\r
+\r
+class UserStepByStepBuilder_With_DisplayName extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder_With_DisplayName\r
+{\r
+ public function With_Name(IName $name) {\r
+ $this->_userBuilder->With_Name($name);\r
+ return new UserStepByStepBuilder_With_Name($this->_userBuilder);\r
+ }\r
+}\r
+\r
+class UserStepByStepBuilder_With_Name extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder_With_Name\r
+{\r
+ public function With_Tags(array $tags) {\r
+ $this->_userBuilder->With_Tags($tags);\r
+ return new UserStepByStepBuilder_With_Tags($this->_userBuilder);\r
+ }\r
+}\r
+\r
+class UserStepByStepBuilder_With_Tags extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder_With_Tags\r
+{\r
+ public function With_YearsStepArtist($years) {\r
+ $this->_userBuilder->With_YearsStepArtist($years);\r
+ return $this;\r
+ }\r
+ \r
+ public function build() {\r
+ return $this->_userBuilder\r
+ ->build();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\Exception;\r
+\r
+use Exception;\r
+\r
+class InvalidCountryException extends Exception {}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Exception;\r
+\r
+use Exception;\r
+\r
+class InvalidDanceModeException extends Exception{}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Exception;\r
+\r
+use Exception;\r
+\r
+class InvalidDifficultyException extends Exception{}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\Exception;\r
+\r
+use Exception;\r
+\r
+class InvalidStepChartException extends Exception{}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs;\r
+\r
+use Domain\VOs\ICountry;\r
+use Domain\Exception\InvalidCountryException;\r
+\r
+class Country implements ICountry\r
+{\r
+ private $_countryCodes =\r
+ array (\r
+ 'AF' => 'Afghanistan',\r
+ 'AX' => 'Ã…land Islands',\r
+ 'AL' => 'Albania',\r
+ 'DZ' => 'Algeria',\r
+ 'AS' => 'American Samoa',\r
+ 'AD' => 'Andorra',\r
+ 'AO' => 'Angola',\r
+ 'AI' => 'Anguilla',\r
+ 'AQ' => 'Antarctica',\r
+ 'AG' => 'Antigua and Barbuda',\r
+ 'AR' => 'Argentina',\r
+ 'AU' => 'Australia',\r
+ 'AT' => 'Austria',\r
+ 'AZ' => 'Azerbaijan',\r
+ 'BS' => 'Bahamas',\r
+ 'BH' => 'Bahrain',\r
+ 'BD' => 'Bangladesh',\r
+ 'BB' => 'Barbados',\r
+ 'BY' => 'Belarus',\r
+ 'BE' => 'Belgium',\r
+ 'BZ' => 'Belize',\r
+ 'BJ' => 'Benin',\r
+ 'BM' => 'Bermuda',\r
+ 'BT' => 'Bhutan',\r
+ 'BO' => 'Bolivia',\r
+ 'BA' => 'Bosnia and Herzegovina',\r
+ 'BW' => 'Botswana',\r
+ 'BV' => 'Bouvet Island',\r
+ 'BR' => 'Brazil',\r
+ 'IO' => 'British Indian Ocean Territory',\r
+ 'BN' => 'Brunei Darussalam',\r
+ 'BG' => 'Bulgaria',\r
+ 'BF' => 'Burkina Faso',\r
+ 'BI' => 'Burundi',\r
+ 'KH' => 'Cambodia',\r
+ 'CM' => 'Cameroon',\r
+ 'CA' => 'Canada',\r
+ 'CV' => 'Cape Verde',\r
+ 'KY' => 'Cayman Islands',\r
+ 'CF' => 'Central African Republic',\r
+ 'TD' => 'Chad',\r
+ 'CL' => 'Chile',\r
+ 'CN' => 'China',\r
+ 'CX' => 'Christmas Island',\r
+ 'CC' => 'Cocos (Keeling) Islands',\r
+ 'CO' => 'Colombia',\r
+ 'KM' => 'Comoros',\r
+ 'CG' => 'Congo',\r
+ 'CD' => 'Zaire',\r
+ 'CK' => 'Cook Islands',\r
+ 'CR' => 'Costa Rica',\r
+ 'CI' => 'Côte D\'Ivoire',\r
+ 'HR' => 'Croatia',\r
+ 'CU' => 'Cuba',\r
+ 'CY' => 'Cyprus',\r
+ 'CZ' => 'Czech Republic',\r
+ 'DK' => 'Denmark',\r
+ 'DJ' => 'Djibouti',\r
+ 'DM' => 'Dominica',\r
+ 'DO' => 'Dominican Republic',\r
+ 'EC' => 'Ecuador',\r
+ 'EG' => 'Egypt',\r
+ 'SV' => 'El Salvador',\r
+ 'GQ' => 'Equatorial Guinea',\r
+ 'ER' => 'Eritrea',\r
+ 'EE' => 'Estonia',\r
+ 'ET' => 'Ethiopia',\r
+ 'FK' => 'Falkland Islands (Malvinas)',\r
+ 'FO' => 'Faroe Islands',\r
+ 'FJ' => 'Fiji',\r
+ 'FI' => 'Finland',\r
+ 'FR' => 'France',\r
+ 'GF' => 'French Guiana',\r
+ 'PF' => 'French Polynesia',\r
+ 'TF' => 'French Southern Territories',\r
+ 'GA' => 'Gabon',\r
+ 'GM' => 'Gambia',\r
+ 'GE' => 'Georgia',\r
+ 'DE' => 'Germany',\r
+ 'GH' => 'Ghana',\r
+ 'GI' => 'Gibraltar',\r
+ 'GR' => 'Greece',\r
+ 'GL' => 'Greenland',\r
+ 'GD' => 'Grenada',\r
+ 'GP' => 'Guadeloupe',\r
+ 'GU' => 'Guam',\r
+ 'GT' => 'Guatemala',\r
+ 'GG' => 'Guernsey',\r
+ 'GN' => 'Guinea',\r
+ 'GW' => 'Guinea-Bissau',\r
+ 'GY' => 'Guyana',\r
+ 'HT' => 'Haiti',\r
+ 'HM' => 'Heard Island and Mcdonald Islands',\r
+ 'VA' => 'Vatican City State',\r
+ 'HN' => 'Honduras',\r
+ 'HK' => 'Hong Kong',\r
+ 'HU' => 'Hungary',\r
+ 'IS' => 'Iceland',\r
+ 'IN' => 'India',\r
+ 'ID' => 'Indonesia',\r
+ 'IR' => 'Iran, Islamic Republic of',\r
+ 'IQ' => 'Iraq',\r
+ 'IE' => 'Ireland',\r
+ 'IM' => 'Isle of Man',\r
+ 'IL' => 'Israel',\r
+ 'IT' => 'Italy',\r
+ 'JM' => 'Jamaica',\r
+ 'JP' => 'Japan',\r
+ 'JE' => 'Jersey',\r
+ 'JO' => 'Jordan',\r
+ 'KZ' => 'Kazakhstan',\r
+ 'KE' => 'KENYA',\r
+ 'KI' => 'Kiribati',\r
+ 'KP' => 'Korea, Democratic People\'s Republic of',\r
+ 'KR' => 'Korea, Republic of',\r
+ 'KW' => 'Kuwait',\r
+ 'KG' => 'Kyrgyzstan',\r
+ 'LA' => 'Lao People\'s Democratic Republic',\r
+ 'LV' => 'Latvia',\r
+ 'LB' => 'Lebanon',\r
+ 'LS' => 'Lesotho',\r
+ 'LR' => 'Liberia',\r
+ 'LY' => 'Libyan Arab Jamahiriya',\r
+ 'LI' => 'Liechtenstein',\r
+ 'LT' => 'Lithuania',\r
+ 'LU' => 'Luxembourg',\r
+ 'MO' => 'Macao',\r
+ 'MK' => 'Macedonia, the Former Yugoslav Republic of',\r
+ 'MG' => 'Madagascar',\r
+ 'MW' => 'Malawi',\r
+ 'MY' => 'Malaysia',\r
+ 'MV' => 'Maldives',\r
+ 'ML' => 'Mali',\r
+ 'MT' => 'Malta',\r
+ 'MH' => 'Marshall Islands',\r
+ 'MQ' => 'Martinique',\r
+ 'MR' => 'Mauritania',\r
+ 'MU' => 'Mauritius',\r
+ 'YT' => 'Mayotte',\r
+ 'MX' => 'Mexico',\r
+ 'FM' => 'Micronesia, Federated States of',\r
+ 'MD' => 'Moldova, Republic of',\r
+ 'MC' => 'Monaco',\r
+ 'MN' => 'Mongolia',\r
+ 'ME' => 'Montenegro',\r
+ 'MS' => 'Montserrat',\r
+ 'MA' => 'Morocco',\r
+ 'MZ' => 'Mozambique',\r
+ 'MM' => 'Myanmar',\r
+ 'NA' => 'Namibia',\r
+ 'NR' => 'Nauru',\r
+ 'NP' => 'Nepal',\r
+ 'NL' => 'Netherlands',\r
+ 'AN' => 'Netherlands Antilles',\r
+ 'NC' => 'New Caledonia',\r
+ 'NZ' => 'New Zealand',\r
+ 'NI' => 'Nicaragua',\r
+ 'NE' => 'Niger',\r
+ 'NG' => 'Nigeria',\r
+ 'NU' => 'Niue',\r
+ 'NF' => 'Norfolk Island',\r
+ 'MP' => 'Northern Mariana Islands',\r
+ 'NO' => 'Norway',\r
+ 'OM' => 'Oman',\r
+ 'PK' => 'Pakistan',\r
+ 'PW' => 'Palau',\r
+ 'PS' => 'Palestinian Territory, Occupied',\r
+ 'PA' => 'Panama',\r
+ 'PG' => 'Papua New Guinea',\r
+ 'PY' => 'Paraguay',\r
+ 'PE' => 'Peru',\r
+ 'PH' => 'Philippines',\r
+ 'PN' => 'Pitcairn',\r
+ 'PL' => 'Poland',\r
+ 'PT' => 'Portugal',\r
+ 'PR' => 'Puerto Rico',\r
+ 'QA' => 'Qatar',\r
+ 'RE' => 'Réunion',\r
+ 'RO' => 'Romania',\r
+ 'RU' => 'Russian Federation',\r
+ 'RW' => 'Rwanda',\r
+ 'SH' => 'Saint Helena',\r
+ 'KN' => 'Saint Kitts and Nevis',\r
+ 'LC' => 'Saint Lucia',\r
+ 'PM' => 'Saint Pierre and Miquelon',\r
+ 'VC' => 'Saint Vincent and the Grenadines',\r
+ 'WS' => 'Samoa',\r
+ 'SM' => 'San Marino',\r
+ 'ST' => 'Sao Tome and Principe',\r
+ 'SA' => 'Saudi Arabia',\r
+ 'SN' => 'Senegal',\r
+ 'RS' => 'Serbia',\r
+ 'SC' => 'Seychelles',\r
+ 'SL' => 'Sierra Leone',\r
+ 'SG' => 'Singapore',\r
+ 'SK' => 'Slovakia',\r
+ 'SI' => 'Slovenia',\r
+ 'SB' => 'Solomon Islands',\r
+ 'SO' => 'Somalia',\r
+ 'ZA' => 'South Africa',\r
+ 'GS' => 'South Georgia and the South Sandwich Islands',\r
+ 'ES' => 'Spain',\r
+ 'LK' => 'Sri Lanka',\r
+ 'SD' => 'Sudan',\r
+ 'SR' => 'Suriname',\r
+ 'SJ' => 'Svalbard and Jan Mayen',\r
+ 'SZ' => 'Swaziland',\r
+ 'SE' => 'Sweden',\r
+ 'CH' => 'Switzerland',\r
+ 'SY' => 'Syrian Arab Republic',\r
+ 'TW' => 'Taiwan, Province of China',\r
+ 'TJ' => 'Tajikistan',\r
+ 'TZ' => 'Tanzania, United Republic of',\r
+ 'TH' => 'Thailand',\r
+ 'TL' => 'Timor-Leste',\r
+ 'TG' => 'Togo',\r
+ 'TK' => 'Tokelau',\r
+ 'TO' => 'Tonga',\r
+ 'TT' => 'Trinidad and Tobago',\r
+ 'TN' => 'Tunisia',\r
+ 'TR' => 'Turkey',\r
+ 'TM' => 'Turkmenistan',\r
+ 'TC' => 'Turks and Caicos Islands',\r
+ 'TV' => 'Tuvalu',\r
+ 'UG' => 'Uganda',\r
+ 'UA' => 'Ukraine',\r
+ 'AE' => 'United Arab Emirates',\r
+ 'GB' => 'United Kingdom',\r
+ 'US' => 'United States',\r
+ 'UM' => 'United States Minor Outlying Islands',\r
+ 'UY' => 'Uruguay',\r
+ 'UZ' => 'Uzbekistan',\r
+ 'VU' => 'Vanuatu',\r
+ 'VE' => 'Venezuela',\r
+ 'VN' => 'Viet Nam',\r
+ 'VG' => 'Virgin Islands, British',\r
+ 'VI' => 'Virgin Islands, U.S.',\r
+ 'WF' => 'Wallis and Futuna',\r
+ 'EH' => 'Western Sahara',\r
+ 'YE' => 'Yemen',\r
+ 'ZM' => 'Zambia',\r
+ 'ZW' => 'Zimbabwe',\r
+ );\r
+\r
+ private $_country;\r
+ \r
+ public function __construct($country) {\r
+ if(!in_array($country, $this->_countryCodes)) {\r
+ throw new InvalidCountryException('Invalid country');\r
+ }\r
+ \r
+ $this->_country = $country;\r
+ }\r
+ \r
+ public function getCountryName() {\r
+ return $this->_country;\r
+ }\r
+ \r
+ public function getCountryCode() {\r
+ return array_search($this->_country, $this->_countryCodes);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs;\r
+\r
+interface ICountry\r
+{\r
+ public function getCountryCode();\r
+ public function getCountryName();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs;\r
+\r
+interface IName\r
+{\r
+ public function getFirstName();\r
+ public function getLastName();\r
+ public function getFullName();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs;\r
+\r
+use Domain\VOs\IName;\r
+\r
+class Name implements IName\r
+{\r
+ private $_firstName;\r
+ private $_lastName;\r
+ \r
+ public function __construct($firstName, $lastName = null)\r
+ {\r
+ $this->_firstName = $firstName;\r
+ $this->_lastName = $lastName;\r
+ }\r
+ \r
+ public function getFirstName() {\r
+ return $this->_firstName;\r
+ }\r
+ \r
+ public function getLastName() {\r
+ return $this->_lastName;\r
+ }\r
+ \r
+ public function getFullName() {\r
+ return sprintf('%s %s', $this->_firstName, $this->_lastName);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+class Artist implements IArtist\r
+{\r
+ private $_name;\r
+ \r
+ public function __construct($name)\r
+ {\r
+ $this->_name = $name; \r
+ }\r
+ \r
+ public function getName() {\r
+ return $this->_name;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+class BPM implements IBPM\r
+{\r
+ protected $high;\r
+ protected $low;\r
+ \r
+ public function __construct($high, $low)\r
+ {\r
+ $this->high = $high;\r
+ $this->low = $low;\r
+ }\r
+ \r
+ public function getHigh()\r
+ {\r
+ return $this->high;\r
+ }\r
+ \r
+ public function getLow()\r
+ {\r
+ return $this->low;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+use Domain\Exception\InvalidDanceModeException;\r
+\r
+class DanceMode implements IDanceMode\r
+{\r
+ protected $stepManiaName;\r
+ protected $prettyName;\r
+ \r
+ private $_nameMap = array(\r
+ 'dance-single' => 'Single',\r
+ 'dance-double' => 'Double'\r
+ );\r
+ \r
+ public function __construct($stepManiaName)\r
+ {\r
+ if(array_key_exists($stepManiaName, $this->_nameMap)) {\r
+ $this->stepManiaName = $stepManiaName;\r
+ $this->prettyName = $this->_nameMap[$stepManiaName];\r
+ } else {\r
+ throw new InvalidDanceModeException(sprintf('Invalid dance mode %s', $stepManiaName));\r
+ } \r
+ }\r
+ \r
+ public function getStepManiaName() {\r
+ return $this->stepManiaName;\r
+ }\r
+ \r
+ public function getPrettyName() {\r
+ return $this->prettyName;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+use Domain\Exception\InvalidDifficultyException;\r
+\r
+class Difficulty implements IDifficulty\r
+{\r
+ protected $stepManiaName;\r
+ protected $itgName;\r
+ \r
+ private $_nameMap = array(\r
+ 'light' => 'Novice',\r
+ 'beginner' => 'Novice',\r
+ 'easy' => 'Easy',\r
+ 'medium' => 'Medium',\r
+ 'hard' => 'Hard',\r
+ 'challenge' => 'Expert',\r
+ 'edit' => 'Edit'\r
+ );\r
+ \r
+ public function __construct($stepManiaName) {\r
+ if(array_key_exists($stepManiaName, $this->_nameMap)) {\r
+ $this->stepManiaName = $stepManiaName;\r
+ $this->itgName = $this->_nameMap[$stepManiaName];\r
+ } else {\r
+ throw new InvalidDifficultyException(sprintf('Invalid difficulty: %s', $stepManiaName));\r
+ } \r
+ }\r
+ \r
+ public function getITGName() {\r
+ return $this->itgName;\r
+ }\r
+ \r
+ public function getStepManiaName() {\r
+ return $this->stepManiaName;\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IArtist\r
+{\r
+ public function getName();\r
+}\r
+\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IBPM\r
+{\r
+ public function getHigh();\r
+ public function getLow();\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IDanceMode\r
+{\r
+ public function getStepManiaName();\r
+ public function getPrettyName();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IDifficulty\r
+{\r
+ public function getStepManiaName();\r
+ public function getITGName();\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IStepArtist\r
+{\r
+ public function getTag();\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface IStepChart\r
+{\r
+ public function getMode();\r
+ public function getRating();\r
+ public function getDifficulty();\r
+ public function getArtist(); \r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+interface ITag\r
+{\r
+ public function getTag();\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+class StepArtist implements IStepArtist\r
+{\r
+ protected $tag;\r
+ \r
+ public function __construct($tag)\r
+ {\r
+ $this->tag = $tag;\r
+ }\r
+ \r
+ public function getTag()\r
+ {\r
+ return $this->tag;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+use Domain\VOs\StepMania\DanceMode;\r
+use Domain\VOs\StepMania\Difficulty;\r
+use Domain\VOs\StepMania\StepArtist;\r
+\r
+class StepChart implements IStepChart\r
+{ \r
+ protected $mode;\r
+ \r
+ protected $rating;\r
+ \r
+ protected $difficulty;\r
+ \r
+ protected $artist;\r
+ \r
+ function __construct(\r
+ DanceMode $mode,\r
+ Difficulty $difficulty,\r
+ StepArtist $artist,\r
+ $rating\r
+ ) {\r
+ $this->mode = $mode;\r
+ $this->difficulty = $difficulty;\r
+ $this->artist = $artist;\r
+ $this->rating = $rating;\r
+ }\r
+ \r
+ public function getMode()\r
+ {\r
+ return $this->mode;\r
+ }\r
+ \r
+ public function getRating()\r
+ {\r
+ return $this->rating;\r
+ }\r
+ \r
+ public function getDifficulty()\r
+ {\r
+ return $this->difficulty;\r
+ }\r
+ \r
+ public function getArtist()\r
+ {\r
+ return $this->artist;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+namespace Domain\VOs\StepMania;\r
+\r
+use Domain\VOs\StepMania\ITag;\r
+\r
+class Tag implements ITag\r
+{\r
+ private $_tag;\r
+ \r
+ public function __construct($tag) {\r
+ $this->_tag = $tag;\r
+ }\r
+ \r
+ public function getTag()\r
+ {\r
+ return $this->_tag;\r
+ }\r
+}\r
+\r
-rock n roll
+Project depends on PHP-DI for dependency injection. Run `composer install` to sort that out.
\ No newline at end of file
--- /dev/null
+<?php\r
+/**\r
+ * @package DIExample\r
+ * @copyright 2013 Internet Brands, Inc. All Rights Reserved.\r
+ */\r
+namespace Domain\Entities;\r
+\r
+/**\r
+ * Bar\r
+ *\r
+ * @author Michael Funk <mfunk@internetbrands.com>\r
+ */\r
+class Bar implements BarInterface\r
+{\r
+\r
+ /**\r
+ * just returns a hardcoded string\r
+ *\r
+ * @return string\r
+ */\r
+ public function returnMe()\r
+ {\r
+ return 'This is from the bar class';\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+/**\r
+ * @package DIExample\r
+ * @copyright 2013 Internet Brands, Inc. All Rights Reserved.\r
+ */\r
+namespace Domain\Entities;\r
+\r
+/**\r
+ * BarInterface\r
+ *\r
+ * @author Michael Funk <mfunk@internetbrands.com>\r
+ */\r
+interface BarInterface\r
+{\r
+\r
+ /**\r
+ * returnMe\r
+ *\r
+ * @return string\r
+ */\r
+ public function returnMe();\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+/**\r
+ * @package DIExample\r
+ * @copyright 2013 Internet Brands, Inc. All Rights Reserved.\r
+ */\r
+namespace Domain\Entities;\r
+\r
+/**\r
+ * Foo\r
+ *\r
+ * @author Michael Funk <mfunk@internetbrands.com>\r
+ */\r
+class Foo\r
+{\r
+\r
+ /**\r
+ * This just holds the injected instance of Bar\r
+ * @var MikeFunk\Test\Bar\r
+ */\r
+ protected $bar;\r
+\r
+ /**\r
+ * inject Bar into $bar and then $this->bar with type hinting. The Bar\r
+ * class is bound to the BarInterface in config/di.yml\r
+ *\r
+ * @return void\r
+ */\r
+ public function __construct(BarInterface $bar)\r
+ {\r
+ $this->bar = $bar;\r
+ }\r
+\r
+ /**\r
+ * Just return the string from Bar::returnMe()\r
+ *\r
+ * @return string\r
+ */\r
+ public function returnMe()\r
+ {\r
+ return $this->bar->returnMe();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+{\r
+ "require": {\r
+ "mnapoli/php-di": "~4.0"\r
+ }, \r
+ "autoload": {\r
+ "psr-0": {\r
+ "Domain" : "./",\r
+ "DataAccess" : "./"\r
+ },\r
+ "files" : ["./DataAccess/functions.php"]\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+return [\r
+ 'Domain\Entities\BarInterface' => DI\object('Domain\Entities\Bar'),\r
+];\r
--- /dev/null
+<?php\r
+\r
+//rely on the convention that any reference column is named [parent_table]_id\r
+//or the other way around, the column is labled [child_table]_id\r
+\r
+// so either we will be looking for the id of the parent table, or we will\r
+// be given the id for the child table\r
+\r
+return [\r
+ 'Simfile' => [\r
+ 'class' => 'Domain\Entities\StepMania\Simfile',\r
+ 'table' => 'simfiles',\r
+ 'maps' => [\r
+ //entity => table\r
+ 'title' => DataAccess\Varchar('title'),\r
+ 'artist' => DataAccess\VO('Artist'),\r
+ 'uploader' => DataAccess\Entity('User', 'getUploader'),\r
+ 'bpm' => DataAccess\VO('BPM'),\r
+ 'bpmChanges' => DataAccess\Int('bpm_changes', 'hasBPMChanges'),\r
+ 'stops' => DataAccess\Int('stops', 'hasStops'),\r
+ 'fgChanges' => DataAccess\Int('fg_changes', 'hasFgChanges'),\r
+ 'bgChanges' => DataAccess\Int('bg_changes', 'hasBgChanges'),\r
+ 'steps' => DataAccess\VOArray('StepChart', 'getSteps')\r
+ ]\r
+ ],\r
+ \r
+ 'BPM' => [\r
+ 'class' => 'Domain\VOs\StepMania\BPM',\r
+ 'table' => 'simfiles',\r
+ 'maps' => [\r
+ 'high' => DataAccess\Int('bpm_high', 'getHigh'),\r
+ 'low' => DataAccess\Int('bpm_low', 'getLow')\r
+ ]\r
+ ],\r
+ \r
+ 'User' => [\r
+ 'class' => 'Domain\Entities\User',\r
+ 'table' => 'users',\r
+ 'maps' => [\r
+ 'country' => DataAccess\VO('Country'),\r
+ 'displayName' => DataAccess\Varchar('display_name'),\r
+ 'name' => DataAccess\VO('Name'),\r
+ 'tags' => DataAccess\VOArray('Tag', 'getTags') // TODO: Make VarcharArray class\r
+ ]\r
+ ],\r
+ \r
+ 'Name' => [\r
+ 'class' => 'Domain\VOs\Name',\r
+ 'table' => 'users_meta',\r
+ 'maps' => [\r
+ 'firstname' => DataAccess\Varchar('firstname'),\r
+ 'lastname' => DataAccess\Varchar('lastname')\r
+ ]\r
+ ],\r
+ \r
+ 'Country' => [\r
+ 'class' => 'Domain\VOs\Country',\r
+ 'table' => 'users_meta',\r
+ 'maps' => [\r
+ 'country' => DataAccess\Varchar('country', 'getCountryName')\r
+ ] \r
+ ],\r
+ \r
+ 'Tag' => [\r
+ 'class' => 'Domain\VOs\StepMania\Tag',\r
+ 'table' => 'step_artists',\r
+ 'maps' => [\r
+ 'tag' => DataAccess\Varchar('tag')\r
+ ]\r
+ ],\r
+ \r
+ 'Artist' => [\r
+ 'class' => 'Domain\VOs\StepMania\Artist',\r
+ 'table' => 'artists',\r
+ 'maps' => [\r
+ 'name' => DataAccess\Varchar('name')\r
+ ]\r
+ ],\r
+ \r
+ 'StepChart' => [\r
+ 'class' => 'Domain\VOs\StepMania\StepChart',\r
+ 'table' => 'steps',\r
+ 'maps' => [\r
+ 'mode' => DataAccess\VO('DanceMode', 'getMode'),\r
+ 'difficulty' => DataAccess\VO('Difficulty'),\r
+ 'artist' => DataAccess\VO('StepArtist', 'getArtist', 'step_artist'),\r
+ 'rating' => DataAccess\Int('rating')\r
+ ]\r
+ ],\r
+ \r
+ 'DanceMode' => [\r
+ 'class' => 'Domain\VOs\StepMania\DanceMode',\r
+ 'table' => 'steps',\r
+ 'maps' => [\r
+ 'stepManiaName' => DataAccess\Varchar('mode', 'getStepManiaName')\r
+ ]\r
+ ],\r
+ \r
+ 'StepArtist' => [\r
+ 'class' => 'Domain\VOs\StepMania\StepArtist',\r
+ 'table' => 'step_artists',\r
+ 'maps' => [\r
+ 'tag' => DataAccess\Varchar('tag')\r
+ ]\r
+ ],\r
+ \r
+ 'Difficulty' => [\r
+ 'class' => 'Domain\VOs\StepMania\Difficulty',\r
+ 'table' => 'steps',\r
+ 'maps' => [\r
+ 'stepManiaName' => DataAccess\Varchar('difficulty', 'getStepManiaName')\r
+ ]\r
+ ]\r
+];\r
--- /dev/null
+-- MySQL dump 10.13 Distrib 5.6.12, for Win64 (x86_64)\r
+--\r
+-- Host: localhost Database: divinelegy\r
+-- ------------------------------------------------------\r
+-- Server version 5.6.12\r
+\r
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r
+/*!40101 SET NAMES utf8 */;\r
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\r
+/*!40103 SET TIME_ZONE='+00:00' */;\r
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\r
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\r
+\r
+--\r
+-- Table structure for table `artists`\r
+--\r
+\r
+DROP TABLE IF EXISTS `artists`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `artists` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `name` varchar(255) NOT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `artists`\r
+--\r
+\r
+LOCK TABLES `artists` WRITE;\r
+/*!40000 ALTER TABLE `artists` DISABLE KEYS */;\r
+INSERT INTO `artists` VALUES (1,'atpunk01'),(2,'FaggotForce');\r
+/*!40000 ALTER TABLE `artists` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+\r
+--\r
+-- Table structure for table `simfiles`\r
+--\r
+\r
+DROP TABLE IF EXISTS `simfiles`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `simfiles` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `title` varchar(255) NOT NULL,\r
+ `artist_id` mediumint(8) unsigned NOT NULL,\r
+ `user_id` mediumint(8) unsigned NOT NULL,\r
+ `bpm_high` int(11) NOT NULL,\r
+ `bpm_low` int(11) NOT NULL,\r
+ `bpm_changes` bit(1) NOT NULL,\r
+ `stops` bit(1) NOT NULL,\r
+ `fg_changes` bit(1) NOT NULL,\r
+ `bg_changes` bit(1) NOT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `simfiles`\r
+--\r
+\r
+LOCK TABLES `simfiles` WRITE;\r
+/*!40000 ALTER TABLE `simfiles` DISABLE KEYS */;\r
+INSERT INTO `simfiles` VALUES (1,'BaBoom',1,1,177,177,'\ 1','\0','\0','\0'),(2,'Some Faggot Chart',2,2,230,230,'\0','\0','\0','\0'),(3,'More Bullshit',2,2,210,210,'\0','\0','\0','\0');\r
+/*!40000 ALTER TABLE `simfiles` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+\r
+--\r
+-- Table structure for table `step_artists`\r
+--\r
+\r
+DROP TABLE IF EXISTS `step_artists`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `step_artists` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `tag` varchar(255) NOT NULL,\r
+ `user_id` mediumint(8) unsigned DEFAULT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `step_artists`\r
+--\r
+\r
+LOCK TABLES `step_artists` WRITE;\r
+/*!40000 ALTER TABLE `step_artists` DISABLE KEYS */;\r
+INSERT INTO `step_artists` VALUES (1,'(-[Jayce]-)',1),(2,'Zaia',2),(3,'Serenade',2);\r
+/*!40000 ALTER TABLE `step_artists` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+\r
+--\r
+-- Table structure for table `steps`\r
+--\r
+\r
+DROP TABLE IF EXISTS `steps`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `steps` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `simfile_id` mediumint(8) unsigned NOT NULL,\r
+ `mode` enum('dance-single','dance-double') NOT NULL,\r
+ `rating` int(10) unsigned NOT NULL,\r
+ `difficulty` enum('beginner','easy','medium','hard','challenge','edit') NOT NULL,\r
+ `step_artist_id` mediumint(8) unsigned NOT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `steps`\r
+--\r
+\r
+LOCK TABLES `steps` WRITE;\r
+/*!40000 ALTER TABLE `steps` DISABLE KEYS */;\r
+INSERT INTO `steps` VALUES (1,1,'dance-single',10,'challenge',1),(2,1,'dance-single',9,'hard',1),(3,1,'dance-single',7,'medium',1),(4,1,'dance-single',4,'easy',1),(5,1,'dance-single',2,'beginner',1),(6,2,'dance-single',15,'beginner',2),(7,3,'dance-single',16,'beginner',3);\r
+/*!40000 ALTER TABLE `steps` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+\r
+--\r
+-- Table structure for table `users`\r
+--\r
+\r
+DROP TABLE IF EXISTS `users`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `users` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `email` varchar(255) NOT NULL,\r
+ `display_name` varchar(255) NOT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `users`\r
+--\r
+\r
+LOCK TABLES `users` WRITE;\r
+/*!40000 ALTER TABLE `users` DISABLE KEYS */;\r
+INSERT INTO `users` VALUES (1,'jayce@divinelegy.com','Jayce'),(2,'chino@chino.net','Chino');\r
+/*!40000 ALTER TABLE `users` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+\r
+--\r
+-- Table structure for table `users_meta`\r
+--\r
+\r
+DROP TABLE IF EXISTS `users_meta`;\r
+/*!40101 SET @saved_cs_client = @@character_set_client */;\r
+/*!40101 SET character_set_client = utf8 */;\r
+CREATE TABLE `users_meta` (\r
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,\r
+ `user_id` mediumint(8) unsigned NOT NULL,\r
+ `firstname` varchar(255) DEFAULT NULL,\r
+ `lastname` varchar(255) DEFAULT NULL,\r
+ `country` varchar(255) NOT NULL,\r
+ PRIMARY KEY (`id`)\r
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;\r
+/*!40101 SET character_set_client = @saved_cs_client */;\r
+\r
+--\r
+-- Dumping data for table `users_meta`\r
+--\r
+\r
+LOCK TABLES `users_meta` WRITE;\r
+/*!40000 ALTER TABLE `users_meta` DISABLE KEYS */;\r
+INSERT INTO `users_meta` VALUES (1,1,'Jayce','Newton','Australia'),(2,2,'Chino','Wood','Australia');\r
+/*!40000 ALTER TABLE `users_meta` ENABLE KEYS */;\r
+UNLOCK TABLES;\r
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\r
+\r
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\r
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r
+\r
+-- Dump completed on 2014-08-31 19:53:16\r
--- /dev/null
+<?php\r
+require_once('../vendor/autoload.php');\r
+\r
+use Domain\Entities\StepMania\SimfileFactory;\r
+use Domain\Entities\StepMania\SimfileBuilder;\r
+use Domain\Entities\StepMania\SimfileStepByStepBuilder;\r
+use Domain\VOs\StepMania\BPM;\r
+use Domain\VOs\StepMania\StepChart;\r
+use Domain\VOs\StepMania\DanceMode;\r
+use Domain\VOs\StepMania\Difficulty;\r
+use Domain\VOs\StepMania\StepArtist;\r
+use Domain\VOs\StepMania\Artist;\r
+use Domain\ConstantsAndTypes\SimfileConstants;\r
+\r
+$containerBuilder = new DI\ContainerBuilder();\r
+$containerBuilder->addDefinitions('../config/DI.php');\r
+\r
+$container = $containerBuilder->build();\r
+\r
+/* @var $foo Domain\Entities\Foo */\r
+//$foo = $container->get('Domain\Entities\Foo');\r
+//$foo->returnMe();\r
+\r
+$DataMapper = new \DataAccess\DataMapper\DataMapper('../config/DataMaps.php');\r
+$user = $DataMapper->find(1,'User');\r
+\r
+$simfileFactory = new SimfileFactory();\r
+$simfileBuilder = new SimfileBuilder($simfileFactory);\r
+$simfileStepByStepBuilder = new SimfileStepByStepBuilder($simfileBuilder);\r
+\r
+$danceMode = new DanceMode('dance-single');\r
+$difficulty = new Difficulty('challenge');\r
+$stepArtist = new StepArtist('Someone new fuck');\r
+$artist = new Artist('A brand new awesome artist!');\r
+$rating = '10';\r
+\r
+$bpm = new BPM('256', '128');\r
+$stepChart = new StepChart($danceMode,\r
+ $difficulty,\r
+ $stepArtist,\r
+ $rating);\r
+\r
+$steps = array($stepChart);\r
+\r
+\r
+$simfile = $simfileStepByStepBuilder->With_Title('Brand New Simfile')\r
+ ->With_Artist($artist)\r
+ ->With_Uploader($user)\r
+ ->With_BPM($bpm)\r
+ ->With_BpmChanges(SimfileConstants::NO_BPM_CHANGES)\r
+ ->With_Stops(SimfileConstants::NO_STOPS)\r
+ ->With_FgChanges(SimfileConstants::NO_FG_CHANGES)\r
+ ->With_BgChanges(SimfileConstants::NO_BG_CHANGES)\r
+ ->With_Steps($steps)\r
+ ->build();\r
+\r
+\r
+//$user->setId(NULL);\r
+\r
+$DataMapper->save($simfile);\r
+\r
+\r
+\r
+\r
+//$stepchart = $simfile->getSteps();\r
+//$stepchart = $stepchart[0];\r
+//$maps = include '../config/DataMaps.php';\r
+//\r
+//$DataMapper->save($user);\r
+\r