Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HuggableInterface in PHP and PSR-8

Tags:

php

interface

On the PHP Framework Interop Group site (the maintainer of PSRs), there is a draft PSR-8 Huggable Interface:

namespace Psr\Hug;

/**
 * Defines a huggable object.
 *
 * A huggable object expresses mutual affection with another huggable object.
 */
interface Huggable
{

    /**
     * Hugs this object.
     *
     * All hugs are mutual. An object that is hugged MUST in turn hug the other
     * object back by calling hug() on the first parameter. All objects MUST
     * implement a mechanism to prevent an infinite loop of hugging.
     *
     * @param Huggable $h
     *   The object that is hugging this object.
     */
    public function hug(Huggable $h);
}

The draft is quite short but does not provide any examples of implementation. What is the purpose of implementing this interface?

like image 605
rink.attendant.6 Avatar asked Jun 10 '15 16:06

rink.attendant.6


1 Answers

I started an implementation here: https://github.com/dave1010/php-fig-psr-8

It's not quite finished (contributors welcome!) but already useful if you need a PSR-8 implementation in your projects.

like image 184
dave1010 Avatar answered Oct 20 '22 04:10

dave1010