PlaydarResolver::handleRequest PHP Метод

handleRequest() публичный Метод

public handleRequest ( $fh )
    public function handleRequest($fh)
    {
        while (!feof($fh)) {
            // Makes the handler compatable with command line testing and playdar resolver pipeline usage
            if (!($content = fread($fh, 4))) {
                break;
            }
            // get the length of the payload from the first 4 bytes:
            $len = current(unpack('N', $content));
            // bail on empty request.
            if ($len == 0) {
                continue;
            }
            // read $len bytes for the actual payload and assume it's a JSON object.
            $request = json_decode(fread($fh, $len));
            // Malformed request
            if (!isset($request->artist, $request->album)) {
                continue;
            }
            // Let's resolve this bitch
            $results = $this->resolve($request);
            // No results, bail
            if (!$results) {
                continue;
            }
            // Build response and send
            $response = (object) array('_msgtype' => 'results', 'qid' => $request->qid, 'results' => $results);
            $this->sendResponse($response);
        }
    }