<commit_before><?php
/**
 * @link      https://github.com/weierophinney/PhlyRestfully for the canonical source repository
 * @copyright Copyright (c) 2013 <NAME>
 * @license   http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
 * @package   PhlyRestfully
 */

namespace PhlyRestfully\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Mvc\Controller\Plugin\Url as UrlHelper;
use Zend\View\Helper\ServerUrl as ServerUrlHelper;

/**
 * Plugin for generating fully qualified links, and sets of HAL-compliant
 * link relations
 *
 * @see http://tools.ietf.org/html/draft-kelly-json-hal-03
 */
class Links extends AbstractPlugin
{
    /**
     * @var ServerUrlHelper
     */
    protected $serverUrlHelper;

    /**
     * @var UrlHelper
     */
    protected $urlHelper;

    /**
     * @param ServerUrlHelper $helper
     */
    public function setServerUrlHelper(ServerUrlHelper $helper)
    {
        $this->serverUrlHelper = $helper;
    }

    /**
     * @param UrlHelper $helper
     */
    public function setUrlHelper(UrlHelper $helper)
    {
        $this->urlHelper = $helper;
    }

    /**
     * Create a fully qualified URI for a link
     *
     * @param  string $route
     * @param  null|int|string $id
     * @return string
     */
    public function createLink($route, $id = null)
    {
        $params = array();
        if (null !== $id) {
            $params['id'] = $id;
        }

        $path = $this->urlHelper->fromRoute($route, $params);
        return $this->serverUrlHelper->__invoke($path);
    }

    /**
     * Generate HAL link relation list
     *
     * @param  array $links
     * @return array
     */
    public function generateHalLinkRelations(array $links)
    {
        $halLinks = array();
        foreach ($links as $rel => $link) {<commit_msg>Re-use route match params when generating urls<commit_after><?php
/**
 * @link      https://github.com/weierophinney/PhlyRestfully for the canonical source repository
 * @copyright Copyright (c) 2013 <NAME>
 * @license   http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
 * @package   PhlyRestfully
 */

namespace PhlyRestfully\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Mvc\Controller\Plugin\Url as UrlHelper;
use Zend\View\Helper\ServerUrl as ServerUrlHelper;

/**
 * Plugin for generating fully qualified links, and sets of HAL-compliant
 * link relations
 *
 * @see http://tools.ietf.org/html/draft-kelly-json-hal-03
 */
class Links extends AbstractPlugin
{
    /**
     * @var ServerUrlHelper
     */
    protected $serverUrlHelper;

    /**
     * @var UrlHelper
     */
    protected $urlHelper;

    /**
     * @param ServerUrlHelper $helper
     */
    public function setServerUrlHelper(ServerUrlHelper $helper)
    {
        $this->serverUrlHelper = $helper;
    }

    /**
     * @param UrlHelper $helper
     */
    public function setUrlHelper(UrlHelper $helper)
    {
        $this->urlHelper = $helper;
    }

    /**
     * Create a fully qualified URI for a link
     *
     * @param  string $route
     * @param  null|int|string $id
     * @return string
     */
    public function createLink($route, $id = null)
    {
        $params = array();
        if (null !== $id) {
            $params['id'] = $id;
        }

        $path = $this->urlHelper->fromRoute($route, $params, true);
        return $this->serverUrlHelper->__invoke($path);
    }

    /**
     * Generate HAL link relation list
     *
     * @param  array $links
     * @return array
     */
    public function generateHalLinkRelations(array $links)
    {
        $halLinks = array();
        foreach ($links as $rel => $link) {
{'fraction_non_alphanumeric': 0.12701888858472488, 'fraction_numerical': 0.0043799616753353405, 'mean_word_length': 2.4245548266166823, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '5275155', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1099, 'n_words': 263}