Giter Club home page Giter Club logo

Comments (4)

bonndan avatar bonndan commented on May 6, 2024

Meanwhile I have a workaround:

$emitter = $this->client->getEmitter();
        foreach ($emitter->listeners() as $listeners)
        {
            foreach ($listeners as $listener)
            {
                if ($listener[0] instanceof PrepareRequest)
                {
                    $emitter->detach($listener[0]);
                    $emitter->attach(new PrepareRequest(array("path" => new PathLocation('path'))));
                    break;
                }
            }
        }

with the following PathLocation implementation (using underscores for the placeholder)

namespace XYZ;

use GuzzleHttp\Command\Guzzle\Parameter;
use GuzzleHttp\Message\RequestInterface;
use GuzzleHttp\Command\Guzzle\Operation;
use GuzzleHttp\Command\Guzzle\GuzzleCommandInterface;
use GuzzleHttp\Command\Guzzle\RequestLocation\AbstractLocation;

/**
 * Inserts url path parameters.
 *
 */
class PathLocation extends AbstractLocation
{
    public function visit(
        GuzzleCommandInterface $command,
        RequestInterface $request,
        Parameter $param,
        array $context
    ) {
        $value = $this->prepareValue(
            $command[$param->getName()],
            $param
        );
        $this->replaceParam($request, $param->getWireName(), $value);
    }

    public function after(
        GuzzleCommandInterface $command,
        RequestInterface $request,
        Operation $operation,
        array $context
    ) {
        return;
        $additional = $operation->getAdditionalParameters();
        if ($additional && $additional->getLocation() == $this->locationName) {
            foreach ($command->toArray() as $key => $value) {
                if (!$operation->hasParam($key)) {
                    $this->replaceParam($request, $key, $this->prepareValue(
                        $value,
                        $additional
                    ));
                }
            }
        }
    }

    private function replaceParam(RequestInterface $request, $name, $value)
    {
        $path = str_replace('_' . $name . '_', $value, $request->getPath());
        $request->setPath($path);
    }
}

from guzzle-services.

mtdowling avatar mtdowling commented on May 6, 2024

You can just use the uri template functionality of Guzzle and set the location of the parameter to "uri".

from guzzle-services.

bonndan avatar bonndan commented on May 6, 2024

Many thanks, that fixed it. No code necessary. Since I have been (and still am) too dumb to find the proper place in the documentation, I quickly hacked the readme.

#48

from guzzle-services.

bonndan avatar bonndan commented on May 6, 2024

Thanks again. I'm closing this.

from guzzle-services.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.