<commit_before><?php
/**
 * Store all necessary information about 3rd party APIs
 */

namespace Graviton\ProxyBundle\Definition;

/**
 * ApiDefinition
 *
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link    http://swisscom.ch
 */
class ApiDefinition
{
    /**
     * @var string
     */
    private $basePath;

    /**
     * @var string
     */
    private $host;

    /**
     * @var mixed
     */
    private $origin;

    /**
     * @var array
     */
    private $endpoints = array();

    /**
     * @var array
     */
    private $schemes = array();

    /**
     * sets the base path of the api
     *
     * @param string $basePath API base path
     *
     * @return void
     */
    public function setBasePath($basePath)
    {
        $this->basePath = $basePath;
    }

    /**
     * sets the FQDN of the API
     *
     * @param string $host FQDN
     *
     * @return void
     */
    public function setHost($host)
    {
        $this->host = $host;
    }

    /**
     * get the FQDN of the API
     *
     * @return string FQDN
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * set the origin service definition
     *
     * @param mixed $origin the origin service definition (type depends on dispersal strategy)
     *
     * @return void
     */
    public function setOrigin($origin)
    {
        $this->origin = $origin;
    }

    /**
     * get the origin service definition
     *
     * @return mixed the origin service definition (type depends on dispersal strategy)
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * add an endpoint
     *
     * @param string $endpoint endpoint
     *
     * @return void
     */
    public function addEndpoint($endpoint)
    {
        $this->endpoints[] = $endpoint;
    }

    /**
     * check if an endpoint exists
     *
     * @param string $endpoint endpoint
     *
     * @return boolean
     */
    public function hasEndpoint($endpoint)
    {
        $retVal = false;
        if (isset($this->endpoints)) {
            $retVal = in_array($endpoint, $this->endpoints);
        }

        return $retVal;
    }

    /**
     * get all defined API endpoints
     *
     * @param boolean $withHost url with hostname
     * @param string  $prefix   add a prefix to the url (blub/endpoint/url)
     *
     * @return array
     */
    public function getEndpoints($withHost = true, $prefix = null)
    {
        $endpoints = array();
        $basePath = "";
        if ($withHost) {
            $basePath = $this->getHost();
        }
        if (!empty($prefix)) {
            $basePath .= $prefix;
        }
        if (isset($this->basePath)) {
            $basePath .= $this->basePath;
        }
        foreach ($this->endpoints as $endpoint) {
            $endpoints[] = $basePath.$endpoint;
        }<commit_msg>Added ability to provide a hostname to getEndpoints<commit_after><?php
/**
 * Store all necessary information about 3rd party APIs
 */

namespace Graviton\ProxyBundle\Definition;

/**
 * ApiDefinition
 *
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link    http://swisscom.ch
 */
class ApiDefinition
{
    /**
     * @var string
     */
    private $basePath;

    /**
     * @var string
     */
    private $host;

    /**
     * @var mixed
     */
    private $origin;

    /**
     * @var array
     */
    private $endpoints = array();

    /**
     * @var array
     */
    private $schemes = array();

    /**
     * sets the base path of the api
     *
     * @param string $basePath API base path
     *
     * @return void
     */
    public function setBasePath($basePath)
    {
        $this->basePath = $basePath;
    }

    /**
     * sets the FQDN of the API
     *
     * @param string $host FQDN
     *
     * @return void
     */
    public function setHost($host)
    {
        $this->host = $host;
    }

    /**
     * get the FQDN of the API
     *
     * @return string FQDN
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * set the origin service definition
     *
     * @param mixed $origin the origin service definition (type depends on dispersal strategy)
     *
     * @return void
     */
    public function setOrigin($origin)
    {
        $this->origin = $origin;
    }

    /**
     * get the origin service definition
     *
     * @return mixed the origin service definition (type depends on dispersal strategy)
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * add an endpoint
     *
     * @param string $endpoint endpoint
     *
     * @return void
     */
    public function addEndpoint($endpoint)
    {
        $this->endpoints[] = $endpoint;
    }

    /**
     * check if an endpoint exists
     *
     * @param string $endpoint endpoint
     *
     * @return boolean
     */
    public function hasEndpoint($endpoint)
    {
        $retVal = false;
        if (isset($this->endpoints)) {
            $retVal = in_array($endpoint, $this->endpoints);
        }

        return $retVal;
    }

    /**
     * get all defined API endpoints
     *
     * @param boolean $withHost url with hostname
     * @param string  $prefix   add a prefix to the url (blub/endpoint/url)
     * @param string  $host
     *
     * @return array
     */
    public function getEndpoints($withHost = true, $prefix = null, $host = '')
    {
        $endpoints = array();
        $basePath = "";
        if ($withHost) {
            $basePath = (empty($host)) ? $this->getHost() : $host;
        }
        if (!empty($prefix)) {
            $basePath .= $prefix;
        }
        if (isset($this->basePath)) {
            $basePath .= $this->basePath;
        }
        foreach ($this->endpoints as $endpoint) {
            $endpoints[] = $basePath.$endpoint;
        }
{'fraction_non_alphanumeric': 0.12506122448979592, 'fraction_numerical': 0.00032653061224489796, 'mean_word_length': 1.7384890478319177, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 2, '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': '131880', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1790, 'n_words': 475}