+1 (855) 920-2583
Login

How to know what object is being linked or unlinked to/from your resource in PHP runtime

Modified on: Fri, 17 Nov 2023 12:07 PM
Original Publishing Date:
2020-01-22

Problem

For <linkname>Link() and <linkname>Unlink() methods in my application resource I would like to know the resource that is being linked or unlinked.

Solution

You can get a link object (APS\ResourceProxy) as an argument to your link and unlink methods. Suppose I have a resource with a relation to an array of DNS records called arecords. This function will write to log the ID of the DNS record that is being unlinked:

public function arecordsUnlink($record) {
        APS\Logger::get()->debug("Record unlinked: " . print_r($record->aps->id, true));
}

Result in /var/log/httpd/error_log will look like this:

[2014-07-03 06:04:52.554716 UTC] DEBUG Record unlinked: dbc28c5f-9605-4c0c-b5ef-3e48ba1ff1f0

Internal content