<commit_before><?php

namespace Ivory\GoogleMapBundle\Model\Services\Directions;

use Ivory\GoogleMapBundle\Model\Services\AbstractService;

use Ivory\GoogleMapBundle\Model\Overlays\EncodedPolyline;

use Ivory\GoogleMapBundle\Model\Base\Bound;
use Ivory\GoogleMapBundle\Model\Base\Coordinate;

/**
 * Google map directions service
 *
 * @author GeLo <<EMAIL>>
 */
class DirectionsService extends AbstractService
{
    /**
     * Creates a directions service
     */
    public function __construct()
    {
        parent::__construct('http://maps.googleapis.com/maps/api/directions');
    }
    
    /**
     * Routes the given request
     *
     * @param Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRequest $directionsRequest 
     */
    public function route(DirectionsRequest $directionsRequest)
    {
        if(!$directionsRequest->isValid())
            throw new \InvalidArgumentException('The directions request is not valid. It needs at least an origin and a destination.'.PHP_EOL.'If you add waypoint to the directions request, it needs at least a location.');
        
        $response = $this->browser->get($this->generateUrl($directionsRequest));
        $directionsResponse = $this->buildDirectionsResponse($this->parse($response->getContent()));
        
        return $directionsResponse;
    }
    
    /**
     * Generates directions URL API according to the request
     *
     * @param Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRequest $directionsRequest<commit_msg>Allow to route an origin/destination or a DirectionsRequest<commit_after><?php

namespace Ivory\GoogleMapBundle\Model\Services\Directions;

use Ivory\GoogleMapBundle\Model\Services\AbstractService;

use Ivory\GoogleMapBundle\Model\Overlays\EncodedPolyline;

use Ivory\GoogleMapBundle\Model\Base\Bound;
use Ivory\GoogleMapBundle\Model\Base\Coordinate;

/**
 * Google map directions service
 *
 * @author GeLo <<EMAIL>>
 */
class DirectionsService extends AbstractService
{
    /**
     * Creates a directions service
     */
    public function __construct()
    {
        parent::__construct('http://maps.googleapis.com/maps/api/directions');
    }
    
    /**
     * Routes the given request
     *
     * Available prototypes:
     * - public function route(string $origin, string $destination)
     * - public function route(Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRequest $request)
     */
    public function route()
    {
        $args = func_get_args();
        
        if(isset($args[0]) && is_string($args[0]) && isset($args[1]) && is_string($args[1]))
        {
            $directionsRequest = new DirectionsRequest();
            $directionsRequest->setOrigin($args[0]);
            $directionsRequest->setDestination($args[1]);
        }
        else if(isset($args[0]) && ($args[0] instanceof DirectionsRequest))
            $directionsRequest = $args[0];
        else
            throw new \InvalidArgumentException('%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s',
                'The route arguments are invalid.',
                'The available prototypes are:',
                '- public function route(string $origin, string $destination)',
                '- public function route(Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRequest $request)'
            );
        
        if(!$directionsRequest->isValid())
            throw new \InvalidArgumentException('The directions request is not valid. It needs at least an origin and a destination.'.PHP_EOL.'If you add waypoint to the directions request, it needs at least a location.');
        
        $response = $this->browser->get($this->generateUrl($directionsRequest));
        $directionsResponse = $this->buildDirectionsResponse($this->parse($response->getContent()));
        
        return $directionsResponse;
    }
    
    /**
     * Generates directions URL API according to the request
     *
     * @param Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRequest $directionsRequest
{'fraction_non_alphanumeric': 0.11425732737208147, 'fraction_numerical': 0.0022354694485842027, 'mean_word_length': 3.092479674796748, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7241274', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1078, 'n_words': 233}