SitePoint Sponsor

User Tag List

Page 7 of 7 FirstFirst ... 34567
Results 151 to 171 of 171
  1. #151
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Yes, but NULL isn't the type expected no? Say... I must be thick this morning
    function __construct(B $b = null)

    $b has to be of type B or null. the = null allows nulls to be passed in. Whereas function __construct(B $b) requires a object of type B.

  2. #152
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Yes, but NULL isn't the type expected no? Say... I must be thick this morning
    No thicker than usual. It was added recently to PHP (5.1.2 IIRC) to allow for option typed parameters. The only allowed value for a default typed parameter is NULL.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #153
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could we stop the Off Topic now ?
    Off Topic:

    Ok some more ot, I've always wondered what the "IIRC" abbrv stands for ;p, anyone?

  4. #154
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ren, how about this then:
    PHP Code:
        protected function PersonMap(){
            
    $map = new ClassMap;
            
    $map->name        Model::string(25);
            
    $map->email        Model::string(50true); // allows null
            
    $map->age        Model::integer(3);
            
    $map->text        Model::text("long");
            
    $map->groups    Model::collection("Group");
            
    $map->children    Model::collection("Person");
            
    $map->parent    Model::object("Person");
            
            
    $map->naturalKey("name","email"); // sql: unique(name, email)
            
    return $map;
        } 

  5. #155
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, they could be statics I suppose.

    And...

    IIRC = If I Remember Correctly


  6. #156
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > No thicker than usual.

    No need to get personal about it okay? That wasn't called for actually

    > It was added recently to PHP (5.1.2 IIRC) to allow for option typed parameters.

    Well I'm using 5.1.1 at the moment, but I can't say that I knew of the change anyways.

  7. #157
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, according to this, http://derickrethans.nl/typehints_and_null.php , its in 5.1.0.

  8. #158
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Quote Originally Posted by Dr Livingston
    > No thicker than usual.

    No need to get personal about it okay? That wasn't called for actually
    It was not meant to be personal, only that the change was recent and you might not have been aware of it, and therefore not you did not have to be particularly "thick" as you stated.

    My apologies for leaving it ambiguous.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  9. #159
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, more ideas comming up - after the insane amount of ORM threads here on sitepoint, this is my current idea(it would only allow one DB connection at a time to be active, I could do some type of selfcontained static registry for the model to allow more - but for now this will suffice), there would be some static abuse(Model + UoW + IDMap = static) to get a better "feel" to it and being able to create mappers / domain objects as you wish.

    The use would look something like this:

    PHP Code:
    Model::paths('./Classes/''./Internal/');
    Model::connect('mysql''localhost''development''dev''devnull');

    $mapper                = new PersonMapper;
    $persons            $mapper->find(1);

    $person            = new Person;
    $person->surname    "John";
    $person->familyname    "Doe";

    Model::commit(); 
    And the mapping in the PersonMapper (in this case) something like:
    PHP Code:
    class PersonMapper extends ModelMapper{
        
        public function 
    __construct(){
            
    $this->setTable("Persons");
            
    $this->hasMany("Post.author");
            
    $this->hasOne("Presentation.owner");
            
    $this->belongsTo("Person.id""parent");
            
    $this->hasInternal('Money', array('savings''currency'));
            
    parent::__construct();
        }
        

    If you don't want any special functionallity there's no need to create the "Person" class as it will be created automaticly at runtime for you - if you wan't other stuff in there go ahead and create your own, etc.

  10. #160
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've decided not to go with the static approach as it's way to limiting in terms of database connectivity, etc. Going to post some new design ideas later on.

  11. #161
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    I've decided not to go with the static approach as it's way to limiting in terms of database connectivity, etc.
    Good

  12. #162
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, now we're talking something like this(Yes I think I'm going to adopt the Zend_Framework _-style as I feel it's a decent workaround do the current php namespace/package problems):


    PHP Code:
    <?php
    class PersonMapper extends Model_Mapper{

         protected function 
    mapping(){
             
    #Model_Mapper::bind($sqlfield, $objectfield = null, $type = null, $key = false)
              
    $this->bind("person_id""id""integer"true);
              
    $this->bind("name");
              
    $this->bind("savings"null"float");
              
    $this->bind("currency");
              
    $this->bind("parent"null"integer");
             
    #Model_Mapper::hasMany/HasOne($locator, $name = null);
             #if $name is not specified it'll take the left most part of the locator
              
    $this->hasMany("Post.author");
              
    $this->hasOne("Presentation.owner");
             
    #Model_Mapper::belongsTo($locator, $name)
             #$name is required for belongsTo as it must be a bound field
              
    $this->belongsTo("Parent.id""parent");
             
    #Model_Mapper::internal($type, $fields, $name = null);
             #if $name is not specified it'll use the first element in $fields
             
    $this->internal("Money", array("savings","currency"));
             
    $this->class("Person");
             
    $this->table("Persons");
         }

    }
    ?>
    It's either this(If I can get it to work and many people feel it's a nice approach) or I'm going with a table data gateway ;p. This is by far the most "clean" approach I've come up with as I wan't to have fieldbinding so you can select what fields to use and what name they should have on the object.

    Edit:

    Model_Mapper::internal() should maybe be named embedded() instead, can't realy decide on a nameing for it

  13. #163
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    Worcester
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks reasonable to me as the amount of code required for a simple table is pretty small, yet you can get as complex as you need.

  14. #164
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wast thinking about adding a Model_Mapper::use(str field [, str field [, ...] ]) method that would allow you to do this: $this->use("name","currency","age"); which would basicly be a shortcut to calling $this->bind("name"); $this->bind("currency"); and $this->bind("age"); if you just want to use them under thier table name without any typecasting.

  15. #165
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    Worcester
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's not a bad idea either.

  16. #166
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    Ok, now we're talking something like this(Yes I think I'm going to adopt the Zend_Framework _-style as I feel it's a decent workaround do the current php namespace/package problems):


    PHP Code:
    <?php
    class PersonMapper extends Model_Mapper{

         protected function 
    mapping(){
             
    #Model_Mapper::bind($sqlfield, $objectfield = null, $type = null, $key = false)
              
    $this->bind("person_id""id""integer"true);
              
    $this->bind("name");
              
    $this->bind("savings"null"float");
              
    $this->bind("currency");
              
    $this->bind("parent"null"integer");
             
    #Model_Mapper::hasMany/HasOne($locator, $name = null);
             #if $name is not specified it'll take the left most part of the locator
              
    $this->hasMany("Post.author");
              
    $this->hasOne("Presentation.owner");
             
    #Model_Mapper::belongsTo($locator, $name)
             #$name is required for belongsTo as it must be a bound field
              
    $this->belongsTo("Parent.id""parent");
             
    #Model_Mapper::internal($type, $fields, $name = null);
             #if $name is not specified it'll use the first element in $fields
             
    $this->internal("Money", array("savings","currency"));
             
    $this->class("Person");
             
    $this->table("Persons");
         }

    }
    ?>
    It's either this(If I can get it to work and many people feel it's a nice approach) or I'm going with a table data gateway ;p. This is by far the most "clean" approach I've come up with as I wan't to have fieldbinding so you can select what fields to use and what name they should have on the object.

    Edit:

    Model_Mapper::internal() should maybe be named embedded() instead, can't realy decide on a nameing for it
    Looks fine, looks like you've chosen to single column PKs, in the in both the bind() and has*()?

  17. #167
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also just had a thought (whilst experimenting with defining relations with MadCap) do you really need both hasOne() and hasMany() ?

    Should be able to deduce that by the checking the wether the joining field is a PK or FK.

    PS
    Code:
    $this->hasOne($catalog->Titles, $catalog->Titles->id == $this->titleId);
    Quite neat I think..

  18. #168
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you could have...

    PHP Code:
    public function getQuantity() { ... }
    // instead? 

  19. #169
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren
    Looks fine, looks like you've chosen to single column PKs, in the in both the bind() and has*()?
    You can bind multiple keys, such as(for a membership class):

    $this->bind("person",null, "integer", true);
    $this->bind("group",null, "integer", true);

    And about the has*(), it seems rather awkward to handle relations with multiple keys?

    Quote Originally Posted by Dr Livingston
    Maybe you could have...

    PHP Code:
    public function getQuantity() { ... }
    // instead? 
    Hmm.. I'm not following you here... ;P


    Quote Originally Posted by Ren
    Also just had a thought (whilst experimenting with defining relations with MadCap) do you really need both hasOne() and hasMany() ?

    Should be able to deduce that by the checking the wether the joining field is a PK or FK
    Ok, that's one good idea - I'll look into it.

  20. #170
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also wondering that should be able to only define relationships once.. if two tables are related would have to define the same relationship twice.

  21. #171
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't seem to load the model.serverside.se website. Anyone know if this is still being worked on?

    - matt


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •