[NFR] Implement interfaces for the Phalcon components so that they can be easily extendable

173 views
Skip to first unread message

Nikolaos Dimopoulos

unread,
Oct 28, 2012, 12:57:52 PM10/28/12
to phalcon-...@googlegroups.com
Description
The framework should provide the ability for developers to replace common components with their own implementations by using interfaces that Phalcon would understand. This calls for generation of interfaces for most components.

Rules
  • For most components an interface must be created that components will use
Examples
  • \Phalcon\Logger\Interface
    • \Phalcon\Logger\Adapter\File implements it
    • \Phalcon\Logger\Adapter\Db\MySql can use it (component not available yet)
    • \Phalcon\Logger\Adapter\Db\Postgresql can use it (component not available yet)
    • \Phalcon\Logger\Adapter\Db\Sqlite can use it (component not available yet)
  • \Phalcon\Translate\Interface
    • \Phalcon\Translate\Adapter\NativeArray implements it
    • \Phalcon\Translate\Adapter\Gettext can use it (component not available yet)
    • \Phalcon\Translate\Adapter\Csv can use it (component not available yet)

hdo...@gmail.com

unread,
Oct 28, 2012, 3:15:04 PM10/28/12
to phalcon-...@googlegroups.com
What about just "adapter" interface/abstract instead of "interface".

I used Phalcon\Mail\Transport abstract class for mail component, which "PHP" transport adapter extends it, and I check it strictly if transport class is instance of Phalcon\Mail\Transport class (else it throws an exception). And transport adapters should have protected abstract "send" method (just defined it as abstract in phalcon.h and implement dummy/empty send method). So I don't have to check if it has "send" method or not (phalcon_method_exists), just fire adapter's "send" method.

So

Phalcon\Logger\Adapter (dummy adapter class - log/begin/commit/rollback/etc methods must be implemented)
Phalcon\Logger\Adapter\File extends from Phalcon\Logger\Adapter

Phalcon\Translate\Adapter (dummy adapter class - query/exists/etc methods must be implemented)
Phalcon\Translate\Adapter\NativeArray extends from Phalcon\Translate\Adapter

Phalcon\Mail\Transport (dummy adapter class - send method must be implemented)
Phalcon\Mail\Transport\PHP extends from Phalcon\Mail\Transport

Same for session, cache backends, etc.

Nikolaos Dimopoulos

unread,
Oct 28, 2012, 6:04:28 PM10/28/12
to phalcon-...@googlegroups.com
That is perfectly fine.

The actual design decision will be taken as soon as work for 0.7.0 starts which will be Nov 05, 2012 onward. We can have discussions about this and suggestions so as to get to a conclusion that would benefit the framework as well as the developers :)

We can have a hangout if you guys like to throw ideas around.

Nikos

hdo...@gmail.com

unread,
Nov 10, 2012, 4:26:24 PM11/10/12
to phalcon-...@googlegroups.com
Which naming convention has been accepted?

Andres-Gutierrez

unread,
Nov 10, 2012, 4:33:55 PM11/10/12
to hdo...@gmail.com, phalcon-...@googlegroups.com
Since \Phalcon\Logger\Interface isn't a valid class name, I'm appending "Interface" to the current class names:

\Phalcon\Http\ResponseInterface
\Phalcon\Logger\AdapterInterface
\Phalcon\FlashInterface

--
 
 

hdo...@gmail.com

unread,
Nov 10, 2012, 4:35:51 PM11/10/12
to phalcon-...@googlegroups.com, hdo...@gmail.com, andres.g...@phalconphp.com
Is "Interface" used by PHP internals/source-code?

Andres-Gutierrez

unread,
Nov 10, 2012, 4:38:00 PM11/10/12
to hdo...@gmail.com, phalcon-...@googlegroups.com
Is a reserved keyword, try this:

interface Phalcon\Logger\Interface {

}

Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting '{' in /www/c.php on line 3

--
 
 

hdo...@gmail.com

unread,
Nov 10, 2012, 4:40:43 PM11/10/12
to phalcon-...@googlegroups.com, hdo...@gmail.com, andres.g...@phalconphp.com
Crap! I think the reason is "interface" keyword and case insensitivity :/
Reply all
Reply to author
Forward
0 new messages