gerbenjacobs / HabboAPI

A PHP wrapper for the (undocumented) Habbo API
MIT License
44 stars 10 forks source link

Data Mapper #17

Closed DavydeVries closed 8 years ago

DavydeVries commented 8 years ago

Maybe an idea to create a data mapper in V2. So you can get arrays of everything. Like:

private function dataMapper(Habbo $obj)
{
    $data[ 'id' ]                = $obj->getId();
    $data[ 'habboName' ]         = $obj->getHabboName();
    $data[ 'motto' ]             = $obj->getMotto();
    $data[ 'memberSince' ]       = $obj->getMemberSince();
    $data[ 'figureString' ]      = $obj->getFigureString();
    $data[ 'profileVisible' ]    = $obj->getProfileVisible();
    return $data;
}

Btw this make it a lot easier to store data in a database.

So that you can access via an object function and array. To come back on the remove of arrays in #2. Is this a better solution on #12.

example for my suggestion:

$habboObj = $API->getHabbo($id, 'object');
$habboData = $API->getHabbo($id, 'array');

$habboObj->getName();
$habboData['habboName'];

So you give default an object, else the format that is given. Like array

gerbenjacobs commented 8 years ago

But that's really dependent on how people set up their database? And if you were to say "but it's really nice to get everything back" then there's already the object itself or you could typecast it to an array.

$array = (array) $habboEntity;

And those options are more flexible than the HabboAPI dictating what the index fields should be. I think DataMappers for marshalling data to and from DB, entities and for example JSON are good, but they should not be inside this library, but in the project that uses it.