-- Greg Donald <[EMAIL PROTECTED]> wrote
(on Friday, 25 April 2008, 02:26 PM -0500):
> On Wed, Apr 23, 2008 at 3:40 PM, Greg Donald <[EMAIL PROTECTED]> wrote:
> > In these docs:
> >
> >  http://framework.zend.com/manual/en/zend.rest.server.html
> >
> >  there is a require for My/Service/Class.php.  What might that class look 
> > like?
> 
> Anyone?

It can look however you want it; the server classes (xml-rpc, rest,
json) simply expose a class as a service consumable. They have the
following rules, though:

 * all public methods are exposed as service methods
 * all service methods should have php docblocks that minimally:
   * document each parameter, including type and name
   * document return value type

As an example, consider the following:

    class My_Service_Class
    {
        /**
         * @param  string $message Message to emit
         * @param  null|string $name Name to greet
         * @return string
         */
        public function hello($message, $name = null)
        {
            if (null !== $name) {
                return 'Hello, ' . (string) $name . " - \n" . (string) $message;
            }

            return "Hello -\n" . (string) $message;
        }
    }

You'd attach this to a server class using:

    $server->setClass('My_Service_Class');

and it would expose the 'hello' method.

The key is proper docblocks on all exposed methods;
Zend_Server_Reflection will throw errors if the return value is missing,
for instance, and services such as XML-RPC will throw errors if the
parameter types are unknown.

For more on phpdoc syntax, see the phpDocumentor site:

    http://phpdoc.org/

The side benefit is that this gets you following the best practice of
documenting your code. :-)

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to