Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending class #1

Open
emilorol opened this issue Jan 13, 2016 · 2 comments
Open

Extending class #1

emilorol opened this issue Jan 13, 2016 · 2 comments

Comments

@emilorol
Copy link

Hi Tom,

I was thinking if there was a way to extend to Repository class so that I can use it as CRUD and pass the new schema from other models.

class bookmark extend repository {

public function makeSchema()   {
        return (new Schema('Color'))
            ->addDatetime('posted')
            ->addString('name', FALSE)
            ->addString('message', FALSE)
            ->addString('ip')
        ;
    }

}

Thank you.

@tomwalder
Copy link
Owner

I'm not 100% sure what you are getting at here.

I have done things like this on occasion:

class Factory
{
   public function getBook()
   {
      return new Store((new Schema('Book'))->addString('title'));
   }
   public function getAuthor()
   {
      return new Store((new Schema('Author'))->addString('name'));
   }
}

Is that what you are getting at?

@emilorol
Copy link
Author

Hi Tom,

What I want to make is a "Model" class with the "CRUD" methods that I can extent on my "sub models".

class Model {

  public function makeSchema()
    {
        return $this;
    }

}

Then when I create a model for a kind call Bookmark I can just said:

class bookmark extend Model {

    public function makeSchema()
    {
        return (new Schema('Bookmark'))
            ->addDatetime('posted')
            ->addString('name', FALSE)
            ->addString('message', FALSE)
            ->addString('ip')
        ;
    }
}

and since I am inheriting all other methods from "Model" I already have the update, post, delete operations for the new "kind".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants