Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1 KB

custom-object-descriptor.md

File metadata and controls

39 lines (29 loc) · 1 KB

Custom Object Descriptor recipe

Writing an object descriptor is as easy as creating a class that implements the ObjectDescriptorInterface. But again it is highly recommended to implement the SupportsObjectDescriptorInterface.

Example :

<?php

use Yokai\SafeDelete\Usage\Descriptor\SupportsObjectDescriptorInterface;

class ApiResourceUsageFinder implements SupportsObjectDescriptorInterface
{
    public function supports(object $object): bool
    {
        return $object instanceof ApiResourceInterface;
    }

    public function describe(object $object): string 
    {
        return sprintf(
            '%s (from %s domain with %s identity)',
            (string) $object,
            $object->getDomain(),
            $object->getIdentity() ?: 'none'
        );
    }
}

« README