PHPackages                             petrgrishin/url-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. petrgrishin/url-builder

ActiveLibrary

petrgrishin/url-builder
=======================

Url builder

2.0.0(11y ago)2221MITPHPPHP &gt;=5.3.0

Since Aug 4Pushed 11y ago2 watchersCompare

[ Source](https://github.com/petrgrishin/url-builder)[ Packagist](https://packagist.org/packages/petrgrishin/url-builder)[ RSS](/packages/petrgrishin-url-builder/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

url-builder
===========

[](#url-builder)

[![Travis CI](https://camo.githubusercontent.com/cee9838e843a44a527ff012e21de2be8a1d04f55a2140fd73c7d20327b23ed61/68747470733a2f2f7472617669732d63692e6f72672f706574726772697368696e2f75726c2d6275696c6465722e706e67 "Travis CI")](https://travis-ci.org/petrgrishin/url-builder)[![Coverage Status](https://camo.githubusercontent.com/137a7cfbd8af949fdfa839a466f05bf2df2c017c12e8d24d001ae3721e2aeed1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f706574726772697368696e2f75726c2d6275696c6465722f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/petrgrishin/url-builder?branch=master)

Url builder

Установка
---------

[](#установка)

Добавите зависимость для вашего проекта в composer.json:

```
{
    "require": {
        "petrgrishin/url-builder": "~1.0"
    }
}
```

Постановка проблемы
-------------------

[](#постановка-проблемы)

Необходимо определить знание об адресе контроллеров в одном слое сисстемы. Это позволит быстро и безболезненно производить поиск и рефакторинг контроллеров и их адресов.

Реализовать проверку достаточности параметров построения адреса, если такое происходит в другом слое, например в представлении или клиентских скриптах.

Решение
-------

[](#решение)

Все адреса контроллеров должны быть определены в самих контроллерах. При необходимости недостающие параметры можно заполнить в слое представления или клиентского скрипта. Для удобной работы необходимо определить помощника - построитель адресов.

Примеры использования
---------------------

[](#примеры-использования)

#### Определение знания об адресе в контроллере

[](#определение-знания-об-адресе-в-контроллере)

Базовый абстрактный контроллер. Реализация метода создания обектов построителя адреса

```
class BaseController extends \CController {

    public function createUrlBuilder($route, $params = array()) {
        $urlBuilder = new SimpleUrlBuilder();
        $urlBuilder
            ->setRoute($route)
            ->setParams($params);
        return $urlBuilder;
    }
}
```

Конкретный контроллер. Использование построителя адреса

```
class SiteController extends BaseController {

    public function actionIndex() {
        return $this->render('index', array(
            'urls' => array(
                'catalog' => $this->createUrlBuilder('site/catalog')
                    ->getUrl(),
                // передана готовая строка адреса /?r=site/catalog
            ),
        ));
    }

    public function actionCatalog() {
        return $this->render('about', array(
            'products' => Product::model()->findAll(),
            'urls' => array(
                'product' => $this->createUrlBuilder('site/product')
                    ->setRequired(array('id')),
                // передан объект построителя с необходимыми знаниями,
                // требуемые параметры заполняются в представлении
            ),
        ));
    }

    public function actionProduct($id) {
        return $this->render('product');
    }
}
```

Представление вывода каталога товаров

```
/** @var UrlBuilder $productUrlBuilder */
$productUrlBuilder = $this->getParam('urls.product');

foreach ($this->getParam('products') as $product) {
    $productUrl = $productUrlBuilder
        ->copy()
        ->setParam('id', $product->id)
        ->getUrl();

    print($productUrl);
    // строка адреса /?r=site/product&id=1
}

// или передать параметры построителя адреса в клиентский скрипт
$this->setJsParams(array(
    'urls' => array(
        'product' => $productUrlBuilder->toArray(),
    ),
));
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

4292d ago

Major Versions

1.0.2 → 2.0.02014-08-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcef45dd6d44dfcbfeb841a627bbc886b2f9d41f90d8826fb46cd4aca19264d5?d=identicon)[petrgrishin](/maintainers/petrgrishin)

---

Top Contributors

[![petrgrishin](https://avatars.githubusercontent.com/u/580229?v=4)](https://github.com/petrgrishin "petrgrishin (9 commits)")[![sabirovruslan](https://avatars.githubusercontent.com/u/8289352?v=4)](https://github.com/sabirovruslan "sabirovruslan (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petrgrishin-url-builder/health.svg)

```
[![Health](https://phpackages.com/badges/petrgrishin-url-builder/health.svg)](https://phpackages.com/packages/petrgrishin-url-builder)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
