Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1 +0,0 @@
service_name: travis-ci

View File

@@ -2,17 +2,23 @@
root = true
# Defaults - Linux style, 4 spaces
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[ISSUE_TEMPLATE.md]
# Markdown uses trailing whitespace to indicate continuation lines
[*.{markdown,md}]
trim_trailing_whitespace = false
[*.yml]
# Ruby standard is 2 spaces
[{*.rb,Gemfile,Rakefile,Vagrantfile}]
indent_size = 2
# Ansible standard is 2 spaces
[ansible/**/*.yml]
indent_size = 2
indent_style = space

View File

@@ -1,16 +0,0 @@
language: php
php:
- 7.0
- 5.6
- 5.5
- hhvm
install:
- travis_retry composer install --no-interaction
script:
- phpunit --coverage-clover build/logs/clover.xml
after_script:
- php vendor/bin/coveralls -v

View File

@@ -1,7 +0,0 @@
################################################################################
Support & Contribution Guidelines
################################################################################
.. This file is for GitHub (https://github.com/blog/1184-contributing-guidelines)
Before submitting a support request, bug report, feature request or pull request, please take a moment to read the instructions in the `README <README.rst#documentation>`_ file. Thank you.

View File

@@ -1,49 +0,0 @@
(For support requests / bug reports, please complete the following - or delete if not applicable.)
**Summary of issue**
**The complete error message, including file & line numbers**
**Software versions**
Laravel Breadcrumbs:
Laravel:
PHP:
**Copy of `routes/breadcrumbs.php` (or `app/Http/breadcrumbs.php`)**
```php
```
**Copy of `routes/web.php` (or `app/Http/routes.php`)**
```php
```
**Copy of `config/breadcrumbs.php` (if used)**
```php
```
**Copy of the view and/or layout files (e.g. `resources/views/home.blade.php`, `resources/views/layouts/master.blade.php`)**
```php
```
**Copy of the custom breadcrumbs template (if used, e.g. `resources/views/_partials/breadcrumbs.blade.php`)**
```php
```
**Copy of `config/app.php`**
```php
```
**Copy of any other relevant files**
```php
```
**Any other information**

View File

@@ -0,0 +1,895 @@
Laravel Breadcrumbs
================================================================================
[![Latest Stable Version](https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/v/stable?format=flat-square)](https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs)
[![Total Downloads](https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/downloads?format=flat-square)](https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs)
[![Monthly Downloads](https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/d/monthly?format=flat-square)](https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs)
[![Latest Unstable Version](https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/v/unstable?format=flat-square)](https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs)
[![License](https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/license?format=flat-square)](https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs)
A simple Laravel-style way to create breadcrumbs in [Laravel](https://laravel.com/).
Table of Contents
--------------------------------------------------------------------------------
- [Compatibility Chart](#compatibility-chart)
- [Getting Started](#getting-started)
- [Defining Breadcrumbs](#defining-breadcrumbs)
- [Custom Templates](#custom-templates)
- [Outputting Breadcrumbs](#outputting-breadcrumbs)
- [Route-Bound Breadcrumbs](#route-bound-breadcrumbs)
- [Advanced Usage](#advanced-usage)
- [API Reference](#api-reference)
- [Changelog](#changelog)
- [Technical Support](#technical-support)
- [Bug Reports](#bug-reports)
- [Contributing](#contributing)
- [License](#license)
Compatibility Chart
--------------------------------------------------------------------------------
| Laravel Breadcrumbs | Laravel | PHP |
|------------------------------------------------------------------------|-----------|------|
| 3.0.2+ | 5.0 5.4 | 5.4+ |
| 3.0.1 | 5.0 5.3 | 5.4+ |
| 3.0.0 | 5.0 5.2 | 5.4+ |
| [2.x](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.x) | 4.0 4.2 | 5.3+ |
Getting Started
--------------------------------------------------------------------------------
### 1. Install Laravel Breadcrumbs
#### Install with Composer
Run this at the command line:
```bash
composer require davejamesmiller/laravel-breadcrumbs
```
This will both update `composer.json` and install the package into the `vendor/` directory.
#### Add to `config/app.php`
Add the service provider to `providers`:
```php
'providers' => [
// ...
DaveJamesMiller\Breadcrumbs\ServiceProvider::class,
],
```
And add the facade to `aliases`:
```php
'aliases' => [
// ...
'Breadcrumbs' => DaveJamesMiller\Breadcrumbs\Facade::class,
],
```
### 2. Define your breadcrumbs
Create a file called `routes/breadcrumbs.php` that looks like this:
```php
<?php
// Home
Breadcrumbs::register('home', function($breadcrumbs)
{
$breadcrumbs->push('Home', route('home'));
});
// Home > About
Breadcrumbs::register('about', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('About', route('about'));
});
// Home > Blog
Breadcrumbs::register('blog', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Blog', route('blog'));
});
// Home > Blog > [Category]
Breadcrumbs::register('category', function($breadcrumbs, $category)
{
$breadcrumbs->parent('blog');
$breadcrumbs->push($category->title, route('category', $category->id));
});
// Home > Blog > [Category] > [Page]
Breadcrumbs::register('page', function($breadcrumbs, $page)
{
$breadcrumbs->parent('category', $page->category);
$breadcrumbs->push($page->title, route('page', $page->id));
});
```
See the [Defining Breadcrumbs](#defining-breadcrumbs) section for more details.
### 3. Choose a template
By default a [Bootstrap](http://getbootstrap.com/components/#breadcrumbs)-compatible ordered list will be rendered, so if you're using Bootstrap 3 you can skip this step.
First initialise the config file by running this command:
```bash
php artisan vendor:publish
```
Then open `config/breadcrumbs.php` and edit this line:
```php
'view' => 'breadcrumbs::bootstrap3',
```
The possible values are:
- [Bootstrap 3](http://getbootstrap.com/components/#breadcrumbs): `breadcrumbs::bootstrap3`
- [Bootstrap 2](http://getbootstrap.com/2.3.2/components.html#breadcrumbs): `breadcrumbs::bootstrap2`
- The path to a custom view: e.g. `_partials/breadcrumbs`
See the [Custom Templates](#custom-templates) section for more details.
### 4. Output the breadcrumbs
Finally, call `Breadcrumbs::render()` in the view template for each page, passing it the name of the breadcrumb to use and any additional parameters for example:
```html+php
{!! Breadcrumbs::render('home') !!}
{!! Breadcrumbs::render('category', $category) !!}
```
See the [Outputting Breadcrumbs](#outputting-breadcrumbs) section for other output options, and see [Route-Bound Breadcrumbs](#route-bound-breadcrumbs) for a way to link breadcrumb names to route names automatically.
Defining Breadcrumbs
--------------------------------------------------------------------------------
Breadcrumbs will usually correspond to actions or types of page. For each breadcrumb you specify a name, the breadcrumb title and the URL to link it to. Since these are likely to change dynamically, you do this in a closure, and you pass any variables you need into the closure.
The following examples should make it clear:
### Static pages
The most simple breadcrumb is probably going to be your homepage, which will look something like this:
```php
Breadcrumbs::register('home', function($breadcrumbs) {
$breadcrumbs->push('Home', route('home'));
});
```
As you can see, you simply call `$breadcrumbs->push($title, $url)` inside the closure.
For generating the URL, you can use any of the standard Laravel URL-generation methods, including:
- `url('path/to/route')` (`URL::to()`)
- `secure_url('path/to/route')`
- `route('routename')` or `route('routename', 'param')` or `route('routename', ['param1', 'param2'])` (`URL::route()`)
- ``action('controller@action')`` (``URL::action()``)
- Or just pass a string URL (`'http://www.example.com/'`)
This example would be rendered like this:
> Home
### Parent links
This is another static page, but this has a parent link before it:
```php
Breadcrumbs::register('blog', function($breadcrumbs) {
$breadcrumbs->parent('home');
$breadcrumbs->push('Blog', route('blog'));
});
```
It works by calling the closure for the `home` breadcrumb defined above.
It would be rendered like this:
> [Home](#) / Blog
Note that the default template does not create a link for the last breadcrumb (the one for the current page), even when a URL is specified. You can override this by creating your own template see [Custom Templates](#custom-templates) for more details.
### Dynamic titles and links
This is a dynamically generated page pulled from the database:
```php
Breadcrumbs::register('page', function($breadcrumbs, $page) {
$breadcrumbs->parent('blog');
$breadcrumbs->push($page->title, route('page', $page->id));
});
```
The `$page` variable would simply be passed in from the view:
```html+php
{!! Breadcrumbs::render('page', $page) !!}
```
It would be rendered like this:
> [Home](#) / [Blog](#) / Page Title
**Tip:** You can pass multiple parameters if necessary.
### Nested categories
Finally if you have nested categories or other special requirements, you can call `$breadcrumbs->push()` multiple times:
```php
Breadcrumbs::register('category', function($breadcrumbs, $category) {
$breadcrumbs->parent('blog');
foreach ($category->ancestors as $ancestor) {
$breadcrumbs->push($ancestor->title, route('category', $ancestor->id));
}
$breadcrumbs->push($category->title, route('category', $category->id));
});
```
Alternatively you could make a recursive function such as this:
```php
Breadcrumbs::register('category', function($breadcrumbs, $category) {
if ($category->parent)
$breadcrumbs->parent('category', $category->parent);
else
$breadcrumbs->parent('blog');
$breadcrumbs->push($category->title, route('category', $category->slug));
});
```
Both would be rendered like this:
> [Home](#) / [Blog](#) / [Grandparent Category](#) / [Parent Category](#) / Category Title
Custom Templates
--------------------------------------------------------------------------------
### Create a view
To customise the HTML, create your own view file (e.g. `resources/views/_partials/breadcrumbs.blade.php`) like this:
```html+php
@if ($breadcrumbs)
<ul class="breadcrumb">
@foreach ($breadcrumbs as $breadcrumb)
@if (!$breadcrumb->last)
<li><a href="{{ $breadcrumb->url }}">{{ $breadcrumb->title }}</a></li>
@else
<li class="active">{{ $breadcrumb->title }}</li>
@endif
@endforeach
</ul>
@endif
```
(See the [views/ directory](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/master/views) for the built-in templates.)
#### View data
The view will receive an array called `$breadcrumbs`.
Each breadcrumb is an object with the following keys:
- `title` The breadcrumb title (see :doc:`defining`)
- `url` The breadcrumb URL (see :doc:`defining`), or `null` if none was given
- `first` `true` for the first breadcrumb (top level), `false` otherwise
- `last` `true` for the last breadcrumb (current page), `false` otherwise
- Plus additional keys for each item in `$data` (see [Custom data](#custom-data))
### Update the config
Then update your config file (`config/breadcrumbs.php`) with the custom view name, e.g.:
```php
// resources/views/_partials/breadcrumbs.blade.php
'view' => '_partials/breadcrumbs',
```
Outputting Breadcrumbs
--------------------------------------------------------------------------------
Call `Breadcrumbs::render()` in the view template for each page, passing it the name of the breadcrumb to use and any additional parameters.
### With Blade
In the page (e.g. `resources/views/home.blade.php`):
```html+php
{!! Breadcrumbs::render('home') !!}
```
Or with a parameter:
```html+php
{!! Breadcrumbs::render('category', $category) !!}
```
### With Blade layouts and @section
In the page (e.g. `resources/views/home.blade.php`):
```html+php
@extends('layout.name')
@section('breadcrumbs', Breadcrumbs::render('home'))
```
In the layout (e.g. `resources/views/app.blade.php`):
```html+php
@yield('breadcrumbs')
```
### Pure PHP (without Blade)
In the page (e.g. `resources/views/home.php`):
```html+php
<?= Breadcrumbs::render('home') ?>
```
Or use the long-hand syntax if you prefer:
```html+php
<?php echo Breadcrumbs::render('home') ?>
```
Route-Bound Breadcrumbs
--------------------------------------------------------------------------------
In normal usage you must call `Breadcrumbs::render($name, $params...)` to render the breadcrumbs on every page. If you prefer, you can name your breadcrumbs the same as your routes and avoid this duplication.
### Setup
#### Name your routes
Make sure each of your routes has a name. For example (`routes/web.php`):
```php
// Home
Route::get('/', 'HomeController@index')->name('home');
// Home > [Page]
Route::get('/page/{id}', 'PageController@show')->name('page');
```
For more details see [Named Routes](https://laravel.com/docs/5.3/routing#named-routes) in the Laravel documentation.
#### Name your breadcrumbs to match
For each route, create a breadcrumb with the same name. For example (`routes/breadcrumbs.php`):
```php
// Home
Breadcrumbs::register('home', function($breadcrumbs) {
$breadcrumbs->push('Home', route('home'));
});
// Home > [Page]
Breadcrumbs::register('page', function($breadcrumbs, $id)
{
$page = Page::findOrFail($id);
$breadcrumbs->parent('home');
$breadcrumbs->push($page->title, route('page', $page->id));
});
```
#### Output breadcrumbs in your layout
Call `Breadcrumbs::render()` with no parameters in your layout file (e.g. `resources/views/app.blade.php`):
```html+php
{!! Breadcrumbs::render() !!}
```
This will automatically output breadcrumbs corresponding to the current route.
It will throw an exception if the breadcrumb doesn't exist, to remind you to create one. To prevent this behaviour, change it to:
```html+php
{!! Breadcrumbs::renderIfExists() !!}
```
### Route model binding
Laravel Breadcrumbs uses the same model binding as the controller. For example:
```php
// routes/web.php
Route::model('page', 'Page');
Route::get('/page/{page}', ['uses' => 'PageController@show', 'as' => 'page']);
```
```php
// app/Http/Controllers/PageController.php
class PageController extends Controller
{
public function show($page)
{
return view('page/show', ['page' => $page]);
}
}
```
```php
// routes/breadcrumbs.php
Breadcrumbs::register('page', function($breadcrumbs, $page)
{
$breadcrumbs->parent('home');
$breadcrumbs->push($page->title, route('page', $page->id));
});
```
This makes your code less verbose and more efficient by only loading the page from the database once.
For more details see [Route Model Binding](https://laravel.com/docs/5.3/routing#route-model-binding) in the Laravel documentation.
### Resourceful controllers
Laravel automatically creates route names for resourceful controllers, e.g. `photo.index`, which you can use when defining your breadcrumbs. For example:
```php
// routes/web.php
Route::resource('photo', 'PhotoController');
```
```
$ php artisan route:list
+--------+----------+--------------------+---------------+-------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+--------------------+---------------+-------------------------+------------+
| | GET|HEAD | photo | photo.index | PhotoController@index | |
| | GET|HEAD | photo/create | photo.create | PhotoController@create | |
| | POST | photo | photo.store | PhotoController@store | |
| | GET|HEAD | photo/{photo} | photo.show | PhotoController@show | |
| | GET|HEAD | photo/{photo}/edit | photo.edit | PhotoController@edit | |
| | PUT | photo/{photo} | photo.update | PhotoController@update | |
| | PATCH | photo/{photo} | | PhotoController@update | |
| | DELETE | photo/{photo} | photo.destroy | PhotoController@destroy | |
+--------+----------+--------------------+---------------+-------------------------+------------+
```
```php
// routes/breadcrumbs.php
// Photos
Breadcrumbs::register('photo.index', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Photos', route('photo.index'));
});
// Photos > Upload Photo
Breadcrumbs::register('photo.create', function($breadcrumbs)
{
$breadcrumbs->parent('photo.index');
$breadcrumbs->push('Upload Photo', route('photo.create'));
});
// Photos > [Photo Name]
Breadcrumbs::register('photo.show', function($breadcrumbs, $photo)
{
$breadcrumbs->parent('photo.index');
$breadcrumbs->push($photo->title, route('photo.show', $photo->id));
});
// Photos > [Photo Name] > Edit Photo
Breadcrumbs::register('photo.edit', function($breadcrumbs, $photo)
{
$breadcrumbs->parent('photo.show', $photo);
$breadcrumbs->push('Edit Photo', route('photo.edit', $photo->id));
});
```
For more details see [Resource Controllers](https://laravel.com/docs/5.3/controllers#resource-controllers) in the Laravel documentation.
### Implicit controllers
To use implicit controllers, you must specify names for each route. For example:
```php
// routes/web.php
Route::controller('auth', 'Auth\AuthController', [
'getRegister' => 'auth.register',
'getLogin' => 'auth.login',
]);
```
(You don't need to provide route names for actions that redirect and never display a view e.g. most POST views.)
For more details see [Implicit Controllers](https://laravel.com/docs/5.1/controllers#implicit-controllers) in the Laravel documentation.
Advanced Usage
--------------------------------------------------------------------------------
### Breadcrumbs with no URL
The second parameter to `push()` is optional, so if you want a breadcrumb with no URL you can do so:
```php
$breadcrumbs->push('Sample');
```
The `$breadcrumb->url` value will be `null`.
The default Twitter Bootstrap templates provided render this with a CSS class of "active", the same as the last breadcrumb, because otherwise they default to black text not grey which doesn't look right.
### Custom data
The `push()` method accepts an optional third parameter, `$data` an array of arbitrary data to be passed to the breadcrumb, which you can use in your custom template. For example, if you wanted each breadcrumb to have an icon, you could do:
```php
$breadcrumbs->push('Home', '/', ['icon' => 'home.png']);
```
The `$data` array's entries will be merged into the breadcrumb as properties, so you would access the icon as ``$breadcrumb->icon`` in your template, like this:
```html+php
<li><a href="{{ $breadcrumb->url }}">
<img src="/images/icons/{{ $breadcrumb->icon }}">
{{ $breadcrumb->title }}
</a></li>
```
Do not use the following keys in your data array, as they will be overwritten: `title`, `url`, `first`, `last`.
### Defining breadcrumbs in a different file
If you don't want to use `routes/breadcrumbs.php` (or `app/Http/breadcrumbs.php` in Laravel 5.2 and below), you can create a custom service provider to use instead of `DaveJamesMiller\Breadcrumbs\ServiceProvider` and override the `registerBreadcrumbs()` method:
```php
<?php
namespace App\Providers;
use DaveJamesMiller\Breadcrumbs\ServiceProvider;
class BreadcrumbsServiceProvider extends ServiceProvider
{
public function registerBreadcrumbs()
{
require base_path('path/to/breadcrumbs.php');
}
}
```
If you are creating your own package, simply load them from your service provider's `boot()` method:
```php
class MyServiceProvider extends ServiceProvider
{
public function register() {}
public function boot()
{
if (class_exists('Breadcrumbs'))
require __DIR__ . '/breadcrumbs.php';
}
}
```
### Switching views dynamically
You can change the view at runtime by calling:
```php
Breadcrumbs::setView('view.name');
```
Or you can call `Breadcrumbs::generate()` and then load the view manually:
```html+php
@include('_partials/breadcrumbs2', ['breadcrumbs' => Breadcrumbs::generate('category', $category)])
```
### Overriding the "current" route
If you call `Breadcrumbs::render()` or `Breadcrumbs::generate()` with no parameters, it will use the current route name and parameters by default (as returned by Laravel's `Route::current()` method).
You can override this by calling `Breadcrumbs::setCurrentRoute($name, $param1, $param2...)` or `Breadcrumbs::setCurrentRouteArray($name, $params)`.
### Passing an array of parameters
If the breadcrumb requires multiple parameters, you would normally pass them like this:
```php
Breadcrumbs::render('name', $param1, $param2, $param3);
Breadcrumbs::generate('name', $param1, $param2, $param3);
$breadcrumbs->parent('name', $param1, $param2, $param3);
```
If you want to pass an array of parameters instead you can use these methods:
```php
Breadcrumbs::renderArray('name', $params);
Breadcrumbs::generateArray('name', $params);
$breadcrumbs->parentArray('name', $params);
```
### Checking if a breadcrumb exists
By default an exception will be thrown if the breadcrumb doesn't exist, so you know to add it. If you want suppress this you can call the following methods instead:
- `Breadcrumbs::renderIfExists()` (returns an empty string)
- `Breadcrumbs::renderIfExistsArray()` (returns an empty string) (was `renderArrayIfExists` before 3.0.0)
- `Breadcrumbs::generateIfExists()` (returns an empty array)
- `Breadcrumbs::generateIfExistsArray()` (returns an empty array) (was `generateArrayIfExists` before 3.0.0)
Alternatively you can call `Breadcrumbs::exists('name')`, which returns a boolean.
API Reference
--------------------------------------------------------------------------------
### `Breadcrumbs` Facade
| Method | Returns | Added in |
|------------------------------------------------------|-----------|----------|
| `Breadcrumbs::register($name, $callback)` | *(none)* | 1.0.0 |
| `Breadcrumbs::exists()` | boolean | 2.2.0 |
| `Breadcrumbs::exists($name)` | boolean | 2.2.0 |
| `Breadcrumbs::generate()` | array | 2.2.3 |
| `Breadcrumbs::generate($name)` | array | 1.0.0 |
| `Breadcrumbs::generate($name, $param1, ...)` | array | 1.0.0 |
| `Breadcrumbs::generateArray($name, $params)` | array | 2.0.0 |
| `Breadcrumbs::generateIfExists()` | array | 2.2.0 |
| `Breadcrumbs::generateIfExists($name)` | array | 2.2.0 |
| `Breadcrumbs::generateIfExists($name, $param1, ...)` | array | 2.2.0 |
| `Breadcrumbs::generateIfExistsArray($name, $params)` | array | 3.0.0 |
| `Breadcrumbs::render()` | string | 2.2.0 |
| `Breadcrumbs::render($name)` | string | 1.0.0 |
| `Breadcrumbs::render($name, $param1, ...)` | string | 1.0.0 |
| `Breadcrumbs::renderArray($name, $params)` | string | 2.0.0 |
| `Breadcrumbs::renderIfExists()` | string | 2.2.0 |
| `Breadcrumbs::renderIfExists($name)` | string | 2.2.0 |
| `Breadcrumbs::renderIfExists($name, $param1, ...)` | string | 2.2.0 |
| `Breadcrumbs::renderIfExistsArray($name, $params)` | string | 3.0.0 |
| `Breadcrumbs::setCurrentRoute($name)` | *(none)* | 2.2.0 |
| `Breadcrumbs::setCurrentRoute($name, $param1, ...)` | *(none)* | 2.2.0 |
| `Breadcrumbs::setCurrentRouteArray($name, $params)` | *(none)* | 2.2.0 |
| `Breadcrumbs::clearCurrentRoute()` | *(none)* | 2.2.0 |
| `Breadcrumbs::setView($view)` | *(none)* | 1.0.0 |
[Source](https://github.com/davejamesmiller/laravel-breadcrumbs/blob/develop/src/Manager.php)
### Defining breadcrumbs
```php
Breadcrumbs::register('name', function($breadcrumbs, $page) {
// ...
});
```
| Method | Returns | Added in |
|------------------------------------------------------|-----------|----------|
| `$breadcrumbs->push($title)` | *(none)* | 1.0.0 |
| `$breadcrumbs->push($title, $url)` | *(none)* | 1.0.0 |
| `$breadcrumbs->push($title, $url, $data)` | *(none)* | 2.3.0 |
| `$breadcrumbs->parent($name)` | *(none)* | 1.0.0 |
| `$breadcrumbs->parent($name, $param1, ...)` | *(none)* | 1.0.0 |
| `$breadcrumbs->parentArray($name, $params)` | *(none)* | 2.0.0 |
[Source](https://github.com/davejamesmiller/laravel-breadcrumbs/blob/develop/src/Generator.php)
### In the view (template)
`$breadcrumbs` (array), contains:
| Variable | Type | Added in |
|--------------------------------------|---------------|----------|
| `$breadcrumb->title` | string | 1.0.0 |
| `$breadcrumb->url` | string / null | 1.0.0 |
| `$breadcrumb->first` | boolean | 1.0.0 |
| `$breadcrumb->last` | boolean | 1.0.0 |
| `$breadcrumb->custom_attribute_name` | mixed | 2.3.0 |
Changelog
--------------------------------------------------------------------------------
*Laravel Breadcrumbs uses [Semantic Versioning](http://semver.org/).*
### [v3.0.3](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.3) (24 Jun 2017)
- Fix exception when using `renderIfExists()` (and related methods) with an unnamed route
([#133](https://github.com/davejamesmiller/laravel-breadcrumbs/issues/133))
- Convert docs back to Markdown
### [v3.0.2](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.2) (30 Jan 2017)
- Laravel 5.4 support
### [v3.0.1](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.1) (28 Aug 2016)
- Laravel 5.3 support
#### Upgrading from Laravel 5.2 to 5.3
- Upgrade Laravel Breadcrumbs to 3.0.1 (or above)
- Move `app/Http/breadcrumbs.php` to `routes/breadcrumbs.php` (optional but recommended)
### [v3.0.0](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.0) (8 Feb 2015)
- Add Laravel 5 support
([#62](https://github.com/davejamesmiller/laravel-breadcrumbs/issues/62))
- Change view namespace from `laravel-breadcrumbs::` to `breadcrumbs::`
- Change Bootstrap 3 template from `<ul>` to `<ol>` to match the [documentation](http://getbootstrap.com/components/#breadcrumbs)
- Move documentation from GitHub (Markdown) to [Read The Docs](https://readthedocs.org/) (reStructuredText/[Sphinx](http://sphinx-doc.org/))
- Greatly improve unit & integration tests (largely thanks to [Testbench](https://github.com/orchestral/testbench))
- Fix issue that prevented non-deferred service providers referencing Breadcrumbs by making Breadcrumbs non-deferred also
([#39](https://github.com/davejamesmiller/laravel-breadcrumbs/issues/39))
- Rename `generateArrayIfExists()` to `generateIfExistsArray()`
- Rename `renderArrayIfExists()` to `renderIfExistsArray()`
- Remove `$breadcrumbs->get()` and `$breadcrumbs->set()` methods from Generator class (they were never used nor documented)
- Remove `Breadcrumbs::getView()`
- Switch from PSR-0 to PSR-4 file naming
#### Upgrading from 2.x to 3.x
- [Upgrade to Laravel 5](https://laravel.com/docs/5.0/upgrade#upgrade-5.0)
- Move `app/breadcrumbs.php` to `app/Http/breadcrumbs.php`
- Move `app/config/packages/davejamesmiller/laravel-breadcrumbs/config.php` to `config/breadcrumbs.php` (if used)
The following changes are optional because there are shims in place:
- In the config file, replace `laravel-breadcrumbs::` with `breadcrumbs::`
- Replace any calls to `Breadcrumbs::generateArrayIfExists()` with `Breadcrumbs::generateIfExistsArray()`
- Replace any calls to `Breadcrumbs::renderArrayIfExists()` with `Breadcrumbs::renderIfExistsArray()`
**Note:** Laravel 4 and PHP 5.3 are no longer supported please continue to use the [2.x branch](https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.x) if you use them.
### v2.x
[Changelog for 2.x and below](https://github.com/davejamesmiller/laravel-breadcrumbs/blob/2.x/CHANGELOG.md)
Technical Support
--------------------------------------------------------------------------------
Sorry, **I don't offer free technical support** for my open source packages. If you can't get Laravel Breadcrumbs working in your application, I suggest you try posting a question on [Stack Overflow](https://stackoverflow.com/search?q=laravel+breadcrumbs). For paid support / consultancy please [email me](https://davejamesmiller.com/contact).
Bug Reports
--------------------------------------------------------------------------------
Please note this is free software so **I don't guarantee to fix any bugs** I will investigate if/when I have the time and motivation to do so. Don't be afraid to go into the Laravel Breadcrumbs code (`vendor/davejamesmiller/laravel-breadcrumbs/src/`), use `var_dump()` to see what's happening and fix your own problems! For paid support / consultancy please [email me](https://davejamesmiller.com/contact).
Contributing
--------------------------------------------------------------------------------
**Bug fixes:** Please fix it and open a [pull request](https://github.com/davejamesmiller/laravel-breadcrumbs/pulls). Bonus points if you add a unit test to make sure it doesn't happen again!
**New features:** Only high value features with a clear use case and well-considered API will be accepted. They must be documented and include unit tests. I suggest you open an [issue](https://github.com/davejamesmiller/laravel-breadcrumbs/issues) to discuss the idea first.
**Documentation:** If you think the documentation can be improved in any way, please do [edit this file](https://github.com/davejamesmiller/laravel-breadcrumbs/edit/master/README.md) and make a pull request.
### Developing inside a real application
The easiest way to work on Laravel Breadcrumbs inside a real Laravel application is to tell Composer to install from source (Git) using the `--prefer-source` flag:
```bash
cd /path/to/repo
rm -rf vendor/davejamesmiller/laravel-breadcrumbs
composer install --prefer-source
```
Then:
```bash
cd vendor/davejamesmiller/laravel-breadcrumbs
git checkout -t origin/master
git checkout -b YOUR_BRANCH
# Make changes and commit them
git remote add YOUR_USERNAME git@github.com:YOUR_USERNAME/laravel-breadcrumbs
git push -u YOUR_USERNAME YOUR_BRANCH
```
Alternatively there is a [test app](https://github.com/davejamesmiller/laravel-breadcrumbs-test) that you can use.
### Unit tests
To run the unit tests, simply run:
```bash
cd /path/to/laravel-breadcrumbs
composer update
scripts/test.sh
```
#### Code coverage
To check code coverage, you will also need [Xdebug](https://xdebug.org/) installed. Run:
```bash
scripts/test-coverage.sh
```
Then open `test-coverage/index.html` to view the results. Be aware of the [edge cases](https://phpunit.de/manual/current/en/code-coverage-analysis.html#code-coverage-analysis.edge-cases) in PHPUnit that can make it not-quite-accurate.
### Using your fork in a project
To use your own fork in a project, update the `composer.json` in your main project as follows:
```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/YOUR_USERNAME/laravel-breadcrumbs.git"
}
],
"require": {
"davejamesmiller/laravel-breadcrumbs": "dev-YOUR_BRANCH"
}
}
```
Replace `YOUR_USERNAME` with your GitHub username and `YOUR_BRANCH` with the branch name (e.g. `develop`). This tells Composer to use your repository instead of the default one.
License
--------------------------------------------------------------------------------
*[MIT License](https://choosealicense.com/licenses/mit/)*
**Copyright © 2013-2017 Dave James Miller**
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,82 +0,0 @@
################################################################################
Laravel Breadcrumbs 3
################################################################################
.. |stable| image:: https://poser.pugx.org/davejamesmiller/laravel-breadcrumbs/v/stable.png
:alt: Latest Stable Version
:target: https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs
.. |downloads| image:: https://img.shields.io/packagist/dt/davejamesmiller/laravel-breadcrumbs.svg?style=flat
:alt: Total Downloads
:target: https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs
.. |references| image:: https://www.versioneye.com/php/davejamesmiller:laravel-breadcrumbs/reference_badge.svg?style=flat
:alt: Reference Status
:target: https://www.versioneye.com/php/davejamesmiller:laravel-breadcrumbs/references
.. |build| image:: https://img.shields.io/travis/davejamesmiller/laravel-breadcrumbs/master.svg?style=flat
:alt: Build Status
:target: https://travis-ci.org/davejamesmiller/laravel-breadcrumbs
.. |coverage| image:: https://img.shields.io/coveralls/davejamesmiller/laravel-breadcrumbs.png
:alt: Coverage Status
:target: https://coveralls.io/r/davejamesmiller/laravel-breadcrumbs
.. |dependencies| image:: https://www.versioneye.com/php/davejamesmiller:laravel-breadcrumbs/badge.svg
:alt: Dependency Status
:target: https://www.versioneye.com/php/davejamesmiller:laravel-breadcrumbs
|stable| |downloads| |references|
|build| |coverage| |dependencies|
A simple Laravel-style way to create breadcrumbs in `Laravel 5 <http://laravel.com/>`_.
(If you are still using Laravel 4.0 to 4.2 please use the `2.x version <https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.x>`_ of Laravel Breadcrumbs instead.)
================================================================================
Documentation
================================================================================
`View documentation >> <http://laravel-breadcrumbs.davejamesmiller.com/>`_
**Note:** If you have any suggestions for improving the documentation -- especially if anything is unclear to you and could be explained better -- please let me know. (Or just edit it yourself and make a pull request.)
================================================================================
Support Requests / Bug Reports
================================================================================
All support requests / bug reports should be submitted using `GitHub issues <https://github.com/davejamesmiller/laravel-breadcrumbs/issues>`_, and **must** include the following:
- The complete error message, including file & line numbers
- Steps to reproduce the problem
- Laravel Breadcrumbs version
- Laravel version
- PHP version
- Copies of the following files (you can use `Gist <https://gist.github.com/>`_ if they're very long):
- ``routes/breadcrumbs.php`` or ``app/Http/breadcrumbs.php``
- ``config/breadcrumbs.php`` (if used)
- The view and/or layout files
- The custom breadcrumbs template (if applicable)
- ``config/app.php``
- Any other relevant files
Before you do - please don't be afraid to go into the Laravel Breadcrumbs code (``vendor/davejamesmiller/laravel-breadcrumbs/src/``) and use ``var_dump()`` (or ``dd()`` or ``print_r()``) to see what's happening and try to fix your own problems! A pull request or detailed bug report is much more likely to get attention than a vague error report. Also make sure you read the `documentation <http://laravel-breadcrumbs.davejamesmiller.com/en/latest/>`_ carefully.
================================================================================
Feature Requests / Pull Requests
================================================================================
.. NOTE: This text is also in docs/contributing.rst
Any feature requests / pull requests should include details of what you are trying to achieve (use case) to explain why your request should be implemented.
If you want to submit a **bug fix**, please make your changes in a new branch, then open a `pull request <https://github.com/davejamesmiller/laravel-breadcrumbs/pulls>`_. (The `Contributing page of the docs <http://laravel-breadcrumbs.davejamesmiller.com/en/latest/contributing.html>`_ may help you to get started if you've not done this before.)
If you want to submit a **new feature**, it's usually best to open an `issue <https://github.com/davejamesmiller/laravel-breadcrumbs/issues>`_ to discuss the idea first -- to make sure it will be accepted before spending too much time on it. (Of course you can go ahead and develop it first if you prefer!) Please be sure to include unit tests and update the documentation as well.
For more details see the `Contributing <http://laravel-breadcrumbs.davejamesmiller.com/en/latest/contributing.html>`_ section of the documentation.
--------------------------------------------------------------------------------
Copyright © 2013-2015 Dave James Miller. Released under the `MIT License <docs/license.rst>`_.

View File

@@ -1,8 +1,7 @@
# Release Checklist
- [ ] Ensure the documentation is up to date, particularly the changelog
- [ ] Merge the `develop` branch into the `master` branch (`git checkout master; git merge develop`)
- [ ] Merge the changes into the `master` branch (if necessary)
- [ ] Push the code changes to GitHub (`git push`)
- [ ] Double-check the [Travis CI results](https://travis-ci.org/davejamesmiller/laravel-breadcrumbs)
- [ ] Tag the release (`git tag 1.2.3`)
- [ ] Push the tag (`git push --tag`)

View File

@@ -1,7 +0,0 @@
#!/bin/bash
set -eu
cd $(dirname $0)
rm -rf docs-html/
sphinx-build docs/ docs-html/
sphinx-autobuild -H 0.0.0.0 docs/ docs-html/

View File

@@ -1,7 +0,0 @@
#!/bin/bash
set -eu
cd $(dirname $0)
rm -rf docs-pdf/
sphinx-build -b latex docs/ docs-pdf/
make -C docs-pdf/ all-pdf

View File

@@ -1,15 +1,15 @@
{
"name": "davejamesmiller/laravel-breadcrumbs",
"description": "A simple Laravel-style way to create breadcrumbs in Laravel 4+.",
"description": "A simple Laravel-style way to create breadcrumbs in Laravel.",
"keywords": [
"laravel"
],
"homepage": "http://laravel-breadcrumbs.davejamesmiller.com",
"homepage": "https://laravel-breadcrumbs.readthedocs.io/",
"authors": [
{
"name": "Dave James Miller",
"email": "dave@davejamesmiller.com",
"homepage": "http://davejamesmiller.com/"
"homepage": "https://davejamesmiller.com/"
}
],
"license": "MIT License",
@@ -21,8 +21,7 @@
"require-dev": {
"mockery/mockery": "0.9.*",
"orchestra/testbench": "3.2.*|3.3.*",
"phpunit/phpunit": "4.*",
"satooshi/php-coveralls": "0.6.*"
"phpunit/phpunit": "4.*"
},
"autoload": {
"psr-4": {

View File

@@ -1,6 +0,0 @@
# 4 space indents in ReST because that's what we want for most code examples
# and if we use tabs it defaults to 8 (and isn't easy to change)
# http://stackoverflow.com/questions/1686837
[*]
indent_size = 4
indent_style = space

View File

@@ -1,26 +0,0 @@
/* Make sections stand out more */
h2 {
border-top: 1px solid #e1e4e5;
padding-top: 24px;
}
h1 + .section > h2:first-child {
border-top: none;
padding-top: 0;
}
/* Changelog styles */
.changelog-date {
font-size: 70%;
}
.changelog-future {
color: #b65a5a;
font-size: 70%;
font-style: italic;
font-weight: bold;
}
.strikethrough {
text-decoration: line-through;
}

View File

@@ -1,164 +0,0 @@
################################################################################
Advanced Usage
################################################################################
.. only:: html
.. contents::
:local:
.. _no-url:
================================================================================
Breadcrumbs with no URL
================================================================================
The second parameter to ``push()`` is optional, so if you want a breadcrumb with no URL you can do so:
.. code-block:: php
$breadcrumbs->push('Sample');
The ``$breadcrumb->url`` value will be ``null``.
The default Twitter Bootstrap templates provided render this with a CSS class of "active", the same as the last breadcrumb, because otherwise they default to black text not grey which doesn't look right.
*Note: Support for this was added to the Twitter Bootstrap templates in 2.1.0. Before this you would need to create a custom template.*
.. _custom-data:
================================================================================
Custom data
================================================================================
*Added in 2.3.0.*
The ``push()`` method accepts an optional third parameter, ``$data`` - an array of arbitrary data to be passed to the breadcrumb, which you can use in your custom template. For example, if you wanted each breadcrumb to have an icon, you could do:
.. code-block:: php
$breadcrumbs->push('Home', '/', ['icon' => 'home.png']);
The ``$data`` array's entries will be merged into the breadcrumb as properties, so you would access the icon as ``$breadcrumb->icon`` in your template, like this:
.. code-block:: html+php
<li><a href="{{ $breadcrumb->url }}">
<img src="/images/icons/{{ $breadcrumb->icon }}">
{{ $breadcrumb->title }}
</a></li>
Do not use the following keys in your data array, as they will be overwritten: ``title``, ``url``, ``first``, ``last``.
================================================================================
Defining breadcrumbs in a different file
================================================================================
If you don't want to use ``routes/breadcrumbs.php`` (or ``app/Http/breadcrumbs.php`` in Laravel 5.2 and below), you can create a custom service provider to use instead of ``DaveJamesMiller\Breadcrumbs\ServiceProvider`` and override the ``registerBreadcrumbs()`` method:
.. code-block:: php
<?php
namespace App\Providers;
use DaveJamesMiller\Breadcrumbs\ServiceProvider;
class BreadcrumbsServiceProvider extends ServiceProvider
{
public function registerBreadcrumbs()
{
require base_path('path/to/breadcrumbs.php');
}
}
If you are creating your own package, simply load them from your service provider's ``boot()`` method:
.. code-block:: php
class MyServiceProvider extends ServiceProvider
{
public function register() {}
public function boot()
{
if (class_exists('Breadcrumbs'))
require __DIR__ . '/breadcrumbs.php';
}
}
.. _switching-views:
================================================================================
Switching views dynamically
================================================================================
You can change the view at runtime by calling:
.. code-block:: php
Breadcrumbs::setView('view.name');
Or you can call ``Breadcrumbs::generate()`` and then load the view manually:
.. code-block:: html+php
@include('_partials/breadcrumbs2', ['breadcrumbs' => Breadcrumbs::generate('category', $category)])
.. _current-route:
================================================================================
Overriding the "current" route
================================================================================
If you call ``Breadcrumbs::render()`` or ``Breadcrumbs::generate()`` with no parameters, it will use the current route name and parameters by default (as returned by Laravel's ``Route::current()`` method).
You can override this by calling ``Breadcrumbs::setCurrentRoute($name, $param1, $param2...)`` or ``Breadcrumbs::setCurrentRouteArray($name, $params)``.
.. _array-parameters:
================================================================================
Passing an array of parameters
================================================================================
*Added in 2.0.0.*
If the breadcrumb requires multiple parameters, you would normally pass them like this:
.. code-block:: php
Breadcrumbs::render('name', $param1, $param2, $param3);
Breadcrumbs::generate('name', $param1, $param2, $param3);
$breadcrumbs->parent('name', $param1, $param2, $param3);
If you want to pass an array of parameters instead you can use these methods:
.. code-block:: php
Breadcrumbs::renderArray('name', $params);
Breadcrumbs::generateArray('name', $params);
$breadcrumbs->parentArray('name', $params);
.. _exists:
================================================================================
Checking if a breadcrumb exists
================================================================================
*Added in 2.2.0.*
By default an exception will be thrown if the breadcrumb doesn't exist, so you know to add it. If you want suppress this you can call the following methods instead:
- ``Breadcrumbs::renderIfExists()`` (returns an empty string)
- ``Breadcrumbs::renderIfExistsArray()`` (returns an empty string) (was ``renderArrayIfExists`` before 3.0.0)
- ``Breadcrumbs::generateIfExists()`` (returns an empty array)
- ``Breadcrumbs::generateIfExistsArray()`` (returns an empty array) (was ``generateArrayIfExists`` before 3.0.0)
Alternatively you can call ``Breadcrumbs::exists('name')``, which returns a boolean.

View File

@@ -1,86 +0,0 @@
################################################################################
API Reference
################################################################################
.. only:: html
.. contents::
:local:
================================================================================
``Breadcrumbs`` Facade
================================================================================
======================================================== ========== ========== ============================
Method Returns Added in Docs
======================================================== ========== ========== ============================
``Breadcrumbs::register($name, $callback)`` *(none)* 1.0.0 :doc:`Defining <defining>`
``Breadcrumbs::exists()`` boolean 2.2.0 :doc:`Route-bound <routing>`
``Breadcrumbs::exists($name)`` boolean 2.2.0 :ref:`Exists <exists>`
``Breadcrumbs::generate()`` array 2.2.3 :doc:`Route-bound <routing>`
``Breadcrumbs::generate($name)`` array 1.0.0 :ref:`Switching views <switching-views>`
``Breadcrumbs::generate($name, $param1, ...)`` array 1.0.0 :ref:`Switching views <switching-views>`
``Breadcrumbs::generateArray($name, $params)`` array 2.0.0 :ref:`Array params <array-parameters>`
``Breadcrumbs::generateIfExists()`` array 2.2.0 :doc:`Route-bound <routing>`
``Breadcrumbs::generateIfExists($name)`` array 2.2.0 :ref:`Exists <exists>`
``Breadcrumbs::generateIfExists($name, $param1, ...)`` array 2.2.0 :ref:`Exists <exists>`
``Breadcrumbs::generateIfExistsArray($name, $params)`` array 3.0.0 :ref:`Exists <exists>`
``Breadcrumbs::render()`` string 2.2.0 :doc:`Route-bound <routing>`
``Breadcrumbs::render($name)`` string 1.0.0 :doc:`Output <output>`
``Breadcrumbs::render($name, $param1, ...)`` string 1.0.0 :doc:`Output <output>`
``Breadcrumbs::renderArray($name, $params)`` string 2.0.0 :ref:`Array params <array-parameters>`
``Breadcrumbs::renderIfExists()`` string 2.2.0 :doc:`Route-bound <routing>`
``Breadcrumbs::renderIfExists($name)`` string 2.2.0 :ref:`Exists <exists>`
``Breadcrumbs::renderIfExists($name, $param1, ...)`` string 2.2.0 :ref:`Exists <exists>`
``Breadcrumbs::renderIfExistsArray($name, $params)`` string 3.0.0 :ref:`Exists <exists>`
``Breadcrumbs::setCurrentRoute($name)`` *(none)* 2.2.0 :ref:`Current route <current-route>`
``Breadcrumbs::setCurrentRoute($name, $param1, ...)`` *(none)* 2.2.0 :ref:`Current route <current-route>`
``Breadcrumbs::setCurrentRouteArray($name, $params)`` *(none)* 2.2.0 :ref:`Current route <current-route>`
``Breadcrumbs::clearCurrentRoute()`` *(none)* 2.2.0
``Breadcrumbs::setView($view)`` *(none)* 1.0.0 :ref:`Switching views <switching-views>`
======================================================== ========== ========== ============================
`Source <https://github.com/davejamesmiller/laravel-breadcrumbs/blob/develop/src/Manager.php>`__
================================================================================
Defining breadcrumbs
================================================================================
.. code-block:: php
Breadcrumbs::register('name', function($breadcrumbs, $page) {
// ...
});
======================================================== ========== ========== ============================
Method Returns Added in Docs
======================================================== ========== ========== ============================
``$breadcrumbs->push($title)`` *(none)* 1.0.0 :ref:`No URL <no-url>`
``$breadcrumbs->push($title, $url)`` *(none)* 1.0.0 :doc:`Defining <defining>`
``$breadcrumbs->push($title, $url, $data)`` *(none)* 2.3.0 :ref:`Custom data <custom-data>`
``$breadcrumbs->parent($name)`` *(none)* 1.0.0 :ref:`Parent links <defining-parents>`
``$breadcrumbs->parent($name, $param1, ...)`` *(none)* 1.0.0 :ref:`Parent links <defining-parents>`
``$breadcrumbs->parentArray($name, $params)`` *(none)* 2.0.0 :ref:`Array parameters <array-parameters>`
======================================================== ========== ========== ============================
`Source <https://github.com/davejamesmiller/laravel-breadcrumbs/blob/develop/src/Generator.php>`__
================================================================================
In the view (template)
================================================================================
``$breadcrumbs`` (array), contains:
======================================================== ================ ========== ============================
Variable Type Added in Docs
======================================================== ================ ========== ============================
``$breadcrumb->title`` string 1.0.0 :ref:`View data <view-data>`
``$breadcrumb->url`` string or null 1.0.0 :ref:`View data <view-data>`
``$breadcrumb->first`` boolean 1.0.0 :ref:`View data <view-data>`
``$breadcrumb->last`` boolean 1.0.0 :ref:`View data <view-data>`
``$breadcrumb->custom_attribute_name`` mixed 2.3.0 :ref:`Custom data <custom-data>`
======================================================== ================ ========== ============================

View File

@@ -1,254 +0,0 @@
################################################################################
Changelog
################################################################################
.. role:: date
:class: changelog-date
.. role:: future
:class: changelog-future
.. role:: strikethrough
:class: strikethrough
Laravel Breadcrumbs uses `Semantic Versioning <http://semver.org/>`_.
.. ================================================================================
.. v3.0.1_ :future:`(Unreleased)`
.. ================================================================================
================================================================================
v3.0.1_ :date:`(28 Aug 2016)`
================================================================================
- Laravel 5.3 support
.. _v3.0.1: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.1
----------------------------------------
Upgrading from Laravel 5.2 to 5.3
----------------------------------------
- Upgrade Laravel Breadcrumbs to 3.0.1 (or above)
- Move ``app/Http/breadcrumbs.php`` to ``routes/breadcrumbs.php`` (optional but recommended)
================================================================================
v3.0.0_ :date:`(8 Feb 2015)`
================================================================================
- Add Laravel 5 support (`#62`_)
- Change view namespace from ``laravel-breadcrumbs::`` to ``breadcrumbs::``
- Change Bootstrap 3 template from ``<ul>`` to ``<ol>`` to match the `documentation <http://getbootstrap.com/components/#breadcrumbs>`_
- Move documentation from GitHub (Markdown) to `Read The Docs <https://readthedocs.org/>`_ (reStructuredText/`Sphinx <http://sphinx-doc.org/>`_)
- Greatly improve unit & integration tests (largely thanks to `Testbench <https://github.com/orchestral/testbench>`_)
- Fix issue that prevented non-deferred service providers referencing Breadcrumbs (`#39`_) by making Breadcrumbs non-deferred also
- Rename ``generateArrayIfExists()`` to ``generateIfExistsArray()``
- Rename ``renderArrayIfExists()`` to ``renderIfExistsArray()``
- Remove ``$breadcrumbs->get()`` and ``$breadcrumbs->set()`` methods from Generator class (they were never used nor documented)
- Remove ``Breadcrumbs::getView()``
- Switch from PSR-0 to PSR-4 file naming
.. _v3.0.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.0
.. _#39: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/39
.. _#62: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/62
----------------------------------------
Upgrading from 2.x to 3.x
----------------------------------------
- `Upgrade to Laravel 5 <http://laravel.com/docs/5.0/upgrade#upgrade-5.0>`_
- Move ``app/breadcrumbs.php`` to ``app/Http/breadcrumbs.php``
- Move ``app/config/packages/davejamesmiller/laravel-breadcrumbs/config.php`` to ``config/breadcrumbs.php`` (if used)
The following changes are optional because there are shims in place:
- In the config file, replace ``laravel-breadcrumbs::`` with ``breadcrumbs::``
- Replace any calls to ``Breadcrumbs::generateArrayIfExists()`` with ``Breadcrumbs::generateIfExistsArray()``
- Replace any calls to ``Breadcrumbs::renderArrayIfExists()`` with ``Breadcrumbs::renderIfExistsArray()``
.. note::
Laravel 4 and PHP 5.3 are no longer supported -- please continue to use the `2.x branch <https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.x>`_ if you use them.
================================================================================
v2.3.1_ :date:`(8 Feb 2015)`
================================================================================
- Fix issue that prevented non-deferred service providers referencing Breadcrumbs (`#39`_) by making Breadcrumbs non-deferred also (backported from 3.0.0)
.. _v2.3.1: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/3.0.0
================================================================================
v2.3.0_ :date:`(26 Oct 2014)`
================================================================================
- Add ``$data`` parameter to ``$breadcrumb->push()`` to allow for arbitrary data (`#34`_, `#35`_, `#55`_, `#56`_)
.. _v2.3.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.3.0
.. _#34: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/34
.. _#35: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/35
.. _#55: https://github.com/davejamesmiller/laravel-breadcrumbs/pull/55
.. _#56: https://github.com/davejamesmiller/laravel-breadcrumbs/pull/56
.. _3a0afc2: https://github.com/laravel/framework/commit/3a0afc20f25ad3bed640ff1a14957f972d123cf7
================================================================================
v2.2.3_ :date:`(10 Sep 2014)`
================================================================================
- Fix ``Breadcrumbs::generate()`` with no parameters so it uses the current route, like ``Breadcrumbs::render()`` does (`#46`_)
.. _v2.2.3: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.2.3
.. _#46: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/46
================================================================================
v2.2.2_ :date:`(3 Aug 2014)`
================================================================================
- Support for Laravel's ``App::missing()`` method when using automatic route detection (`#40`_, `#41`_)
.. _v2.2.2: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.2.2
.. _#40: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/40
.. _#41: https://github.com/davejamesmiller/laravel-breadcrumbs/pull/41
================================================================================
v2.2.1_ :date:`(19 May 2014)`
================================================================================
- Laravel 4.2 support (`#21`_, `#28`_)
.. _v2.2.1: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.2.1
.. _#21: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/21
.. _#28: https://github.com/davejamesmiller/laravel-breadcrumbs/pull/28
================================================================================
v2.2.0_ :date:`(26 Jan 2014)`
================================================================================
- Add ``Breadcrumbs::exists()``, ``renderIfExists()``, ``renderArrayIfExists()`` (`#22`_)
- Use the current route name & parameters by default so you don't have to specify them in the view (as long as you use consistent names) (`#16`_, `#24`_)
.. _v2.2.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.2.0
.. _#16: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/16
.. _#22: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/22
.. _#24: https://github.com/davejamesmiller/laravel-breadcrumbs/pull/24
================================================================================
v2.1.0_ :date:`(16 Oct 2013)`
================================================================================
- Add support for non-linked breadcrumbs to the Twitter Bootstrap templates (`#20`_)
.. _v2.1.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.1.0
.. _#20: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/20
================================================================================
v2.0.0_ :date:`(28 Sep 2013)`
================================================================================
- Add Twitter Bootstrap v3 template (`#7`_)
- Twitter Bootstrap v3 is now the default template
- Support for passing arrays into ``render()``, ``generate()`` and ``parent()`` (**not backwards-compatible**) (`#8`_)
- Split ``Breadcrumbs::render()`` into ``render($name, $arg1, $arg2)`` and ``renderArray($name, $params)``
- Split ``Breadcrumbs::generate()`` into ``generate($name, $arg1, $arg2)`` and ``generateArray($name, $params)``
- Split ``$breadcrumbs->parent()`` into ``parent($name, $arg1, $arg2)`` and ``parentArray($name, $params)``
- Set view name in config file instead of in ``breadcrumbs.php`` (`#10`_, `#11`_)
- Simplify class names (`#15`_)
- Add unit tests
.. _v2.0.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.0.0
.. _#7: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/7
.. _#8: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/8
.. _#10: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/10
.. _#11: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/11
.. _#15: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/15
----------------------------------------
Upgrading from 1.x to 2.x
----------------------------------------
- In ``app/config/app.php`` change ``DaveJamesMiller\Breadcrumbs\BreadcrumbsServiceProvider`` to ``DaveJamesMiller\Breadcrumbs\ServiceProvider``
- In ``app/config/app.php`` change ``DaveJamesMiller\Breadcrumbs\Facades\Breadcrumbs`` to ``DaveJamesMiller\Breadcrumbs\Facade``
- The default template was changed from Bootstrap 2 to Bootstrap 3. See :ref:`Choose a template <choose-template>` if you need to switch it back.
The following internal changes will not affect most people but if you have any problems please be aware of the following:
- The view namespace was changed from ``breadcrumbs`` to ``laravel-breadcrumbs`` to match the Composer project name.
- The Bootstrap 2 template name was changed from ``breadcrumbs::bootstrap`` to ``laravel-breadcrumbs::bootstrap2``.
- If you pass arrays into any of the methods, please read the following section:
Passing arrays into ``render()``, ``generate()`` and ``parent()``
.................................................................
In **version 1.x** you could pass an array into each of these methods and it was split up into several parameters. For example:
.. code-block:: php
// If this breadcrumb is defined:
Breadcrumbs::register('page', function($breadcrumbs, $param1, $param2)
{
$breadcrumbs->push($param1, $param2);
});
// Then this:
Breadcrumbs::render('page', ['param1', 'param2']);
// Was equivalent to this:
Breadcrumbs::render('page', 'param1', 'param2');
// But to pass an array as the first parameter you would have to do this instead:
Breadcrumbs::render('page', [['param1A', 'param1B']]);
This means you couldn't pass an array as the first parameter unless you wrapped all parameters in another array (issue `#8`_).
In **version 2.x** this has been split into two methods:
.. code-block:: php
// Now this:
Breadcrumbs::renderArray('page', ['param1', 'param2']);
// Is equivalent to this:
Breadcrumbs::render('page', 'param1', 'param2');
// And this only passes a single parameter (an array) to the callback:
Breadcrumbs::render('page', ['param1A', 'param1B']);
Similarly ``Breadcrumbs::generateArray()`` and ``$breadcrumbs->parentArray()`` methods are available, which take a single array argument.
================================================================================
v1.0.1_ :date:`(13 Jul 2013)`
================================================================================
- Fix for PHP 5.3 compatibility (`#3`_)
.. _v1.0.1: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/1.0.1
.. _#3: https://github.com/davejamesmiller/laravel-breadcrumbs/issues/3
================================================================================
v1.0.0_ :date:`(25 May 2013)`
================================================================================
.. _v1.0.0: https://github.com/davejamesmiller/laravel-breadcrumbs/tree/1.0.0
- Initial release

View File

@@ -1,314 +0,0 @@
# -*- coding: utf-8 -*-
#
# Laravel Breadcrumbs documentation build configuration file, created by
# sphinx-quickstart on Sat Nov 8 11:14:26 2014.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
import json
# Custom imports
import re
from datetime import date
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.todo',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = []
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Laravel Breadcrumbs'
copyright = u'2013-%d, Dave James Miller' % date.today().year
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
with open('changelog.rst', 'r') as changelog:
# Determine the version number from the changelog so I don't have to update
# it in two places
match = re.search(r'^ v((\d+)\.\d+\.\d+)_ :(date|future):', changelog.read(), re.MULTILINE)
# The short X.Y version.
version = match.group(2)
# The full version, including alpha/beta/rc tags.
release = match.group(1)
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%-d %B %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'LaravelBreadcrumbsdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
'preamble': '\n'.join((
# Fix the unicode characters in the file tree diagrams
r'\DeclareUnicodeCharacter{251C}{+}', # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
r'\DeclareUnicodeCharacter{2514}{+}', # BOX DRAWINGS LIGHT UP AND RIGHT
r'\DeclareUnicodeCharacter{00A0}{ }', # NO-BREAK SPACE
# Fix "! Undefined control sequence. <argument> \node@class@name" error when using ".. role"
# Based on https://bitbucket.org/birkenfeld/sphinx/issue/1564/custom-roles-are-not-properly-translated
# (I couldn't get the patches suggested in that issue to work either!)
r'\renewcommand{\DUspan}[2]{#2}',
)),
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'laravel-breadcrumbs.tex', u'Laravel Breadcrumbs Documentation',
u'Dave James Miller', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
latex_show_pagerefs = True
# If true, show URL addresses after external links.
latex_show_urls = 'footnote'
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'laravel-breadcrumbs', u'Laravel Breadcrumbs Documentation',
[u'Dave James Miller'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'laravel-breadcrumbs', u'Laravel Breadcrumbs Documentation',
u'Dave James Miller', 'Laravel Breadcrumbs', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
# -- Custom options -------------------------------------------------------
# Default to plain text blocks
highlight_language = 'none'
# Custom CSS
html_static_path = ['_static']
def setup(app):
app.add_stylesheet('custom.css')
# Only when run locally (not on Read The Docs):
if os.environ.get('READTHEDOCS', None) != 'True':
# Read The Docs theme
# http://read-the-docs.readthedocs.org/en/latest/theme.html
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# Show TODO items
todo_include_todos = True
# Show a link to the online docs in the index page
tags.add('local')
# Enable highlighting for PHP code not between ``<?php ... ?>`` by default
# https://github.com/fabpot/sphinx-php
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
lexers['php'] = PhpLexer(startinline=True)
lexers['php-annotations'] = PhpLexer(startinline=True)

View File

@@ -1,184 +0,0 @@
################################################################################
Contributing
################################################################################
.. NOTE: This text is also in ../README.rst
If you want to submit a **bug fix**, please make your changes in a new branch, then open a `pull request <https://github.com/davejamesmiller/laravel-breadcrumbs/pulls>`_. (The `Contributing page of the docs <http://laravel-breadcrumbs.davejamesmiller.com/en/latest/contributing.html>`_ may help you to get started if you've not done this before.)
If you want to submit a **new feature**, it's usually best to open an `issue <https://github.com/davejamesmiller/laravel-breadcrumbs/issues>`_ to discuss the idea first -- to make sure it will be accepted before spending too much time on it. (Of course you can go ahead and develop it first if you prefer!) Please be sure to include unit tests and update the documentation as well.
If you have any suggestions for improving the **documentation** -- especially if anything is unclear to you and could be explained better -- please let me know. (Or just edit it yourself and make a pull request.)
.. only:: html
.. contents::
:local:
================================================================================
Developing inside a real application
================================================================================
The easiest way to develop Laravel Breadcrumbs alongside a real Laravel application is to set it up as normal, but tell Composer to install from source with the ``--prefer-source`` flag.
If you've already got it installed, delete it from the ``vendor/`` directory and re-install from source:
.. code-block:: bash
$ cd /path/to/repo
$ rm -rf vendor/davejamesmiller/laravel-breadcrumbs
$ composer install --prefer-source
$ cd vendor/davejamesmiller/laravel-breadcrumbs
$ git checkout -t origin/master
$ git checkout -b YOUR_BRANCH
# Make changes and commit them
$ git remote add YOUR_USERNAME git@github.com:YOUR_USERNAME/laravel-breadcrumbs
$ git push -u YOUR_USERNAME YOUR_BRANCH
There is also a `test app <https://github.com/davejamesmiller/laravel-breadcrumbs-test>`_ available to simplify testing against multiple versions of Laravel.
.. note::
The test app is not a replacement for unit tests - we have those too - but it gives a better feel for how the package works in practice.
================================================================================
Using your fork in a project
================================================================================
If you have forked the package (e.g. to fix a bug or add a feature), you may want to use that version in your project until the changes are merged and released. To do that, simply update the ``composer.json`` in your main project as follows:
.. code-block:: json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/YOUR_USERNAME/laravel-breadcrumbs.git"
}
],
"require": {
"davejamesmiller/laravel-breadcrumbs": "dev-YOUR_BRANCH"
}
}
Replace ``YOUR_USERNAME`` with your GitHub username and ``YOUR_BRANCH`` with the branch name (e.g. ``develop``). This tells Composer to use your repository instead of the default one.
================================================================================
Unit tests
================================================================================
To run the unit tests, simply run:
.. code-block:: bash
$ cd /path/to/laravel-breadcrumbs
$ composer update
$ ./test.sh
(Note: The unit tests are not 100% complete yet, and the code will probably need some refactoring to make it easier to test.)
----------------------------------------
Code coverage
----------------------------------------
To check code coverage, you will also need `Xdebug <http://xdebug.org/>`_ installed. Run:
.. code-block:: bash
$ ./test-coverage.sh
Then open ``test-coverage/index.html`` to view the results. (However, be aware of the `edge cases <https://phpunit.de/manual/current/en/code-coverage-analysis.html#code-coverage-analysis.edge-cases>`_ in PHPUnit that can make it not-quite-accurate.)
.. _contributing-documentation:
================================================================================
Documentation
================================================================================
Documentation is in ``docs/``. It is written in `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ and converted to HTML and PDF formats by `Sphinx <http://sphinx-doc.org/>`_.
To submit a documentation change, simply `edit the appropriate file on GitHub <https://github.com/alberon/awe/tree/master/docs>`_. (There's an "Edit on GitHub" link in the top-right corner of each page.)
.. warning::
Not all markup is supported by GitHub -- e.g. ``:ref:`` and ``:doc:`` -- so the preview may not be exactly what appears in the online documentation.
For more comprehensive documentation changes you may be better installing Sphinx so you can test the docs locally:
----------------------------------------
Installing Sphinx
----------------------------------------
You will need `Python <https://www.python.org/>`_ and `pip <https://pypi.python.org/pypi/pip>`_ to install `Sphinx <http://sphinx-doc.org/>`_, the documentation generator. To install them (on Debian Wheezy or similar), you can run the following:
.. code-block:: bash
$ sudo apt-get install python python-pip
$ sudo pip install sphinx sphinx-autobuild sphinx_rtd_theme
To build the PDF documentation, you will also need LaTeX installed:
.. code-block:: bash
$ sudo apt-get install texlive texlive-latex-extra
----------------------------------------
Building documentation
----------------------------------------
To build the HTML docs (``docs-html/index.html``):
.. code-block:: bash
$ ./build-html-docs.sh
This will build the docs and run a HTML server on port 8000 that will automatically rebuild the docs and reload the page whenever you modify a file.
To build the PDF docs (``docs-pdf/laravel-breadcrumbs.pdf``):
.. code-block:: bash
$ ./build-pdf-docs.sh
----------------------------------------
Sphinx markup reference
----------------------------------------
I found the following documents useful when writing the documentation:
- `reStructuredText quick reference <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_
- `Admonitions list <http://docutils.sourceforge.net/docs/ref/rst/directives.html#admonitions>`_ (``note::``, ``warning::``, etc.)
- `Code examples markups <http://sphinx-doc.org/markup/code.html>`_ (``code-block::``, ``highlight::``)
- `Other paragraph-level markup <http://sphinx-doc.org/markup/para.html>`_ (``versionadded::``, ``deprecated::``, etc.)
- `Inline markup <http://sphinx-doc.org/markup/inline.html>`_ (``:ref:``, ``:doc:``, etc.)
- `Table of contents <http://sphinx-doc.org/markup/toctree.html>`_ (``toctree::``)
----------------------------------------
Heading styles
----------------------------------------
The following code styles are used for headings::
################################################################################
Page title (80 hashes)
################################################################################
================================================================================
Section title (80 equals signs)
================================================================================
----------------------------------------
Heading 2 (40 hypens)
----------------------------------------
Heading 3 (full stops)
......................

View File

@@ -1,165 +0,0 @@
################################################################################
Defining Breadcrumbs
################################################################################
Breadcrumbs will usually correspond to actions or types of page. For each breadcrumb you specify a name, the breadcrumb title and the URL to link it to. Since these are likely to change dynamically, you do this in a closure, and you pass any variables you need into the closure.
The following examples should make it clear:
.. only:: html
.. contents::
:local:
================================================================================
Static pages
================================================================================
The most simple breadcrumb is probably going to be your homepage, which will look something like this:
.. code-block:: php
Breadcrumbs::register('home', function($breadcrumbs) {
$breadcrumbs->push('Home', route('home'));
});
As you can see, you simply call ``$breadcrumbs->push($title, $url)`` inside the closure.
For generating the URL, you can use any of the standard Laravel URL-generation methods, including:
- ``url('path/to/route')`` (``URL::to()``)
- ``secure_url('path/to/route')``
- ``route('routename')`` or ``route('routename', 'param')`` or ``route('routename', ['param1', 'param2'])`` (``URL::route()``)
- ``action('controller@action')`` (``URL::action()``)
- Or just pass a string URL (``'http://www.example.com/'``)
This example would be rendered like this:
.. raw:: html
<div class="highlight"><pre>
Home
</pre></div>
.. only:: not html
::
Home
.. _defining-parents:
================================================================================
Parent links
================================================================================
This is another static page, but this has a parent link before it:
.. code-block:: php
Breadcrumbs::register('blog', function($breadcrumbs) {
$breadcrumbs->parent('home');
$breadcrumbs->push('Blog', route('blog'));
});
It works by calling the closure for the ``home`` breadcrumb defined above.
It would be rendered like this:
.. raw:: html
<div class="highlight"><pre>
<a href="#">Home</a> / Blog
</pre></div>
.. only:: not html
::
Home > Blog
Note that the default template does not create a link for the last breadcrumb (the one for the current page), even when a URL is specified. You can override this by creating your own template - see :doc:`templates` for more details.
================================================================================
Dynamic titles and links
================================================================================
This is a dynamically generated page pulled from the database:
.. code-block:: php
Breadcrumbs::register('page', function($breadcrumbs, $page) {
$breadcrumbs->parent('blog');
$breadcrumbs->push($page->title, route('page', $page->id));
});
The ``$page`` variable would simply be passed in from the view:
.. code-block:: html+php
{!! Breadcrumbs::render('page', $page) !!}
It would be rendered like this:
.. raw:: html
<div class="highlight"><pre>
<a href="#">Home</a> / <a href="#">Blog</a> / Page Title
</pre></div>
.. only:: not html
::
Home > Blog > Page Title
**Tip:** You can pass multiple parameters if necessary.
================================================================================
Nested categories
================================================================================
Finally if you have nested categories or other special requirements, you can call ``$breadcrumbs->push()`` multiple times:
.. code-block:: php
Breadcrumbs::register('category', function($breadcrumbs, $category) {
$breadcrumbs->parent('blog');
foreach ($category->ancestors as $ancestor) {
$breadcrumbs->push($ancestor->title, route('category', $ancestor->id));
}
$breadcrumbs->push($category->title, route('category', $category->id));
});
Alternatively you could make a recursive function such as this:
.. code-block:: php
Breadcrumbs::register('category', function($breadcrumbs, $category) {
if ($category->parent)
$breadcrumbs->parent('category', $category->parent);
else
$breadcrumbs->parent('blog');
$breadcrumbs->push($category->title, route('category', $category->slug));
});
Both would be rendered like this:
.. raw:: html
<div class="highlight"><pre>
<a href="#">Home</a> / <a href="#">Blog</a> / <a href="#">Grandparent Category</a> / <a href="#">Parent Category</a> / Category Title
</pre></div>
.. only:: not html
::
Home > Blog > Grandparent Category > Parent Category > Category Title

View File

@@ -1,37 +0,0 @@
################################################################################
Laravel Breadcrumbs 3
################################################################################
.. Link to the online documentation
.. only:: local and html
.. admonition:: Local Documentation
:class: warning
`Read the documentation online >> <http://laravel-breadcrumbs.davejamesmiller.com/>`_
.. Introduction
A simple Laravel-style way to create breadcrumbs in `Laravel 5 <http://laravel.com/>`_.
================================================================================
Table of Contents
================================================================================
.. toctree::
start
defining
templates
output
routing
advanced
api
contributing
changelog
thanks
license
» GitHub <https://github.com/davejamesmiller/laravel-breadcrumbs>
» Packagist <https://packagist.org/packages/davejamesmiller/laravel-breadcrumbs>

View File

@@ -1,25 +0,0 @@
################################################################################
License
################################################################################
`The MIT License (MIT) <http://choosealicense.com/licenses/mit/>`_
**Copyright © 2013-2015 Dave James Miller**
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,63 +0,0 @@
################################################################################
Outputting Breadcrumbs
################################################################################
Call ``Breadcrumbs::render()`` in the view template for each page, passing it the name of the breadcrumb to use and any additional parameters.
.. only:: html
.. contents::
:local:
================================================================================
With Blade
================================================================================
In the page (e.g. ``resources/views/home.blade.php``):
.. code-block:: html+php
{!! Breadcrumbs::render('home') !!}
Or with a parameter:
.. code-block:: html+php
{!! Breadcrumbs::render('category', $category) !!}
================================================================================
With Blade layouts and @section
================================================================================
In the page (e.g. ``resources/views/home.blade.php``):
.. code-block:: html+php
@extends('layout.name')
@section('breadcrumbs', Breadcrumbs::render('home'))
In the layout (e.g. ``resources/views/app.blade.php``):
.. code-block:: html+php
@yield('breadcrumbs')
================================================================================
Pure PHP (without Blade)
================================================================================
In the page (e.g. ``resources/views/home.php``):
.. code-block:: html+php
<?= Breadcrumbs::render('home') ?>
Or use the long-hand syntax if you prefer:
.. code-block:: html+php
<?php echo Breadcrumbs::render('home') ?>

View File

@@ -1,190 +0,0 @@
################################################################################
Route-Bound Breadcrumbs
################################################################################
In normal usage you must call ``Breadcrumbs::render($name, $params...)`` to render the breadcrumbs on every page. If you prefer, you can name your breadcrumbs the same as your routes and avoid this duplication.
.. only:: html
.. contents::
:local:
================================================================================
Setup
================================================================================
----------------------------------------
Name your routes
----------------------------------------
Make sure each of your routes has a name (``'as'`` parameter). For example (``routes/web.php``):
.. code-block:: php
// Home
Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']);
// Home > [Page]
Route::get('/page/{id}', ['as' => 'page', 'uses' => 'PageController@show']);
For more details see `Named Routes <https://www.laravel.com/docs/5.3/routing#named-routes>`_ in the Laravel documentation.
----------------------------------------
Name your breadcrumbs to match
----------------------------------------
For each route, create a breadcrumb with the same name. For example (``routes/breadcrumbs.php``):
.. code-block:: php
// Home
Breadcrumbs::register('home', function($breadcrumbs) {
$breadcrumbs->push('Home', route('home'));
});
// Home > [Page]
Breadcrumbs::register('page', function($breadcrumbs, $id)
{
$page = Page::findOrFail($id);
$breadcrumbs->parent('home');
$breadcrumbs->push($page->title, route('page', $page->id));
});
----------------------------------------
Output breadcrumbs in your layout
----------------------------------------
Call ``Breadcrumbs::render()`` with no parameters in your layout file (e.g. ``resources/views/app.blade.php``):
.. code-block:: html+php
{!! Breadcrumbs::render() !!}
This will automatically output breadcrumbs corresponding to the current route.
It will throw an exception if the breadcrumb doesn't exist, to remind you to create one. To prevent this behaviour, change it to:
.. code-block:: html+php
{!! Breadcrumbs::renderIfExists() !!}
================================================================================
Route model binding
================================================================================
Laravel Breadcrumbs uses the same model binding as the controller. For example:
.. code-block:: php
// routes/web.php
Route::model('page', 'Page');
Route::get('/page/{page}', ['uses' => 'PageController@show', 'as' => 'page']);
.. code-block:: php
// app/Http/Controllers/PageController.php
class PageController extends Controller
{
public function show($page)
{
return view('page/show', ['page' => $page]);
}
}
.. code-block:: php
// routes/breadcrumbs.php
Breadcrumbs::register('page', function($breadcrumbs, $page)
{
$breadcrumbs->parent('home');
$breadcrumbs->push($page->title, route('page', $page->id));
});
This makes your code less verbose and more efficient by only loading the page from the database once.
For more details see `Route Model Binding <https://www.laravel.com/docs/5.3/routing#route-model-binding>`_ in the Laravel documentation.
================================================================================
Resourceful controllers
================================================================================
Laravel automatically creates route names for resourceful controllers, e.g. ``photo.index``, which you can use when defining your breadcrumbs. For example:
.. code-block:: php
// routes/web.php
Route::resource('photo', 'PhotoController');
.. code-block:: bash
$ php artisan route:list
+--------+----------+--------------------+---------------+-------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+--------------------+---------------+-------------------------+------------+
| | GET|HEAD | photo | photo.index | PhotoController@index | |
| | GET|HEAD | photo/create | photo.create | PhotoController@create | |
| | POST | photo | photo.store | PhotoController@store | |
| | GET|HEAD | photo/{photo} | photo.show | PhotoController@show | |
| | GET|HEAD | photo/{photo}/edit | photo.edit | PhotoController@edit | |
| | PUT | photo/{photo} | photo.update | PhotoController@update | |
| | PATCH | photo/{photo} | | PhotoController@update | |
| | DELETE | photo/{photo} | photo.destroy | PhotoController@destroy | |
+--------+----------+--------------------+---------------+-------------------------+------------+
.. code-block:: php
// routes/breadcrumbs.php
// Photos
Breadcrumbs::register('photo.index', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Photos', route('photo.index'));
});
// Photos > Upload Photo
Breadcrumbs::register('photo.create', function($breadcrumbs)
{
$breadcrumbs->parent('photo.index');
$breadcrumbs->push('Upload Photo', route('photo.create'));
});
// Photos > [Photo Name]
Breadcrumbs::register('photo.show', function($breadcrumbs, $photo)
{
$breadcrumbs->parent('photo.index');
$breadcrumbs->push($photo->title, route('photo.show', $photo->id));
});
// Photos > [Photo Name] > Edit Photo
Breadcrumbs::register('photo.edit', function($breadcrumbs, $photo)
{
$breadcrumbs->parent('photo.show', $photo);
$breadcrumbs->push('Edit Photo', route('photo.edit', $photo->id));
});
For more details see `Resource Controllers <https://www.laravel.com/docs/5.3/controllers#resource-controllers>`_ in the Laravel documentation.
================================================================================
Implicit controllers
================================================================================
To use implicit controllers, you must specify names for each route. For example:
.. code-block:: php
// routes/web.php
Route::controller('auth', 'Auth\AuthController', [
'getRegister' => 'auth.register',
'getLogin' => 'auth.login',
]);
(You don't need to provide route names for actions that redirect and never display a view - e.g. most POST views.)
For more details see `Implicit Controllers <https://www.laravel.com/docs/5.1/controllers#implicit-controllers>`_ in the Laravel documentation.

View File

@@ -1,144 +0,0 @@
################################################################################
Getting Started
################################################################################
.. only:: html
.. contents::
:local:
================================================================================
1. Install Laravel Breadcrumbs
================================================================================
.. note::
Laravel 5.0 or above is required -- use the `2.x version <https://github.com/davejamesmiller/laravel-breadcrumbs/tree/2.x>`_ for Laravel 4.
----------------------------------------
Install with Composer
----------------------------------------
Run this at the command line:
.. code-block:: bash
$ composer require davejamesmiller/laravel-breadcrumbs
This will both update ``composer.json`` and install the package into the ``vendor/`` directory.
----------------------------------------
Add to ``config/app.php``
----------------------------------------
Add the service provider to ``providers``:
.. code-block:: php
'providers' => [
// ...
DaveJamesMiller\Breadcrumbs\ServiceProvider::class,
],
And add the facade to ``aliases``:
.. code-block:: php
'aliases' => [
// ...
'Breadcrumbs' => DaveJamesMiller\Breadcrumbs\Facade::class,
],
================================================================================
2. Define your breadcrumbs
================================================================================
Create a file called ``routes/breadcrumbs.php`` that looks like this:
.. code-block:: php
<?php
// Home
Breadcrumbs::register('home', function($breadcrumbs)
{
$breadcrumbs->push('Home', route('home'));
});
// Home > About
Breadcrumbs::register('about', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('About', route('about'));
});
// Home > Blog
Breadcrumbs::register('blog', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Blog', route('blog'));
});
// Home > Blog > [Category]
Breadcrumbs::register('category', function($breadcrumbs, $category)
{
$breadcrumbs->parent('blog');
$breadcrumbs->push($category->title, route('category', $category->id));
});
// Home > Blog > [Category] > [Page]
Breadcrumbs::register('page', function($breadcrumbs, $page)
{
$breadcrumbs->parent('category', $page->category);
$breadcrumbs->push($page->title, route('page', $page->id));
});
See the :doc:`defining` section for more details.
.. _choose-template:
================================================================================
3. Choose a template
================================================================================
By default a `Bootstrap <http://getbootstrap.com/components/#breadcrumbs>`_-compatible ordered list will be rendered, so if you're using Bootstrap 3 you can skip this step.
First initialise the config file by running this command:
.. code-block:: bash
$ php artisan vendor:publish
Then open ``config/breadcrumbs.php`` and edit this line:
.. code-block:: php
'view' => 'breadcrumbs::bootstrap3',
The possible values are:
- `Bootstrap 3 <http://getbootstrap.com/components/#breadcrumbs>`_: ``breadcrumbs::bootstrap3``
- `Bootstrap 2 <http://getbootstrap.com/2.3.2/components.html#breadcrumbs>`_: ``breadcrumbs::bootstrap2``
- The path to a custom view: e.g. ``_partials/breadcrumbs``
See the :doc:`templates` section for more details.
================================================================================
4. Output the breadcrumbs
================================================================================
Finally, call ``Breadcrumbs::render()`` in the view template for each page, passing it the name of the breadcrumb to use and any additional parameters -- for example:
.. code-block:: html+php
{!! Breadcrumbs::render('home') !!}
{!! Breadcrumbs::render('category', $category) !!}
See the :doc:`output` section for other output options, and see :doc:`routing` for a way to link breadcrumb names to route names automatically.

View File

@@ -1,60 +0,0 @@
################################################################################
Custom Templates
################################################################################
.. only:: html
.. contents::
:local:
================================================================================
Create a view
================================================================================
To customise the HTML, create your own view file (e.g. ``resources/views/_partials/breadcrumbs.blade.php``) like this:
.. code-block:: html+php
@if ($breadcrumbs)
<ul class="breadcrumb">
@foreach ($breadcrumbs as $breadcrumb)
@if (!$breadcrumb->last)
<li><a href="{{ $breadcrumb->url }}">{{ $breadcrumb->title }}</a></li>
@else
<li class="active">{{ $breadcrumb->title }}</li>
@endif
@endforeach
</ul>
@endif
(See the `views/ directory <https://github.com/davejamesmiller/laravel-breadcrumbs/tree/master/views>`_ for the built-in templates.)
.. _view-data:
----------------------------------------
View data
----------------------------------------
The view will receive an array called ``$breadcrumbs``.
Each breadcrumb is an object with the following keys:
- ``title`` - The breadcrumb title (see :doc:`defining`)
- ``url`` - The breadcrumb URL (see :doc:`defining`), or ``null`` if none was given
- ``first`` - ``true`` for the first breadcrumb (top level), ``false`` otherwise
- ``last`` - ``true`` for the last breadcrumb (current page), ``false`` otherwise
- Plus additional keys for each item in ``$data`` (see :ref:`custom-data`)
================================================================================
Update the config
================================================================================
Then update your config file (``config/breadcrumbs.php``) with the custom view name, e.g.:
.. code-block:: php
// resources/views/_partials/breadcrumbs.blade.php
'view' => '_partials/breadcrumbs',

View File

@@ -1,24 +0,0 @@
################################################################################
Thanks to
################################################################################
This package is largely based on the `Gretel <https://github.com/lassebunk/gretel>`_ plugin for Ruby on Rails, which I used for a while before discovering Laravel.
And of course it would be nothing without `Laravel <http://laravel.com/>`_ itself!
================================================================================
Contributors
================================================================================
- Christian Thomas (`christian-thomas <https://github.com/christian-thomas>`_) -
`#62 <https://github.com/davejamesmiller/laravel-breadcrumbs/issues/62#issuecomment-71724019>`_
- Miloš Levačić (`levacic <https://github.com/levacic>`_) -
`#56 <https://github.com/davejamesmiller/laravel-breadcrumbs/pull/56>`_
- Ricky Wiens (`rickywiens <https://github.com/rickywiens>`_) -
`#41 <https://github.com/davejamesmiller/laravel-breadcrumbs/pull/41>`_
- Boris Glumpler (`shabushabu <https://github.com/shabushabu>`_) -
`#28 <https://github.com/davejamesmiller/laravel-breadcrumbs/pull/28>`_
- Andrej Badin (`Andreyco <https://github.com/Andreyco>`_) -
`#24 <https://github.com/davejamesmiller/laravel-breadcrumbs/pull/24>`_
- Stef Horner (`tedslittlerobot <https://github.com/tedslittlerobot>`_) -
`#11 <https://github.com/davejamesmiller/laravel-breadcrumbs/pull/11>`_

View File

@@ -1,7 +0,0 @@
<?php
// Load Composer packages
require __DIR__ . '/vendor/autoload.php';
// Load base class
require __DIR__ . '/tests/TestCase.php';

View File

@@ -4,7 +4,7 @@
backupStaticAttributes="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="phpunit.php"
bootstrap="tests/bootstrap.php"
checkForUnintentionallyCoveredCode="true"
colors="true"
convertErrorsToExceptions="true"

View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -o nounset -o pipefail -o errexit
cd "$(dirname "$0")/.."
################################################################################
# Run PHPUnit with code coverage (requires Xdebug).
################################################################################
exec php -d xdebug.coverage_enable=On vendor/bin/phpunit --coverage-html test-coverage "$@"

View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -o nounset -o pipefail -o errexit
cd "$(dirname "$0")/.."
################################################################################
# Run PHPUnit.
################################################################################
exec vendor/bin/phpunit "$@"

View File

@@ -2,159 +2,169 @@
class Manager {
protected $currentRoute;
protected $generator;
protected $view;
protected $currentRoute;
protected $generator;
protected $view;
protected $callbacks = [];
protected $viewName;
protected $currentRouteManual;
protected $callbacks = [];
protected $viewName;
protected $currentRouteManual;
public function __construct(CurrentRoute $currentRoute, Generator $generator, View $view)
{
$this->generator = $generator;
$this->currentRoute = $currentRoute;
$this->view = $view;
}
public function __construct(CurrentRoute $currentRoute, Generator $generator, View $view)
{
$this->generator = $generator;
$this->currentRoute = $currentRoute;
$this->view = $view;
}
public function register($name, $callback)
{
if (isset($this->callbacks[$name]))
throw new Exception("Breadcrumb name \"{$name}\" has already been registered");
$this->callbacks[$name] = $callback;
}
public function register($name, $callback)
{
if (isset($this->callbacks[$name]))
throw new Exception("Breadcrumb name \"{$name}\" has already been registered");
$this->callbacks[$name] = $callback;
}
public function exists($name = null)
{
if (is_null($name)) {
try {
list($name) = $this->currentRoute->get();
} catch (Exception $e) {
return false;
}
}
public function exists($name = null)
{
if (is_null($name)) {
try {
list($name) = $this->currentRoute->get();
} catch (Exception $e) {
return false;
}
}
return isset($this->callbacks[$name]);
}
return isset($this->callbacks[$name]);
}
public function generate($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
public function generate($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
return $this->generator->generate($this->callbacks, $name, $params);
}
return $this->generator->generate($this->callbacks, $name, $params);
}
public function generateArray($name, $params = [])
{
return $this->generator->generate($this->callbacks, $name, $params);
}
public function generateArray($name, $params = [])
{
return $this->generator->generate($this->callbacks, $name, $params);
}
public function generateIfExists($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
public function generateIfExists($name = null)
{
if (is_null($name)) {
try {
list($name, $params) = $this->currentRoute->get();
} catch (Exception $e) {
return [];
}
} else {
$params = array_slice(func_get_args(), 1);
}
if (!$this->exists($name))
return [];
if (!$this->exists($name))
return [];
return $this->generator->generate($this->callbacks, $name, $params);
}
return $this->generator->generate($this->callbacks, $name, $params);
}
public function generateIfExistsArray($name, $params = [])
{
if (!$this->exists($name))
return [];
public function generateIfExistsArray($name, $params = [])
{
if (!$this->exists($name))
return [];
return $this->generator->generate($this->callbacks, $name, $params);
}
return $this->generator->generate($this->callbacks, $name, $params);
}
/**
* @deprecated Since 3.0.0
* @see generateIfExistsArray
*/
public function generateArrayIfExists()
{
return call_user_func_array([$this, 'generateIfExistsArray'], func_get_args());
}
/**
* @deprecated Since 3.0.0
* @see generateIfExistsArray
*/
public function generateArrayIfExists()
{
return call_user_func_array([$this, 'generateIfExistsArray'], func_get_args());
}
public function render($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
public function render($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
return $this->view->render($this->viewName, $breadcrumbs);
}
return $this->view->render($this->viewName, $breadcrumbs);
}
public function renderArray($name, $params = [])
{
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
public function renderArray($name, $params = [])
{
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
return $this->view->render($this->viewName, $breadcrumbs);
}
return $this->view->render($this->viewName, $breadcrumbs);
}
public function renderIfExists($name = null)
{
if (is_null($name))
list($name, $params) = $this->currentRoute->get();
else
$params = array_slice(func_get_args(), 1);
public function renderIfExists($name = null)
{
if (is_null($name)) {
try {
list($name, $params) = $this->currentRoute->get();
} catch (Exception $e) {
return '';
}
} else {
$params = array_slice(func_get_args(), 1);
}
if (!$this->exists($name))
return '';
if (!$this->exists($name))
return '';
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
return $this->view->render($this->viewName, $breadcrumbs);
}
return $this->view->render($this->viewName, $breadcrumbs);
}
public function renderIfExistsArray($name, $params = [])
{
if (!$this->exists($name))
return '';
public function renderIfExistsArray($name, $params = [])
{
if (!$this->exists($name))
return '';
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
$breadcrumbs = $this->generator->generate($this->callbacks, $name, $params);
return $this->view->render($this->viewName, $breadcrumbs);
}
return $this->view->render($this->viewName, $breadcrumbs);
}
/**
* @deprecated Since 3.0.0
* @see renderIfExistsArray
*/
public function renderArrayIfExists()
{
return call_user_func_array([$this, 'renderIfExistsArray'], func_get_args());
}
/**
* @deprecated Since 3.0.0
* @see renderIfExistsArray
*/
public function renderArrayIfExists()
{
return call_user_func_array([$this, 'renderIfExistsArray'], func_get_args());
}
public function setCurrentRoute($name)
{
$params = array_slice(func_get_args(), 1);
public function setCurrentRoute($name)
{
$params = array_slice(func_get_args(), 1);
$this->currentRoute->set($name, $params);
}
$this->currentRoute->set($name, $params);
}
public function setCurrentRouteArray($name, $params = [])
{
$this->currentRoute->set($name, $params);
}
public function setCurrentRouteArray($name, $params = [])
{
$this->currentRoute->set($name, $params);
}
public function clearCurrentRoute()
{
$this->currentRoute->clear();
}
public function clearCurrentRoute()
{
$this->currentRoute->clear();
}
public function setView($view)
{
$this->viewName = $view;
}
public function setView($view)
{
$this->viewName = $view;
}
}

View File

@@ -31,7 +31,7 @@ class ServiceProvider extends BaseServiceProvider {
*/
public function register()
{
$this->app['breadcrumbs'] = $this->app->share(function($app)
$this->app->singleton('breadcrumbs', function ($app)
{
$breadcrumbs = $this->app->make('DaveJamesMiller\Breadcrumbs\Manager');

View File

@@ -1,5 +0,0 @@
#!/bin/bash
set -eu
cd $(dirname $0)
php -d xdebug.coverage_enable=On vendor/bin/phpunit --coverage-html test-coverage "$@"

View File

@@ -1,5 +0,0 @@
#!/bin/bash
set -eu
cd $(dirname $0)
vendor/bin/phpunit "$@"

View File

@@ -0,0 +1,7 @@
<?php
// Load Composer packages
require __DIR__ . '/../vendor/autoload.php';
// Load base class
require __DIR__ . '/../tests/TestCase.php';

View File

@@ -5,159 +5,167 @@ use Mockery as m;
class ManagerTest extends TestCase {
public function setUp()
{
parent::setUp();
public function setUp()
{
parent::setUp();
$this->currentRoute = m::mock('DaveJamesMiller\Breadcrumbs\CurrentRoute');
$this->generator = m::mock('DaveJamesMiller\Breadcrumbs\Generator');
$this->view = m::mock('DaveJamesMiller\Breadcrumbs\View');
$this->manager = new Manager($this->currentRoute, $this->generator, $this->view);
$this->currentRoute = m::mock('DaveJamesMiller\Breadcrumbs\CurrentRoute');
$this->generator = m::mock('DaveJamesMiller\Breadcrumbs\Generator');
$this->view = m::mock('DaveJamesMiller\Breadcrumbs\View');
$this->manager = new Manager($this->currentRoute, $this->generator, $this->view);
$this->manager->setView('view');
}
$this->manager->setView('view');
}
// Breadcrumbs::register($name, $callback) is tested by other methods
protected function register($name)
{
$this->manager->register($name, $fn = function() {
// We're not testing whether the callbacks are executed - see GeneratorTest
throw new Exception('Callback executed');
});
// Breadcrumbs::register($name, $callback) is tested by other methods
protected function register($name)
{
$this->manager->register($name, $fn = function() {
// We're not testing whether the callbacks are executed - see GeneratorTest
throw new Exception('Callback executed');
});
return $fn;
}
return $fn;
}
// Breadcrumbs::exists() -> boolean
public function testExists()
{
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
// Breadcrumbs::exists() -> boolean
public function testExists()
{
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->assertFalse($this->manager->exists());
$this->assertFalse($this->manager->exists());
$this->register('sample');
$this->assertTrue($this->manager->exists());
}
$this->register('sample');
$this->assertTrue($this->manager->exists());
}
// Breadcrumbs::exists($name) -> boolean
public function testExists_name()
{
$this->assertFalse($this->manager->exists('sample'));
// Breadcrumbs::exists($name) -> boolean
public function testExists_name()
{
$this->assertFalse($this->manager->exists('sample'));
$this->register('sample');
$this->assertTrue($this->manager->exists('sample'));
}
$this->register('sample');
$this->assertTrue($this->manager->exists('sample'));
}
// Breadcrumbs::generate() -> array
public function testGenerate()
{
$fn = $this->register('sample');
// Breadcrumbs::generate() -> array
public function testGenerate()
{
$fn = $this->register('sample');
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->assertSame('generated', $this->manager->generate());
}
$this->assertSame('generated', $this->manager->generate());
}
// Breadcrumbs::generate($name) -> array
public function testGenerate_name()
{
$fn = $this->register('sample');
// Breadcrumbs::generate($name) -> array
public function testGenerate_name()
{
$fn = $this->register('sample');
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [])->once()->andReturn('generated');;
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [])->once()->andReturn('generated');;
$this->assertSame('generated', $this->manager->generate('sample'));
}
$this->assertSame('generated', $this->manager->generate('sample'));
}
// Breadcrumbs::generate($name, $param1, ...) -> array
public function testGenerate_name_params()
{
$fn = $this->register('sample');
// Breadcrumbs::generate($name, $param1, ...) -> array
public function testGenerate_name_params()
{
$fn = $this->register('sample');
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->assertSame('generated', $this->manager->generate('sample', 1, 'blah'));
}
$this->assertSame('generated', $this->manager->generate('sample', 1, 'blah'));
}
// Breadcrumbs::generateArray($name, $params) -> array
public function testGenerateArray_name_params()
{
$fn = $this->register('sample');
// Breadcrumbs::generateArray($name, $params) -> array
public function testGenerateArray_name_params()
{
$fn = $this->register('sample');
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->assertSame('generated', $this->manager->generateArray('sample', [1, 'blah']));
}
$this->assertSame('generated', $this->manager->generateArray('sample', [1, 'blah']));
}
// Breadcrumbs::generateIfExists() -> array
public function testGenerateIfExists_existing()
{
$fn = $this->register('sample');
// Breadcrumbs::generateIfExists() -> array
public function testGenerateIfExists_existing()
{
$fn = $this->register('sample');
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->assertSame('generated', $this->manager->generateIfExists());
}
$this->assertSame('generated', $this->manager->generateIfExists());
}
public function testGenerateIfExists_nonexistant()
{
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->never();
public function testGenerateIfExists_nonexistant()
{
$this->currentRoute->shouldReceive('get')->andReturn(['sample', [1, 'blah']]);
$this->generator->shouldReceive('generate')->never();
$this->assertSame([], $this->manager->generateIfExists());
}
$this->assertSame([], $this->manager->generateIfExists());
}
// Breadcrumbs::generateIfExists($name) -> array
public function testGenerateIfExists_name_existing()
{
$fn = $this->register('sample');
public function testGenerateIfExists_noroute()
{
$this->currentRoute->shouldReceive('get')->andThrow('DaveJamesMiller\Breadcrumbs\Exception', 'The current route (GET /sample/unnamed) is not named - please check routes.php for an "as" parameter');
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateIfExists());
}
$this->assertSame('generated', $this->manager->generateIfExists('sample'));
}
// Breadcrumbs::generateIfExists($name) -> array
public function testGenerateIfExists_name_existing()
{
$fn = $this->register('sample');
public function testGenerateIfExists_name_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateIfExists('sample'));
}
$this->assertSame('generated', $this->manager->generateIfExists('sample'));
}
// Breadcrumbs::generateIfExists($name, $param1, ...) -> array
public function testGenerateIfExists_name_params_existing()
{
$fn = $this->register('sample');
public function testGenerateIfExists_name_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateIfExists('sample'));
}
$this->assertSame('generated', $this->manager->generateIfExists('sample', 1, 'blah'));
}
// Breadcrumbs::generateIfExists($name, $param1, ...) -> array
public function testGenerateIfExists_name_params_existing()
{
$fn = $this->register('sample');
public function testGenerateIfExists_name_params_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateIfExists('sample', 1, 'blah'));
}
$this->assertSame('generated', $this->manager->generateIfExists('sample', 1, 'blah'));
}
// Breadcrumbs::generateArrayIfExists($name, $params) -> array
public function testGenerateArrayIfExists_name_params_existing()
{
$fn = $this->register('sample');
public function testGenerateIfExists_name_params_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateIfExists('sample', 1, 'blah'));
}
$this->assertSame('generated', $this->manager->generateArrayIfExists('sample', [1, 'blah']));
}
// Breadcrumbs::generateArrayIfExists($name, $params) -> array
public function testGenerateArrayIfExists_name_params_existing()
{
$fn = $this->register('sample');
public function testGenerateArrayIfExists_name_params_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');
$this->assertSame([], $this->manager->generateArrayIfExists('sample', [1, 'blah']));
}
$this->assertSame('generated', $this->manager->generateArrayIfExists('sample', [1, 'blah']));
}
public function testGenerateArrayIfExists_name_params_nonexistant()
{
$this->generator->shouldReceive('generate')->never();
$this->assertSame([], $this->manager->generateArrayIfExists('sample', [1, 'blah']));
}
// Breadcrumbs::render() -> array
public function testRender()
@@ -225,6 +233,15 @@ class ManagerTest extends TestCase {
$this->assertSame('', $this->manager->renderIfExists());
}
public function testRenderIfExists_noroute()
{
$this->currentRoute->shouldReceive('get')->andThrow('DaveJamesMiller\Breadcrumbs\Exception', 'The current route (GET /sample/unnamed) is not named - please check routes.php for an "as" parameter');
$this->generator->shouldReceive('generate')->never();
$this->view->shouldReceive('render')->never();
$this->assertSame('', $this->manager->renderIfExists());
}
// Breadcrumbs::renderIfExists($name) -> array
public function testRenderIfExists_name_existing()
{
@@ -282,48 +299,48 @@ class ManagerTest extends TestCase {
$this->assertSame('', $this->manager->renderArrayIfExists('sample', [1, 'blah']));
}
// Breadcrumbs::setCurrentRoute($name)
public function testSetCurrentRoute_name()
{
$this->currentRoute->shouldReceive('set')->with('sample', [])->once();
// Breadcrumbs::setCurrentRoute($name)
public function testSetCurrentRoute_name()
{
$this->currentRoute->shouldReceive('set')->with('sample', [])->once();
$this->manager->setCurrentRoute('sample');
}
$this->manager->setCurrentRoute('sample');
}
// Breadcrumbs::setCurrentRoute($name, $param1, ...)
public function testSetCurrentRoute_name_params()
{
$this->currentRoute->shouldReceive('set')->with('sample', [1, 'blah'])->once();
// Breadcrumbs::setCurrentRoute($name, $param1, ...)
public function testSetCurrentRoute_name_params()
{
$this->currentRoute->shouldReceive('set')->with('sample', [1, 'blah'])->once();
$this->manager->setCurrentRoute('sample', 1, 'blah');
}
$this->manager->setCurrentRoute('sample', 1, 'blah');
}
// Breadcrumbs::setCurrentRouteArray($name, $params)
public function testSetCurrentRouteArray_name_params()
{
$this->currentRoute->shouldReceive('set')->with('sample', [1, 'blah'])->once();
// Breadcrumbs::setCurrentRouteArray($name, $params)
public function testSetCurrentRouteArray_name_params()
{
$this->currentRoute->shouldReceive('set')->with('sample', [1, 'blah'])->once();
$this->manager->setCurrentRouteArray('sample', [1, 'blah']);
}
$this->manager->setCurrentRouteArray('sample', [1, 'blah']);
}
// Breadcrumbs::clearCurrentRoute()
public function testClearCurrentRoute()
{
$this->currentRoute->shouldReceive('clear')->withNoArgs()->once();
// Breadcrumbs::clearCurrentRoute()
public function testClearCurrentRoute()
{
$this->currentRoute->shouldReceive('clear')->withNoArgs()->once();
$this->manager->clearCurrentRoute();
}
$this->manager->clearCurrentRoute();
}
// Breadcrumbs::setView($view)
public function testSetView()
{
// Breadcrumbs::setView($view)
public function testSetView()
{
$fn = $this->register('sample');
$this->generator->shouldReceive('generate')->with(['sample' => $fn], 'sample', [1, 'blah'])->once()->andReturn('generated');;
$this->view->shouldReceive('render')->with('custom.view', 'generated')->once()->andReturn('rendered');
$this->manager->setView($view = 'custom.view');
$this->manager->setView($view = 'custom.view');
$this->assertSame('rendered', $this->manager->render('sample', 1, 'blah'));
}
}
}