E
E
Evgeny Blinkov2018-12-25 14:30:24
OOP
Evgeny Blinkov, 2018-12-25 14:30:24

How to implement versioning for rest api using factory method pattern in php?

I think how beautiful it is to write rest api in php. I'm trying to implement versioning. I read that you need to create your own model for each version using the Factory Method pattern. Good. But how to make it beautiful? Not if - else - run each version, or if so - then why is there a pattern at all? Or I just didn’t understand the essence of this pattern and my question is just moronic and how to do it then? Or is some other pattern suitable here? Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2018-12-25
@SilenceOfWinter

namespace api;

class v1\model {
  public static function factory() {
    return new static;
  }
}
class v2\model extends v1\model {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question