Update v1.0.6
This commit is contained in:
7
vendor/autoload.php
vendored
7
vendor/autoload.php
vendored
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit1bacc9bd2a82216bf11bc15e6aee6c79::getLoader();
|
7
vendor/bin/classpreloader.php
vendored
7
vendor/bin/classpreloader.php
vendored
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
SRC_DIR="`pwd`"
|
||||
cd "`dirname "$0"`"
|
||||
cd "../classpreloader/classpreloader"
|
||||
BIN_TARGET="`pwd`/classpreloader.php"
|
||||
cd "$SRC_DIR"
|
||||
"$BIN_TARGET" "$@"
|
3
vendor/bin/classpreloader.php.bat
vendored
3
vendor/bin/classpreloader.php.bat
vendored
@@ -1,3 +0,0 @@
|
||||
@ECHO OFF
|
||||
SET BIN_TARGET=%~dp0/../classpreloader/classpreloader/classpreloader.php
|
||||
php "%BIN_TARGET%" %*
|
7
vendor/bin/phpspec
vendored
7
vendor/bin/phpspec
vendored
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
SRC_DIR="`pwd`"
|
||||
cd "`dirname "$0"`"
|
||||
cd "../phpspec/phpspec/bin"
|
||||
BIN_TARGET="`pwd`/phpspec"
|
||||
cd "$SRC_DIR"
|
||||
"$BIN_TARGET" "$@"
|
3
vendor/bin/phpspec.bat
vendored
3
vendor/bin/phpspec.bat
vendored
@@ -1,3 +0,0 @@
|
||||
@ECHO OFF
|
||||
SET BIN_TARGET=%~dp0/../phpspec/phpspec/bin/phpspec
|
||||
php "%BIN_TARGET%" %*
|
7
vendor/bin/phpunit
vendored
7
vendor/bin/phpunit
vendored
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
SRC_DIR="`pwd`"
|
||||
cd "`dirname "$0"`"
|
||||
cd "../phpunit/phpunit"
|
||||
BIN_TARGET="`pwd`/phpunit"
|
||||
cd "$SRC_DIR"
|
||||
"$BIN_TARGET" "$@"
|
3
vendor/bin/phpunit.bat
vendored
3
vendor/bin/phpunit.bat
vendored
@@ -1,3 +0,0 @@
|
||||
@ECHO OFF
|
||||
SET BIN_TARGET=%~dp0/../phpunit/phpunit/phpunit
|
||||
php "%BIN_TARGET%" %*
|
7
vendor/bin/psysh
vendored
7
vendor/bin/psysh
vendored
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
SRC_DIR="`pwd`"
|
||||
cd "`dirname "$0"`"
|
||||
cd "../psy/psysh/bin"
|
||||
BIN_TARGET="`pwd`/psysh"
|
||||
cd "$SRC_DIR"
|
||||
"$BIN_TARGET" "$@"
|
3
vendor/bin/psysh.bat
vendored
3
vendor/bin/psysh.bat
vendored
@@ -1,3 +0,0 @@
|
||||
@ECHO OFF
|
||||
SET BIN_TARGET=%~dp0/../psy/psysh/bin/psysh
|
||||
php "%BIN_TARGET%" %*
|
@@ -1,3 +0,0 @@
|
||||
example/ export-ignore
|
||||
tests/ export-ignore
|
||||
phpunit.xml export-ignore
|
4
vendor/bugsnag/bugsnag-laravel/.gitignore
vendored
4
vendor/bugsnag/bugsnag-laravel/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
18
vendor/bugsnag/bugsnag-laravel/.travis.yml
vendored
18
vendor/bugsnag/bugsnag-laravel/.travis.yml
vendored
@@ -1,18 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
|
||||
before_script:
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- phpunit
|
||||
|
||||
notifications:
|
||||
hipchat:
|
||||
rooms:
|
||||
secure: h9501ANwjT/oDK9YM1fmLV9+1WuhEWpRu35VCqJrOHEHpDQjk7W0LZw4xJo/kK10AKCN861U5VT1U5ncxujFLBZ2HnrKGraTCvXRss/dC2wn+fG2P+T4hsQGWAyU/rU/A8uPwZT71gqCmNtt1Xo/uGHt1UHT+H59J3d3GoFjgBY=
|
121
vendor/bugsnag/bugsnag-laravel/CHANGELOG.md
vendored
121
vendor/bugsnag/bugsnag-laravel/CHANGELOG.md
vendored
@@ -1,121 +0,0 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
1.6.3
|
||||
-----
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Avoid initializing Bugsnag when no API key is set
|
||||
| [Dries Vints](https://github.com/driesvints)
|
||||
| [#72](https://github.com/bugsnag/bugsnag-laravel/pull/72)
|
||||
|
||||
1.6.2
|
||||
-----
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Add support for configuring the notifier completely from
|
||||
[environment variables](https://github.com/bugsnag/bugsnag-laravel#environment-variables)
|
||||
| [Andrew](https://github.com/browner12)
|
||||
| [#71](https://github.com/bugsnag/bugsnag-laravel/pull/71)
|
||||
|
||||
1.6.1
|
||||
-----
|
||||
- Fix array syntax for older php
|
||||
|
||||
1.6.0
|
||||
-----
|
||||
- Move to using .env for api key in laravel 5+
|
||||
- Support for artisan vendor:publish
|
||||
|
||||
1.5.1
|
||||
-----
|
||||
- Lumen Service Provider use statement
|
||||
|
||||
1.5.0
|
||||
-----
|
||||
- Lumen support
|
||||
- Fix bug in instructions
|
||||
- Fix bug with reading settings from service file
|
||||
|
||||
1.4.2
|
||||
-----
|
||||
- Try/catch for missing/nonstandard auth service
|
||||
|
||||
1.4.1
|
||||
-----
|
||||
- Default severity to 'error'
|
||||
|
||||
1.4.0
|
||||
-----
|
||||
- Better laravel 5 support!
|
||||
|
||||
1.3.0
|
||||
-----
|
||||
- Laravel 5 support!
|
||||
|
||||
1.2.1
|
||||
-----
|
||||
- Protect against missing configuration variables (thanks @jasonlfunk!)
|
||||
|
||||
1.2.0
|
||||
-----
|
||||
- Update `bugsnag-php` dependency to enable support for code snippets on
|
||||
your Bugsnag dashboard
|
||||
- Allow configuring of more Bugsnag settings from your `config.php`
|
||||
(thanks @jacobmarshall!)
|
||||
|
||||
1.1.1
|
||||
-----
|
||||
- Fix issue where sending auth information with complex users could fail (thanks @hannesvdvreken!)
|
||||
|
||||
1.1.0
|
||||
-----
|
||||
- Send user/auth information if available (thanks @hannesvdvreken!)
|
||||
|
||||
1.0.10
|
||||
------
|
||||
- Laravel 5 support
|
||||
|
||||
1.0.9
|
||||
------
|
||||
- Split strip paths from `inProject`
|
||||
|
||||
1.0.8
|
||||
-----
|
||||
- Bump the bugsnag-php dependency to include recent fixes
|
||||
|
||||
1.0.7
|
||||
-----
|
||||
- Fix major notification bug introduced in 1.0.6
|
||||
|
||||
1.0.6
|
||||
-----
|
||||
- Fix incompatibility with PHP 5.3
|
||||
|
||||
1.0.5
|
||||
-----
|
||||
- Identify as Laravel notifier instead of PHP
|
||||
|
||||
1.0.4
|
||||
-----
|
||||
- Allow configuration of notify_release_stages from config file
|
||||
|
||||
1.0.3
|
||||
-----
|
||||
- Fix bug when setting releaseStage in the ServiceProvider
|
||||
|
||||
1.0.2
|
||||
-----
|
||||
- Fix laravel requirement to work with 4.1
|
||||
- Add a `Bugsnag` facade for quick access to $app["bugsnag"]
|
||||
|
||||
1.0.1
|
||||
-----
|
||||
- Fixed fatal error handling
|
||||
- Set release stage based on laravel's `App::environment` setting
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
- Initial release
|
26
vendor/bugsnag/bugsnag-laravel/CONTRIBUTING.md
vendored
26
vendor/bugsnag/bugsnag-laravel/CONTRIBUTING.md
vendored
@@ -1,26 +0,0 @@
|
||||
Contributing
|
||||
============
|
||||
|
||||
- [Fork](https://help.github.com/articles/fork-a-repo) the [notifier on github](https://github.com/bugsnag/bugsnag-laravel)
|
||||
- Build and test your changes:
|
||||
```
|
||||
composer install && ./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
- Commit and push until you are happy with your contribution
|
||||
- [Make a pull request](https://help.github.com/articles/using-pull-requests)
|
||||
- Thanks!
|
||||
|
||||
|
||||
Releasing
|
||||
=========
|
||||
|
||||
1. Commit all outstanding changes
|
||||
1. Bump the version in `src/Bugsnag/BugsnagLaravel/BugsnagLaravelServiceProvider.php` and `src/Bugsnag/BugsnagLaravel/BugsnagLumenServiceProvider.php`
|
||||
2. Update the CHANGELOG.md, and README if appropriate.
|
||||
3. Commit, tag push
|
||||
|
||||
git commit -am v1.x.x
|
||||
git tag v1.x.x
|
||||
git push origin master v1.x.x
|
||||
|
20
vendor/bugsnag/bugsnag-laravel/LICENSE.txt
vendored
20
vendor/bugsnag/bugsnag-laravel/LICENSE.txt
vendored
@@ -1,20 +0,0 @@
|
||||
Copyright (c) 2013 Bugsnag
|
||||
|
||||
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.
|
349
vendor/bugsnag/bugsnag-laravel/README.md
vendored
349
vendor/bugsnag/bugsnag-laravel/README.md
vendored
@@ -1,349 +0,0 @@
|
||||
Bugsnag Notifier for Laravel and Lumen
|
||||
=====================================
|
||||
|
||||
The Bugsnag Notifier for Laravel gives you instant notification of errors and
|
||||
exceptions in your Laravel PHP applications. We support Laravel 5, Laravel 4,
|
||||
Laravel 3, and Lumen.
|
||||
|
||||
[Bugsnag](https://bugsnag.com) captures errors in real-time from your web,
|
||||
mobile and desktop applications, helping you to understand and resolve them
|
||||
as fast as possible. [Create a free account](https://bugsnag.com) to start
|
||||
capturing errors from your applications.
|
||||
|
||||
Check out this excellent [Laracasts
|
||||
screencast](https://laracasts.com/lessons/better-error-tracking-with-bugsnag)
|
||||
for a quick overview of how to use Bugsnag with your Laravel apps.
|
||||
|
||||
Contents
|
||||
--------
|
||||
|
||||
- [Getting Started](#getting-started)
|
||||
- [Installation](#installation)
|
||||
- [Laravel 5.0+](#laravel-50)
|
||||
- [Laravel (Older Versions)](#laravel-older-versions)
|
||||
- [Lumen](#lumen)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Usage](#usage)
|
||||
- [Catching and Reporting Exceptions](#catching-and-reporting-exceptions)
|
||||
- [Sending Non-fatal Exceptions](#sending-non-fatal-exceptions)
|
||||
- [Configuration Options](#configuration-options)
|
||||
- [Error Reporting Levels](#error-reporting-levels)
|
||||
- [Callbacks](#callbacks)
|
||||
- [Demo Applications](#demo-applications)
|
||||
- [Support](#support)
|
||||
- [Contributing](#contributing)
|
||||
- [License](#license)
|
||||
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
### Installation
|
||||
|
||||
#### Laravel 5.0+
|
||||
|
||||
1. Install the `bugsnag/bugsnag-laravel` package
|
||||
|
||||
```shell
|
||||
$ composer require bugsnag/bugsnag-laravel:1.*
|
||||
```
|
||||
|
||||
1. Update `config/app.php` to activate Bugsnag
|
||||
|
||||
```php
|
||||
# Add `BugsnagLaravelServiceProvider` to the `providers` array
|
||||
'providers' => array(
|
||||
...
|
||||
Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider::class,
|
||||
)
|
||||
|
||||
# Add the `BugsnagFacade` to the `aliases` array
|
||||
'aliases' => array(
|
||||
...
|
||||
'Bugsnag' => Bugsnag\BugsnagLaravel\BugsnagFacade::class,
|
||||
)
|
||||
```
|
||||
|
||||
1. Use the Bugsnag exception handler from `App/Exceptions/Handler.php`.
|
||||
|
||||
```php
|
||||
# DELETE this line
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
```
|
||||
|
||||
```php
|
||||
# ADD this line instead
|
||||
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
|
||||
```
|
||||
|
||||
After this change, your file should look like this:
|
||||
|
||||
```php
|
||||
<?php namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler {
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
1. Create the configuration file `config/bugsnag.php`:
|
||||
|
||||
```shell
|
||||
$ php artisan vendor:publish --provider="Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider"
|
||||
```
|
||||
|
||||
1. Configure your `api_key` in your `.env` file:
|
||||
|
||||
```shell
|
||||
BUGSNAG_API_KEY=YOUR-API-KEY-HERE
|
||||
```
|
||||
|
||||
1. Optionally, you can add the `notify_release_stages` key to the
|
||||
`config/bugsnag.php` file to define which Laravel environments will send
|
||||
Exceptions to Bugsnag.
|
||||
|
||||
```php
|
||||
return array(
|
||||
'api_key' => env('BUGSNAG_API_KEY'),
|
||||
'notify_release_stages' => ['production', 'staging']
|
||||
);
|
||||
```
|
||||
|
||||
#### Laravel (Older Versions)
|
||||
|
||||
For versions of Laravel before 5.0:
|
||||
|
||||
1. Install the `bugsnag/bugsnag-laravel` package
|
||||
|
||||
```shell
|
||||
$ composer require bugsnag/bugsnag-laravel:1.*
|
||||
```
|
||||
|
||||
1. Update app/config/app.php` to activate Bugsnag
|
||||
|
||||
```php
|
||||
# Add `BugsnagLaravelServiceProvider` to the `providers` array
|
||||
'providers' => array(
|
||||
...
|
||||
'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',
|
||||
)
|
||||
|
||||
# Add the `BugsnagFacade` to the `aliases` array
|
||||
'aliases' => array(
|
||||
...
|
||||
'Bugsnag' => 'Bugsnag\BugsnagLaravel\BugsnagFacade',
|
||||
)
|
||||
```
|
||||
|
||||
1. Generate a template Bugsnag config file
|
||||
|
||||
```shell
|
||||
$ php artisan config:publish bugsnag/bugsnag-laravel
|
||||
```
|
||||
|
||||
1. Update `app/config/packages/bugsnag/bugsnag-laravel/config.php` with your
|
||||
Bugsnag API key:
|
||||
|
||||
```php
|
||||
return array(
|
||||
'api_key' => 'YOUR-API-KEY-HERE'
|
||||
);
|
||||
```
|
||||
|
||||
1. Optionally, you can add the `notify_release_stages` key to the same file
|
||||
above to define which Laravel environments will send Exceptions to Bugsnag.
|
||||
|
||||
```php
|
||||
return array(
|
||||
'api_key' => 'YOUR-API-KEY-HERE',
|
||||
'notify_release_stages' => ['production', 'staging']
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
#### Lumen
|
||||
|
||||
1. In `bootstrap/app.php` add the line
|
||||
|
||||
```php
|
||||
$app->register('Bugsnag\BugsnagLaravel\BugsnagLumenServiceProvider');
|
||||
```
|
||||
|
||||
just before the line
|
||||
|
||||
```php
|
||||
require __DIR__ . '/../app/Http/routes.php';
|
||||
```
|
||||
|
||||
2. Change the function `report` in `app/Exceptions/Handler.php` to look like
|
||||
this:
|
||||
|
||||
```php
|
||||
public function report(Exception $e) {
|
||||
app('bugsnag')->notifyException($e, []);
|
||||
return parent::report($e);
|
||||
}
|
||||
```
|
||||
|
||||
3. Create a file `config/bugsnag.php` that contains your API key
|
||||
|
||||
```php
|
||||
<?php # config/bugsnag.php
|
||||
|
||||
return array(
|
||||
'api_key' => 'YOUR-API-KEY-HERE'
|
||||
);
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
In addition to `BUGSNAG_API_KEY`, other configuration keys can be automatically
|
||||
populated in `config.php` from your `.env` file:
|
||||
|
||||
- `BUGSNAG_API_KEY`: Your API key. You can find your API key on your Bugsnag
|
||||
dashboard.
|
||||
- `BUGSNAG_NOTIFY_RELEASE_STAGES`: Set which release stages should send
|
||||
notifications to Bugsnag.
|
||||
- `BUGSNAG_ENDPOINT`: Set what server to which the Bugsnag notifier should send
|
||||
errors. The default is https://notify.bugsnag.com, but for Bugsnag Enterprise
|
||||
the endpoint should be the URL of your Bugsnag instance.
|
||||
- `BUGSNAG_FILTERS`: Set which keys are filtered from metadata is sent to
|
||||
Bugsnag.
|
||||
- `BUGSNAG_PROXY`: Set the configuration options for your server if it is behind
|
||||
a proxy server. Additional details are available in the
|
||||
[sample configuration](src/Bugsnag/BugsnagLaravel/config.php#L56).
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
### Catching and Reporting Exceptions
|
||||
|
||||
Bugsnag works "out of the box" for reporting unhandled exceptions in
|
||||
Laravel and Lumen apps.
|
||||
|
||||
|
||||
### Sending Non-fatal Exceptions
|
||||
|
||||
You can easily tell Bugsnag about non-fatal or caught exceptions by
|
||||
calling `Bugsnag::notifyException`:
|
||||
|
||||
```php
|
||||
Bugsnag::notifyException(new Exception("Something bad happened"));
|
||||
```
|
||||
|
||||
You can also send custom errors to Bugsnag with `Bugsnag::notifyError`:
|
||||
|
||||
```php
|
||||
Bugsnag::notifyError("ErrorType", "Something bad happened here too");
|
||||
```
|
||||
|
||||
Both of these functions can also be passed an optional `$metaData` parameter,
|
||||
which should take the following format:
|
||||
|
||||
```php
|
||||
$metaData = array(
|
||||
"user" => array(
|
||||
"name" => "James",
|
||||
"email" => "james@example.com"
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
### Configuration Options
|
||||
|
||||
The [Bugsnag PHP Client](https://bugsnag.com/docs/notifiers/php)
|
||||
is available as `Bugsnag`, which allows you to set various
|
||||
configuration options. These options are listed in the
|
||||
[documentation for Bugsnag PHP](https://bugsnag.com/docs/notifiers/php#additional-options).
|
||||
|
||||
#### Error Reporting Levels
|
||||
|
||||
By default we'll use the value of `error_reporting` from your `php.ini`
|
||||
or any value you set at runtime using the `error_reporting(...)` function.
|
||||
|
||||
If you'd like to send different levels of errors to Bugsnag, you can call
|
||||
`setErrorReportingLevel`, for example:
|
||||
|
||||
```php
|
||||
Bugsnag::setErrorReportingLevel(E_ALL & ~E_NOTICE);
|
||||
```
|
||||
|
||||
#### Callbacks
|
||||
|
||||
It is often useful to send additional meta-data about your app, such as
|
||||
information about the currently logged in user, along with any
|
||||
error or exceptions, to help debug problems.
|
||||
|
||||
To send custom data, you should define a *before-notify* function,
|
||||
adding an array of "tabs" of custom data to the $metaData parameter. For example:
|
||||
|
||||
```php
|
||||
Bugsnag::setBeforeNotifyFunction("before_bugsnag_notify");
|
||||
|
||||
function before_bugsnag_notify($error) {
|
||||
// Do any custom error handling here
|
||||
|
||||
// Also add some meta data to each error
|
||||
$error->setMetaData(array(
|
||||
"user" => array(
|
||||
"name" => "James",
|
||||
"email" => "james@example.com"
|
||||
)
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
This example snippet adds a "user" tab to the Bugsnag error report. See the
|
||||
[setBeforeNotifyFunction](https://bugsnag.com/docs/notifiers/php#setbeforenotifyfunction)
|
||||
documentation on the `bugsnag-php` library for more information.
|
||||
|
||||
|
||||
Demo Applications
|
||||
-----------------
|
||||
|
||||
The [Bugsnag Laravel source
|
||||
repository](https://github.com/bugsnag/bugsnag-laravel) includes example
|
||||
applications for [Laravel 4, Laravel 5, and
|
||||
Lumen](https://github.com/bugsnag/bugsnag-laravel/tree/master/example).
|
||||
|
||||
Before running one of the example applications, install the prerequisites:
|
||||
|
||||
brew tap josegonzalez/homebrew-php
|
||||
brew install php56 php56-mcrypt composer
|
||||
|
||||
Then open the example directory (such as `example/laravel-5.1`) in a terminal
|
||||
and start the server:
|
||||
|
||||
composer install
|
||||
php56 artisan serve --port 8004
|
||||
|
||||
|
||||
Support
|
||||
-------
|
||||
|
||||
* [Additional Documentation](https://github.com/bugsnag/bugsnag-laravel/tree/master/docs)
|
||||
* [Search open and closed issues](https://github.com/bugsnag/bugsnag-laravel/issues?utf8=✓&q=is%3Aissue) for similar problems
|
||||
* [Report a bug or request a feature](https://github.com/bugsnag/bugsnag-laravel/issues/new)
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
We'd love you to file issues and send pull requests. The [contributing
|
||||
guidelines](https://github.com/bugsnag/bugsnag-laravel/CONTRIBUTING.md) details
|
||||
the process of building and testing `bugsnag-laravel`, as well as the pull
|
||||
request process. Feel free to comment on [existing
|
||||
issues](https://github.com/bugsnag/bugsnag-laravel/issues) for clarification or
|
||||
starting points.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The Bugsnag Laravel notifier is free software released under the MIT License.
|
||||
See [LICENSE.txt](LICENSE.txt) for details.
|
23
vendor/bugsnag/bugsnag-laravel/composer.json
vendored
23
vendor/bugsnag/bugsnag-laravel/composer.json
vendored
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "bugsnag/bugsnag-laravel",
|
||||
"description": "Official Bugsnag notifier for Laravel applications.",
|
||||
"keywords": ["bugsnag", "exceptions", "errors", "logging", "tracking", "laravel"],
|
||||
"homepage": "https://github.com/bugsnag/bugsnag-laravel",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "James Smith",
|
||||
"email": "notifiers@bugsnag.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/support": "4.*|5.*",
|
||||
"bugsnag/bugsnag": ">=2.5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Bugsnag\\BugsnagLaravel\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
11
vendor/bugsnag/bugsnag-laravel/provides.json
vendored
11
vendor/bugsnag/bugsnag-laravel/provides.json
vendored
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"providers": [
|
||||
"Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider"
|
||||
],
|
||||
"aliases": [
|
||||
{
|
||||
"alias": "Bugsnag",
|
||||
"facade": "Bugsnag\BugsnagLaravel\BugsnagFacade"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
<?php namespace Bugsnag\BugsnagLaravel;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class BugsnagExceptionHandler extends ExceptionHandler {
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
{
|
||||
foreach ($this->dontReport as $type) {
|
||||
if ($e instanceof $type) {
|
||||
return parent::report($e);
|
||||
}
|
||||
}
|
||||
|
||||
if (app()->bound('bugsnag')) {
|
||||
app('bugsnag')->notifyException($e, null, "error");
|
||||
}
|
||||
|
||||
return parent::report($e);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<?php namespace Bugsnag\BugsnagLaravel;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class BugsnagFacade extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'bugsnag';
|
||||
}
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
<?php namespace Bugsnag\BugsnagLaravel;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BugsnagLaravelServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
|
||||
$app = $this->app;
|
||||
|
||||
if (version_compare($app::VERSION, '5.0') < 0) {
|
||||
|
||||
$this->package('bugsnag/bugsnag-laravel', 'bugsnag');
|
||||
|
||||
// Register for exception handling
|
||||
$app->error(function (\Exception $exception) use ($app) {
|
||||
if ('Symfony\Component\Debug\Exception\FatalErrorException'
|
||||
!== get_class($exception)
|
||||
) {
|
||||
$app['bugsnag']->notifyException($exception, null, "error");
|
||||
}
|
||||
});
|
||||
|
||||
// Register for fatal error handling
|
||||
$app->fatal(function ($exception) use ($app) {
|
||||
$app['bugsnag']->notifyException($exception, null, "error");
|
||||
});
|
||||
} else {
|
||||
$this->publishes(array(
|
||||
__DIR__.'/config.php' => config_path('bugsnag.php'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('bugsnag', function ($app) {
|
||||
$config = isset($app['config']['services']['bugsnag']) ? $app['config']['services']['bugsnag'] : null;
|
||||
if (is_null($config)) {
|
||||
$config = $app['config']['bugsnag'] ?: $app['config']['bugsnag::config'];
|
||||
}
|
||||
|
||||
$client = new \Bugsnag_Client($config['api_key']);
|
||||
$client->setStripPath(base_path());
|
||||
$client->setProjectRoot(app_path());
|
||||
$client->setAutoNotify(false);
|
||||
$client->setBatchSending(false);
|
||||
$client->setReleaseStage($app->environment());
|
||||
$client->setNotifier(array(
|
||||
'name' => 'Bugsnag Laravel',
|
||||
'version' => '1.6.3',
|
||||
'url' => 'https://github.com/bugsnag/bugsnag-laravel'
|
||||
));
|
||||
|
||||
if (isset($config['notify_release_stages']) && is_array($config['notify_release_stages'])) {
|
||||
$client->setNotifyReleaseStages($config['notify_release_stages']);
|
||||
}
|
||||
|
||||
if (isset($config['endpoint'])) {
|
||||
$client->setEndpoint($config['endpoint']);
|
||||
}
|
||||
|
||||
if (isset($config['filters']) && is_array($config['filters'])) {
|
||||
$client->setFilters($config['filters']);
|
||||
}
|
||||
|
||||
if (isset($config['proxy']) && is_array($config['proxy'])) {
|
||||
$client->setProxySettings($config['proxy']);
|
||||
}
|
||||
|
||||
// Check if someone is logged in.
|
||||
try {
|
||||
if ($app['auth']->check()) {
|
||||
// User is logged in.
|
||||
$user = $app['auth']->user();
|
||||
|
||||
// If these attributes are available: pass them on.
|
||||
$client->setUser(array('id' => $user->getAuthIdentifier()));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return $client;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array("bugsnag");
|
||||
}
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
<?php namespace Bugsnag\BugsnagLaravel;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BugsnagLumenServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app->configure('bugsnag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('bugsnag', function ($app) {
|
||||
$config = isset($app['config']['services']['bugsnag']) ? $app['config']['services']['bugsnag'] : null;
|
||||
if (is_null($config)) {
|
||||
$config = $app['config']['bugsnag'] ?: $app['config']['bugsnag::config'];
|
||||
}
|
||||
|
||||
$client = new \Bugsnag_Client($config['api_key']);
|
||||
$client->setStripPath(base_path());
|
||||
$client->setProjectRoot(base_path() . '/app');
|
||||
$client->setAutoNotify(false);
|
||||
$client->setBatchSending(false);
|
||||
$client->setReleaseStage($app->environment());
|
||||
$client->setNotifier(array(
|
||||
'name' => 'Bugsnag Lumen',
|
||||
'version' => '1.6.3',
|
||||
'url' => 'https://github.com/bugsnag/bugsnag-laravel'
|
||||
));
|
||||
|
||||
if (isset($config['notify_release_stages']) && is_array($config['notify_release_stages'])) {
|
||||
$client->setNotifyReleaseStages($config['notify_release_stages']);
|
||||
}
|
||||
|
||||
if (isset($config['endpoint'])) {
|
||||
$client->setEndpoint($config['endpoint']);
|
||||
}
|
||||
|
||||
if (isset($config['filters']) && is_array($config['filters'])) {
|
||||
$client->setFilters($config['filters']);
|
||||
}
|
||||
|
||||
if (isset($config['proxy']) && is_array($config['proxy'])) {
|
||||
$client->setProxySettings($config['proxy']);
|
||||
}
|
||||
|
||||
// Check if someone is logged in.
|
||||
try {
|
||||
if ($app['auth']->check()) {
|
||||
// User is logged in.
|
||||
$user = $app['auth']->user();
|
||||
|
||||
// If these attributes are available: pass them on.
|
||||
$client->setUser(array('id' => $user->getAuthIdentifier()));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return $client;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array("bugsnag");
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You can find your API key on your Bugsnag dashboard.
|
||||
|
|
||||
| This api key points the Bugsnag notifier to the project in your account
|
||||
| which should receive your application's uncaught exceptions.
|
||||
|
|
||||
*/
|
||||
'api_key' => env('BUGSNAG_API_KEY'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Notify Release Stages
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Set which release stages should send notifications to Bugsnag.
|
||||
|
|
||||
| Example: array('development', 'production')
|
||||
|
|
||||
*/
|
||||
'notify_release_stages' => env('BUGSNAG_NOTIFY_RELEASE_STAGES', null),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Endpoint
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Set what server the Bugsnag notifier should send errors to. By default
|
||||
| this is set to 'https://notify.bugsnag.com', but for Bugsnag Enterprise
|
||||
| this should be the URL to your Bugsnag instance.
|
||||
|
|
||||
*/
|
||||
'endpoint' => env('BUGSNAG_ENDPOINT', null),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Use this if you want to ensure you don't send sensitive data such as
|
||||
| passwords, and credit card numbers to our servers. Any keys which
|
||||
| contain these strings will be filtered.
|
||||
|
|
||||
*/
|
||||
'filters' => env('BUGSNAG_FILTERS', array('password')),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Proxy
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your server is behind a proxy server, you can configure this as well.
|
||||
| Other than the host, none of these settings are mandatory.
|
||||
|
|
||||
| Note: Proxy configuration is only possible if the PHP cURL extension
|
||||
| is installed.
|
||||
|
|
||||
| Example:
|
||||
|
|
||||
| 'proxy' => array(
|
||||
| 'host' => 'bugsnag.com',
|
||||
| 'port' => 42,
|
||||
| 'user' => 'username',
|
||||
| 'password' => 'password123'
|
||||
| )
|
||||
|
|
||||
*/
|
||||
'proxy' => env('BUGSNAG_PROXY', null)
|
||||
|
||||
);
|
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You can find your API key on your Bugsnag dashboard.
|
||||
|
|
||||
| This api key points the Bugsnag notifier to the project in your account
|
||||
| which should receive your application's uncaught exceptions.
|
||||
|
|
||||
*/
|
||||
'api_key' => 'YOUR-API-KEY-HERE',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Notify Release Stages
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Set which release stages should send notifications to Bugsnag.
|
||||
|
|
||||
| Example: array('development', 'production')
|
||||
|
|
||||
*/
|
||||
'notify_release_stages' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Endpoint
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Set what server the Bugsnag notifier should send errors to. By default
|
||||
| this is set to 'https://notify.bugsnag.com', but for Bugsnag Enterprise
|
||||
| this should be the URL to your Bugsnag instance.
|
||||
|
|
||||
*/
|
||||
'endpoint' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Use this if you want to ensure you don't send sensitive data such as
|
||||
| passwords, and credit card numbers to our servers. Any keys which
|
||||
| contain these strings will be filtered.
|
||||
|
|
||||
*/
|
||||
'filters' => array('password'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Proxy
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your server is behind a proxy server, you can configure this as well.
|
||||
| Other than the host, none of these settings are mandatory.
|
||||
|
|
||||
| Note: Proxy configuration is only possible if the PHP cURL extension
|
||||
| is installed.
|
||||
|
|
||||
| Example:
|
||||
|
|
||||
| 'proxy' => array(
|
||||
| 'host' => 'bugsnag.com',
|
||||
| 'port' => 42,
|
||||
| 'user' => 'username',
|
||||
| 'password' => 'password123'
|
||||
| )
|
||||
|
|
||||
*/
|
||||
'proxy' => null
|
||||
|
||||
);
|
13
vendor/bugsnag/bugsnag/.editorconfig
vendored
13
vendor/bugsnag/bugsnag/.editorconfig
vendored
@@ -1,13 +0,0 @@
|
||||
# http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
4
vendor/bugsnag/bugsnag/.gitignore
vendored
4
vendor/bugsnag/bugsnag/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/vendor
|
||||
/composer.lock
|
||||
/composer.phar
|
||||
/.idea
|
10
vendor/bugsnag/bugsnag/.travis.yml
vendored
10
vendor/bugsnag/bugsnag/.travis.yml
vendored
@@ -1,10 +0,0 @@
|
||||
sudo: false
|
||||
language: php
|
||||
php:
|
||||
- 7.0
|
||||
- 5.6
|
||||
- 5.5
|
||||
- 5.4
|
||||
- 5.3
|
||||
- 5.2
|
||||
- hhvm
|
209
vendor/bugsnag/bugsnag/CHANGELOG.md
vendored
209
vendor/bugsnag/bugsnag/CHANGELOG.md
vendored
@@ -1,209 +0,0 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
2.6.1 (2016-01-28)
|
||||
-----
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixes an error thrown when sending an `Error` instance using PHP 7
|
||||
[Petr Bugyík](https://github.com/o5)
|
||||
[#110](https://github.com/bugsnag/bugsnag-php/pull/110)
|
||||
|
||||
2.6.0 (23 Dec 2015)
|
||||
-----
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add support for PHP 7's Throwable
|
||||
| [Chris Stone](https://github.com/cmstone)
|
||||
| [#106](https://github.com/bugsnag/bugsnag-php/pull/106)
|
||||
|
||||
* Fix errors which arise from from error payloads not encoded using UTF-8
|
||||
| [GaetanNaulin](https://github.com/GaetanNaulin)
|
||||
| [#104](https://github.com/bugsnag/bugsnag-php/pull/104)
|
||||
| [#105](https://github.com/bugsnag/bugsnag-php/pull/105)
|
||||
|
||||
2.5.6
|
||||
-----
|
||||
- Added a debug flag to help diagnose notification problems
|
||||
|
||||
2.5.5
|
||||
-----
|
||||
- Ensure no unnecessary code is executed when errors should be skipped
|
||||
|
||||
2.5.4
|
||||
-----
|
||||
- Fix HHVM support for release 2.5.3
|
||||
|
||||
2.5.3
|
||||
-----
|
||||
- Add support for custom curl options
|
||||
|
||||
2.5.2
|
||||
-----
|
||||
- Add support for setHostname
|
||||
|
||||
2.5.1
|
||||
-----
|
||||
- Extract file and line numbers better for crashes in eval'd code
|
||||
|
||||
2.5.0
|
||||
-----
|
||||
- Collect and send snippets of source code to Bugsnag for easier debugging
|
||||
- Update `setEndpoint` to accept full URLs
|
||||
- Add support for `Error#setGroupingHash` to customize error grouping in
|
||||
`setBeforeNotify` functions
|
||||
|
||||
2.4.0
|
||||
-----
|
||||
- Don't send $_ENV by default
|
||||
|
||||
2.3.1
|
||||
-----
|
||||
- Warn if neither curl or fopen are available
|
||||
|
||||
2.3.0
|
||||
-----
|
||||
- Remove cURL requirement, fallback to using fopen() if cURL not available
|
||||
|
||||
2.2.10
|
||||
------
|
||||
- Remove default for `setProjectRoot` since it was sometimes overzealous
|
||||
|
||||
2.2.9
|
||||
-----
|
||||
- Fix boolean metadata handling
|
||||
|
||||
2.2.8
|
||||
-----
|
||||
- Fix various metadata-encoding bugs
|
||||
|
||||
2.2.7
|
||||
-----
|
||||
- Allow configuration of projectRoot stripping from stacktraces
|
||||
|
||||
2.2.6
|
||||
-----
|
||||
- Fix calling `mb_detect_encoding` on non-objects
|
||||
|
||||
2.2.5
|
||||
-----
|
||||
- Remove deprecated "fatal" severity state
|
||||
|
||||
2.2.4
|
||||
-----
|
||||
- Prepare 'severity' feature for release
|
||||
|
||||
2.2.3
|
||||
-----
|
||||
- Fix invalid utf-8 errors for people using iso-8859-1 by default.
|
||||
|
||||
2.2.2
|
||||
-----
|
||||
- Make frames public on the stacktrace.
|
||||
|
||||
2.2.1
|
||||
-----
|
||||
- Log any curl errors to the command line, increase default timeout to 10s
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
- Support previous exceptions on PHP >= 5.3.0
|
||||
- Allow overriding notifier
|
||||
- Use manual loading in place of custom autoloading
|
||||
|
||||
2.1.4
|
||||
-----
|
||||
- Make cURL timeout configurable (thanks pauloschilling)
|
||||
|
||||
2.1.3
|
||||
-----
|
||||
- Fix crash during stacktrace generation that happened when a closure was
|
||||
the first stackframe.
|
||||
|
||||
2.1.2
|
||||
-----
|
||||
- Add `ErrorTypes::getLevelsForSeverity` function to fetch an
|
||||
`error_reporting` bitmask for a particular Bugsnag severity
|
||||
|
||||
2.1.1
|
||||
-----
|
||||
- Fix crash during stacktrace generation for frameworks that have their own
|
||||
`shutdown_handler` method (eg. Laravel)
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
- Add `setAppType` for sending app type (script, request, resque, etc)
|
||||
- Add `setUser` for sending structured user data
|
||||
- Automatically send the severity level of each PHP error
|
||||
- Added ability to chain setters (eg $bugsnag->setUser(...)->setReleaseStage(...))
|
||||
|
||||
2.0.4
|
||||
-----
|
||||
- Add hostname collection to help with debugging
|
||||
|
||||
2.0.3
|
||||
-----
|
||||
- Add `setBatchSending` function to disable batch sending of errors at the
|
||||
end of each request
|
||||
|
||||
2.0.2
|
||||
-----
|
||||
- Fix bug which caused `setNotifyReleaseStages` being ignored
|
||||
|
||||
2.0.1
|
||||
-----
|
||||
- Fix minor request meta-data issues introduced in 2.0.0
|
||||
|
||||
2.0.0
|
||||
-----
|
||||
- Backwards-incompatible rewrite (using non-static access)
|
||||
- Full suite of tests and Travis CI testing on PHP 5.2+
|
||||
- Add `setBeforeNotify` functionality to add meta-data or execute code
|
||||
before each error is sent to Bugsnag
|
||||
|
||||
1.0.9
|
||||
-----
|
||||
- Add `setAutoNotify` function to allow disabling of automatic error handling
|
||||
- Fix bug where error reporting level was being ignored for fatal errors
|
||||
|
||||
1.0.8
|
||||
-----
|
||||
- Added a `setMetaData` function for sending custom data with every error
|
||||
|
||||
1.0.7
|
||||
-----
|
||||
- Don't default `notifyReleaseStages` to anything to reduce confusion
|
||||
|
||||
1.0.6
|
||||
-----
|
||||
- Fix PHP 5.2 bug with missing constants
|
||||
|
||||
1.0.5
|
||||
-----
|
||||
- Protect against missing $_SERVER variables
|
||||
|
||||
1.0.4
|
||||
-----
|
||||
- Send JSON POST params to Bugsnag if available
|
||||
- Send HTTP headers to Bugsnag if available
|
||||
|
||||
1.0.3
|
||||
-----
|
||||
- Remove unnecessary post to Bugsnag when error list is empty
|
||||
|
||||
1.0.2
|
||||
-----
|
||||
- Fix bug with 'internal' stacktrace lines (missing line/file)
|
||||
|
||||
1.0.1
|
||||
-----
|
||||
- Renamed default error classes for clarity
|
||||
- Batch-send errors at the end of each request
|
||||
- `Bugsnag::errorHandler` now respects PHP's `error_reporting` settings
|
||||
- Added `setErrorReportingLevel` function to override PHP's error_reporting settings
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
- First public release
|
48
vendor/bugsnag/bugsnag/CONTRIBUTING.md
vendored
48
vendor/bugsnag/bugsnag/CONTRIBUTING.md
vendored
@@ -1,48 +0,0 @@
|
||||
Contributing
|
||||
============
|
||||
|
||||
- [Fork](https://help.github.com/articles/fork-a-repo) the [notifier on github](https://github.com/bugsnag/bugsnag-laravel)
|
||||
- Build and test your changes. Run the tests using [phpunit](https://phpunit.de) (vendored to `vendor/bin/phpunit`)
|
||||
- Commit and push until you are happy with your contribution
|
||||
- [Make a pull request](https://help.github.com/articles/using-pull-requests)
|
||||
- Thanks!
|
||||
|
||||
Example apps
|
||||
============
|
||||
|
||||
Test the notifier by running the application locally.
|
||||
|
||||
[Install composer](http://getcomposer.org/doc/01-basic-usage.md), and then cd into `example/php` and start the server:
|
||||
|
||||
composer install
|
||||
php index.php
|
||||
|
||||
|
||||
Releasing
|
||||
=========
|
||||
|
||||
1. Commit all outstanding changes
|
||||
2. Bump the version in `src/Bugsnag/Configuration.php`.
|
||||
3. Update the CHANGELOG.md, and README if appropriate.
|
||||
4. Build a new phar package
|
||||
* NB: You may need to set `phar.readonly = Off` in /usr/local/etc/php/5.4/php.ini
|
||||
* If not located in /usr/local/etc, check /private/etc/php.ini
|
||||
* If not in /private/etc/php.ini:
|
||||
|
||||
```
|
||||
sudo cp /private/etc/php.ini.default /private/etc/php.ini
|
||||
```
|
||||
* Then:
|
||||
|
||||
```
|
||||
composer install
|
||||
php pharbuilder.php
|
||||
```
|
||||
|
||||
4. Commit, tag push
|
||||
|
||||
```
|
||||
git commit -am v2.x.x
|
||||
git tag v2.x.x
|
||||
git push origin master && git push --tags
|
||||
```
|
20
vendor/bugsnag/bugsnag/LICENSE.txt
vendored
20
vendor/bugsnag/bugsnag/LICENSE.txt
vendored
@@ -1,20 +0,0 @@
|
||||
Copyright (c) 2013 Bugsnag
|
||||
|
||||
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.
|
481
vendor/bugsnag/bugsnag/README.md
vendored
481
vendor/bugsnag/bugsnag/README.md
vendored
@@ -1,481 +0,0 @@
|
||||
Bugsnag Notifier for PHP <img src="https://travis-ci.org/bugsnag/bugsnag-php.svg?branch=master" alt="build status" class="build-status">
|
||||
========================
|
||||
|
||||
The Bugsnag Notifier for PHP gives you instant notification of errors and
|
||||
exceptions in your PHP applications.
|
||||
|
||||
[Bugsnag](https://bugsnag.com) captures errors in real-time from your web,
|
||||
mobile and desktop applications, helping you to understand and resolve them
|
||||
as fast as possible. [Create a free account](https://bugsnag.com) to start
|
||||
capturing errors from your applications.
|
||||
|
||||
The Bugsnag Notifier for PHP supports PHP 5.2+.
|
||||
|
||||
|
||||
How to Install
|
||||
--------------
|
||||
|
||||
### Using [Composer](http://getcomposer.org/) (Recommended)
|
||||
|
||||
1. Install the `bugsnag/bugsnag-php` package:
|
||||
|
||||
```shell
|
||||
$ composer require "bugsnag/bugsnag:2.*"
|
||||
```
|
||||
|
||||
### Using Phar Package
|
||||
|
||||
1. Download the latest [bugsnag.phar](https://raw.github.com/bugsnag/bugsnag-php/master/build/bugsnag.phar)
|
||||
to your PHP project.
|
||||
|
||||
2. Require it in your app.
|
||||
|
||||
```php
|
||||
require_once "/path/to/bugsnag.phar";
|
||||
```
|
||||
|
||||
### Manual Installation
|
||||
|
||||
1. Download and extract the [latest Bugsnag source code](https://github.com/bugsnag/bugsnag-php/archive/master.zip)
|
||||
to your PHP project.
|
||||
|
||||
2. Require it in your app using the provided autoloader.
|
||||
|
||||
```php
|
||||
require_once "/path/to/Bugsnag/Autoload.php";
|
||||
```
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
1. Configure Bugsnag with your API key:
|
||||
|
||||
```php
|
||||
$bugsnag = new Bugsnag_Client('YOUR-API-KEY-HERE');
|
||||
```
|
||||
|
||||
2. Enable automatic error and exception notification by attaching Bugsnag's
|
||||
error and exception handlers:
|
||||
|
||||
```php
|
||||
set_error_handler(array($bugsnag, 'errorHandler'));
|
||||
set_exception_handler(array($bugsnag, 'exceptionHandler'));
|
||||
```
|
||||
|
||||
If you app or PHP framework already has error handling functions, you can
|
||||
also call `$bugsnag->errorHandler` and `$bugsnag->exceptionHandler`
|
||||
directly from your existing functions, simply pass all parameters through.
|
||||
|
||||
|
||||
Sending Custom Data With Exceptions
|
||||
-----------------------------------
|
||||
|
||||
It is often useful to send additional meta-data about your app, such as
|
||||
information about the currently logged in user, along with any
|
||||
error or exceptions, to help debug problems.
|
||||
|
||||
Bugsnag supports sending user information, such as the user's name or email
|
||||
address, by calling the [setUser](#setUser) function.
|
||||
|
||||
To send other custom data, you should define a *before-notify* function,
|
||||
adding an array of "tabs" of custom data to the $metaData parameter.
|
||||
For an example, see the [setBeforeNotifyFunction](#setbeforenotifyfunction)
|
||||
documentation below.
|
||||
|
||||
|
||||
Sending Custom Errors or Non-Fatal Exceptions
|
||||
---------------------------------------------
|
||||
|
||||
You can easily tell Bugsnag about non-fatal or caught exceptions by
|
||||
calling `notifyException`:
|
||||
|
||||
```php
|
||||
$bugsnag->notifyException(new Exception('Something bad happened'));
|
||||
```
|
||||
|
||||
You can also send custom errors to Bugsnag with `notifyError`:
|
||||
|
||||
```php
|
||||
$bugsnag->notifyError('ErrorType', 'Something bad happened here too');
|
||||
```
|
||||
|
||||
Both of these functions can also be passed an optional `$metaData` parameter,
|
||||
which should take the following format:
|
||||
|
||||
```php
|
||||
$metaData = array(
|
||||
'account' => array(
|
||||
'paying' => true,
|
||||
'name' => 'Acme Co'
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
### Severity
|
||||
|
||||
You can set the severity of an error in Bugsnag by including the severity option as the fourth parameter when
|
||||
notifying bugsnag of the error,
|
||||
|
||||
```php
|
||||
$bugsnag->notifyError('ErrorType', 'Something bad happened here too', NULL, "error")
|
||||
```
|
||||
|
||||
Valid severities are `error`, `warning` and `info`.
|
||||
|
||||
Severity is displayed in the dashboard and can be used to filter the error list.
|
||||
By default all crashes (or unhandled exceptions) are set to `error` and all
|
||||
`$bugsnag->notify` calls default to `warning`.
|
||||
|
||||
|
||||
Additional Configuration
|
||||
------------------------
|
||||
|
||||
###setUser
|
||||
|
||||
Bugsnag helps you understand how many of your users are affected by each
|
||||
error, and allows you to search for which errors affect a particular user
|
||||
using your Bugsnag dashboard. To send useful user-specific information you can
|
||||
call `setUser`:
|
||||
|
||||
```php
|
||||
$bugsnag->setUser(array(
|
||||
'name' => 'Leeroy Jenkins',
|
||||
'email' => 'leeeeroy@jenkins.com'
|
||||
));
|
||||
```
|
||||
|
||||
The `name`, `email` and `id` fields are searchable, and everything you send in
|
||||
this array will be displayed on your Bugsnag dashboard.
|
||||
|
||||
The `id` field is used also used by Bugsnag to determine the number of
|
||||
impacted users. By default, we use the IP address of the request as the `id`.
|
||||
|
||||
###setReleaseStage
|
||||
|
||||
If you would like to distinguish between errors that happen in different
|
||||
stages of the application release process (development, production, etc)
|
||||
you can set the `releaseStage` that is reported to Bugsnag.
|
||||
|
||||
```php
|
||||
$bugsnag->setReleaseStage('development');
|
||||
```
|
||||
|
||||
By default this is set to "production".
|
||||
|
||||
|
||||
###setNotifyReleaseStages
|
||||
|
||||
By default, we will notify Bugsnag of errors that happen in *any*
|
||||
`releaseStage` If you would like to change which release stages notify
|
||||
Bugsnag of errors you can call `setNotifyReleaseStages`:
|
||||
|
||||
```php
|
||||
$bugsnag->setNotifyReleaseStages(array('development', 'production'));
|
||||
```
|
||||
|
||||
###setMetaData
|
||||
|
||||
Sets additional meta-data to send with every bugsnag notification,
|
||||
for example:
|
||||
|
||||
```php
|
||||
$bugsnag->setMetaData(array(
|
||||
'account' => array(
|
||||
'paying' => true,
|
||||
'name' => 'Acme Co'
|
||||
)
|
||||
));
|
||||
```
|
||||
|
||||
###setContext
|
||||
|
||||
Bugsnag uses the concept of "contexts" to help display and group your
|
||||
errors. Contexts represent what was happening in your application at the
|
||||
time an error occurs. By default this will be set to the current request
|
||||
URL and HTTP method, eg "GET /pages/documentation".
|
||||
|
||||
If you would like to set the bugsnag context manually, you can call
|
||||
`setContext`:
|
||||
|
||||
```php
|
||||
$bugsnag->setContext('Backport Job');
|
||||
```
|
||||
|
||||
###setType
|
||||
|
||||
You can set the type of application executing the current code by using
|
||||
`setType`:
|
||||
|
||||
```php
|
||||
$bugsnag->setType('resque');
|
||||
```
|
||||
|
||||
This is usually used to represent if you are running plain PHP code "php", via
|
||||
a framework, eg "laravel", or executing through delayed worker code,
|
||||
eg "resque". By default this is `NULL`.
|
||||
|
||||
###setFilters
|
||||
|
||||
Sets the strings to filter out from the `metaData` arrays before sending
|
||||
them to Bugsnag. Use this if you want to ensure you don't send
|
||||
sensitive data such as passwords, and credit card numbers to our
|
||||
servers. Any keys which contain these strings will be filtered.
|
||||
|
||||
```php
|
||||
$bugsnag->setFilters(array('password', 'credit_card'));
|
||||
```
|
||||
|
||||
By default, this is set to be `array("password")`.
|
||||
|
||||
###setEndpoint
|
||||
|
||||
Set the endpoint to send error reports to. By default we'll send reports to
|
||||
the standard `https://notify.bugsnag.com` endpoint, but you can override this
|
||||
if you are using [Bugsnag Enterprise](https://bugsnag.com/enterprise), to
|
||||
point to your own Bugsnag endpoint:
|
||||
|
||||
```php
|
||||
$bugsnag->setEndpoint("http://bugsnag.internal.example.com");
|
||||
```
|
||||
|
||||
###setTimeout
|
||||
|
||||
> Note: Timeout configuration is only possible if the PHP cURL extension is installed.
|
||||
|
||||
Define a custom timeout, in seconds, for cURL connection when notifying bugsnag.com.
|
||||
|
||||
```php
|
||||
$bugsnag->setTimeout(2);
|
||||
```
|
||||
|
||||
By default, this is set to be `2`.
|
||||
|
||||
###setBeforeNotifyFunction
|
||||
|
||||
Set a custom function to call before notifying Bugsnag of an error.
|
||||
You can use this to call your own error handling functions, to add custom
|
||||
tabs of data to each error on your Bugsnag dashboard, or to modify the
|
||||
stacktrace.
|
||||
|
||||
To add custom tabs of meta-data, simply add to the `$metaData` array
|
||||
that is passed as the first parameter to your function, for example:
|
||||
|
||||
```php
|
||||
$bugsnag->setBeforeNotifyFunction('before_bugsnag_notify');
|
||||
|
||||
function before_bugsnag_notify(Bugsnag_Error $error) {
|
||||
// Do any custom error handling here
|
||||
|
||||
// Also add some meta data to each error
|
||||
$error->setMetaData(array(
|
||||
"user" => array(
|
||||
"name" => "James",
|
||||
"email" => "james@example.com"
|
||||
)
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
If Bugsnag is called by a wrapper library, you can remove stack frames from the
|
||||
back-trace. For example:
|
||||
|
||||
```php
|
||||
function before_bugsnag_notify(Bugsnag_Error $error) {
|
||||
|
||||
$firstFrame = $error->stacktrace->frames[0];
|
||||
if ($firstFrame && $firstFrame['file'] === 'My_Logger.php') {
|
||||
array_splice($error->stacktrace->frames, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
You can also return `FALSE` from your beforeNotifyFunction to stop this error
|
||||
from being sent to bugsnag.
|
||||
|
||||
###setAutoNotify
|
||||
|
||||
Controls whether bugsnag should automatically notify about any errors it detects in
|
||||
the PHP error handlers.
|
||||
|
||||
```php
|
||||
$bugsnag->setAutoNotify(FALSE);
|
||||
```
|
||||
|
||||
By default, this is set to `TRUE`.
|
||||
|
||||
###setErrorReportingLevel
|
||||
|
||||
Set the levels of PHP errors to report to Bugsnag, by default we'll use
|
||||
the value of `error_reporting` from your `php.ini` or any value you set
|
||||
at runtime using the `error_reporting(...)` function.
|
||||
|
||||
If you'd like to send different levels of errors to Bugsnag, you can call
|
||||
`setErrorReportingLevel`:
|
||||
|
||||
```php
|
||||
$bugsnag->setErrorReportingLevel(E_ALL & ~E_NOTICE);
|
||||
```
|
||||
|
||||
See PHP's [error reporting documentation](http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting)
|
||||
for allowed values.
|
||||
|
||||
<!-- Custom anchor for linking from alerts -->
|
||||
<div id="set-project-root"></div>
|
||||
###setProjectRoot
|
||||
|
||||
We mark stacktrace lines as in-project if they come from files inside your
|
||||
`projectRoot`. By default this value is automatically set to be
|
||||
`$_SERVER['DOCUMENT_ROOT']` but sometimes this can cause problems with
|
||||
stacktrace highlighting. You can set this manually by calling `setProjectRoot`:
|
||||
|
||||
```php
|
||||
$bugsnag->setProjectRoot('/path/to/your/app');
|
||||
```
|
||||
|
||||
If your app has files in many different locations, you should consider using
|
||||
[setProjectRootRegex](#setprojectrootregex) instead.
|
||||
|
||||
###setProjectRootRegex
|
||||
|
||||
If your app has files in many different locations, you can set the a regular
|
||||
expression for matching filenames in stacktrace lines that are part of your
|
||||
application:
|
||||
|
||||
```php
|
||||
$bugsnag->setProjectRootRegex('('.preg_quote('/app').'|'.preg_quote('/libs').')');
|
||||
```
|
||||
|
||||
###setProxySettings
|
||||
|
||||
> Note: Proxy configuration is only possible if the PHP cURL extension is installed.
|
||||
|
||||
If your server is behind a proxy server, you can configure this as well:
|
||||
|
||||
```php
|
||||
$bugsnag->setProxySettings(array(
|
||||
'host' => 'bugsnag.com',
|
||||
'port' => 42,
|
||||
'user' => 'username',
|
||||
'password' => 'password123'
|
||||
));
|
||||
```
|
||||
|
||||
Other than the host, none of these settings are mandatory.
|
||||
|
||||
###setAppVersion
|
||||
|
||||
If you tag your app releases with version numbers, Bugsnag can display these
|
||||
on your dashboard if you call `setAppVersion`:
|
||||
|
||||
```php
|
||||
$bugsnag->setAppVersion('1.2.3');
|
||||
```
|
||||
|
||||
###setSendEnvironment
|
||||
|
||||
Bugsnag can transmit your `$_ENV` environment to help diagnose issues. This can
|
||||
contain private/sensitive information, so we do not transmit this by default. To
|
||||
send your environment, you can call `setSendEnvironment`:
|
||||
|
||||
```php
|
||||
$bugsnag->setSendEnvironment(true);
|
||||
```
|
||||
|
||||
###setSendCode
|
||||
|
||||
Bugsnag automatically sends a small snippet of the code that crashed to help
|
||||
you diagnose even faster from within your dashboard. If you don't want to send
|
||||
this snippet, you can call `setSendCode`:
|
||||
|
||||
```php
|
||||
$bugsnag->setSendCode(false);
|
||||
```
|
||||
|
||||
###setGroupingHash
|
||||
|
||||
Sets the grouping hash of the error report. All errors with the same grouping hash are grouped together. This is an advanced usage of the library and mis-using it will cause your errors not to group properly in your dashboard.
|
||||
|
||||
```php
|
||||
$error->setGroupingHash($exception->message . $exception->class);
|
||||
```
|
||||
|
||||
PHP Frameworks
|
||||
--------------
|
||||
|
||||
### Laravel
|
||||
|
||||
Check out the [bugsnag-laravel](https://github.com/bugsnag/bugsnag-laravel) plugin.
|
||||
|
||||
### WordPress
|
||||
|
||||
Check out the [WordPress Error Monitoring by Bugsnag](http://wordpress.org/plugins/bugsnag/) plugin.
|
||||
|
||||
### CakePHP
|
||||
|
||||
Check out the third-party [Label305/bugsnag-cakephp](https://github.com/Label305/bugsnag-cakephp) plugin.
|
||||
|
||||
### Magento
|
||||
|
||||
Check out the official [Bugsnag Magento Extension](http://www.magentocommerce.com/magento-connect/bugsnag-notifier.html).
|
||||
|
||||
### Symfony2
|
||||
|
||||
Check out the third-party [evolution7/Evolution7BugsnagBundle](https://github.com/evolution7/Evolution7BugsnagBundle) or [wrep/bugsnag-php-symfony](https://github.com/wrep/bugsnag-php-symfony) bundles.
|
||||
|
||||
### Monolog
|
||||
Check out the 3rd party log handler for monolog: [meadsteve/MonoSnag/](https://github.com/meadsteve/MonoSnag/)
|
||||
|
||||
### Silverstripe
|
||||
|
||||
Check out the third-party [evolution7/silverstripe-bugsnag-logger](https://github.com/evolution7/silverstripe-bugsnag-logger) plugin.
|
||||
|
||||
### Zend Framework 2
|
||||
|
||||
Check out the third-party [nickurt/bugsnag-php](https://github.com/nickurt/zf-bugsnag) plugin.
|
||||
|
||||
|
||||
Building a Phar from Source
|
||||
---------------------------
|
||||
|
||||
- Install the composer dependencies
|
||||
|
||||
```shell
|
||||
$ composer install
|
||||
```
|
||||
|
||||
- Build the phar using `pharbuilder.php`. You may need to set `phar.readonly = Off` in your `php.ini`.
|
||||
|
||||
```shell
|
||||
php pharbuilder.php
|
||||
```
|
||||
|
||||
A new `bugsnag.phar` will be generated in the `build` folder.
|
||||
|
||||
|
||||
Reporting Bugs or Feature Requests
|
||||
----------------------------------
|
||||
|
||||
Please report any bugs or feature requests on the github issues page for this
|
||||
project here:
|
||||
|
||||
<https://github.com/bugsnag/bugsnag-php/issues>
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
- [Fork](https://help.github.com/articles/fork-a-repo) the [notifier on github](https://github.com/bugsnag/bugsnag-php)
|
||||
- Commit and push until you are happy with your contribution
|
||||
- Run the tests to make sure they all pass: `composer install && vendor/bin/phpunit`
|
||||
- [Make a pull request](https://help.github.com/articles/using-pull-requests)
|
||||
- Thanks!
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The Bugsnag PHP notifier is free software released under the MIT License.
|
||||
See [LICENSE.txt](https://github.com/bugsnag/bugsnag-php/blob/master/LICENSE.txt) for details.
|
BIN
vendor/bugsnag/bugsnag/build/bugsnag.phar
vendored
BIN
vendor/bugsnag/bugsnag/build/bugsnag.phar
vendored
Binary file not shown.
27
vendor/bugsnag/bugsnag/composer.json
vendored
27
vendor/bugsnag/bugsnag/composer.json
vendored
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"name": "bugsnag/bugsnag",
|
||||
"type": "library",
|
||||
"description": "Official Bugsnag notifier for PHP applications.",
|
||||
"keywords": ["bugsnag", "exceptions", "errors", "logging", "tracking"],
|
||||
"homepage": "https://github.com/bugsnag/bugsnag-php",
|
||||
"license": "MIT",
|
||||
"authors": [{
|
||||
"name": "James Smith",
|
||||
"email": "notifiers@bugsnag.com",
|
||||
"homepage": "https://bugsnag.com"
|
||||
}],
|
||||
|
||||
"require": {
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8|~5.0"
|
||||
},
|
||||
|
||||
"autoload": {
|
||||
"psr-0" : {
|
||||
"Bugsnag_" : "src/"
|
||||
}
|
||||
}
|
||||
}
|
16
vendor/bugsnag/bugsnag/example/php/README.md
vendored
16
vendor/bugsnag/bugsnag/example/php/README.md
vendored
@@ -1,16 +0,0 @@
|
||||
- Install composer
|
||||
|
||||
<http://getcomposer.org/doc/01-basic-usage.md>
|
||||
|
||||
- Install bugsnag using composer
|
||||
|
||||
```shell
|
||||
composer install
|
||||
```
|
||||
|
||||
- Add your API key to the example script
|
||||
- Run the example script
|
||||
|
||||
```shell
|
||||
php index.php
|
||||
```
|
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"require": {
|
||||
"bugsnag/bugsnag": "1.*"
|
||||
}
|
||||
}
|
8
vendor/bugsnag/bugsnag/example/php/index.php
vendored
8
vendor/bugsnag/bugsnag/example/php/index.php
vendored
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "../../build/bugsnag.phar";
|
||||
|
||||
$bugsnag = new Bugsnag_Client("YOUR-API-KEY-HERE");
|
||||
$bugsnag->notifyError("Broken", "Something broke", array("tab" => array("paying" => true, "object" => (object)array("key" => "value"), "null" => NULL, "string" => "test", "int" => 4)));
|
||||
|
||||
?>
|
12
vendor/bugsnag/bugsnag/pharbuilder.php
vendored
12
vendor/bugsnag/bugsnag/pharbuilder.php
vendored
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
function build_phar()
|
||||
{
|
||||
$phar = new Phar('build/bugsnag.phar');
|
||||
$phar->buildFromDirectory(dirname(__FILE__) . '/src','/\.php$/');
|
||||
$phar->compressFiles(Phar::GZ);
|
||||
$phar->stopBuffering();
|
||||
$phar->setStub($phar->createDefaultStub('Bugsnag/Autoload.php'));
|
||||
}
|
||||
|
||||
build_phar();
|
16
vendor/bugsnag/bugsnag/phpunit.xml
vendored
16
vendor/bugsnag/bugsnag/phpunit.xml
vendored
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<phpunit
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
bootstrap="./src/Bugsnag/Autoload.php">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Bugsnag tests">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
</phpunit>
|
15
vendor/bugsnag/bugsnag/src/Bugsnag/Autoload.php
vendored
15
vendor/bugsnag/bugsnag/src/Bugsnag/Autoload.php
vendored
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
# We used to have an autoloader, but it caused problems in some
|
||||
# environments. So now we manually load the entire library upfront.
|
||||
#
|
||||
# The file is still called Autoload so that existing integration
|
||||
# instructions continue to work.
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Client.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Configuration.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Diagnostics.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Error.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."ErrorTypes.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Notification.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Request.php";
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR."Stacktrace.php";
|
557
vendor/bugsnag/bugsnag/src/Bugsnag/Client.php
vendored
557
vendor/bugsnag/bugsnag/src/Bugsnag/Client.php
vendored
@@ -1,557 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Client
|
||||
{
|
||||
private $config;
|
||||
/** @var Bugsnag_Notification|null */
|
||||
private $notification;
|
||||
|
||||
/**
|
||||
* Initialize Bugsnag
|
||||
*
|
||||
* @param String $apiKey your Bugsnag API key
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($apiKey)
|
||||
{
|
||||
// Check API key has been passed
|
||||
if (!is_string($apiKey)) {
|
||||
throw new Exception('Bugsnag Error: Invalid API key');
|
||||
}
|
||||
|
||||
// Create a configuration object
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
$this->config->apiKey = $apiKey;
|
||||
|
||||
// Build a Diagnostics object
|
||||
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
|
||||
|
||||
// Register a shutdown function to check for fatal errors
|
||||
// and flush any buffered errors
|
||||
register_shutdown_function(array($this, 'shutdownHandler'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set your release stage, eg "production" or "development"
|
||||
*
|
||||
* @param String $releaseStage the app's current release stage
|
||||
* @return $this
|
||||
*/
|
||||
public function setReleaseStage($releaseStage)
|
||||
{
|
||||
$this->config->releaseStage = $releaseStage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set your app's semantic version, eg "1.2.3"
|
||||
*
|
||||
* @param String $appVersion the app's version
|
||||
* @return $this
|
||||
*/
|
||||
public function setAppVersion($appVersion)
|
||||
{
|
||||
$this->config->appVersion = $appVersion;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the host name
|
||||
*
|
||||
* @param String $hostname the host name
|
||||
* @return $this
|
||||
*/
|
||||
public function setHostname($hostname)
|
||||
{
|
||||
$this->config->hostname = $hostname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which release stages should be allowed to notify Bugsnag
|
||||
* eg array("production", "development")
|
||||
*
|
||||
* @param Array $notifyReleaseStages array of release stages to notify for
|
||||
* @return $this
|
||||
*/
|
||||
public function setNotifyReleaseStages(array $notifyReleaseStages)
|
||||
{
|
||||
$this->config->notifyReleaseStages = $notifyReleaseStages;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which Bugsnag endpoint to send errors to.
|
||||
*
|
||||
* @param String $endpoint endpoint URL
|
||||
* @return $this
|
||||
*/
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
$this->config->endpoint = $endpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable debug mode to help diagnose problems.
|
||||
*
|
||||
* @param Boolean $debug whether to enable debug mode
|
||||
* @return $this
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->config->debug = $debug;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not to use SSL when notifying bugsnag
|
||||
*
|
||||
* @param Boolean $useSSL whether to use SSL
|
||||
* @deprecated you can now pass full URLs to setEndpoint
|
||||
* @return $this
|
||||
*/
|
||||
public function setUseSSL($useSSL)
|
||||
{
|
||||
$this->config->useSSL = $useSSL;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired timeout for cURL connection when notifying bugsnag
|
||||
*
|
||||
* @param Integer $timeout the desired timeout in seconds
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->config->timeout = $timeout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the absolute path to the root of your application.
|
||||
* We use this to help with error grouping and to highlight "in project"
|
||||
* stacktrace lines.
|
||||
*
|
||||
* @param String $projectRoot the root path for your application
|
||||
* @return $this
|
||||
*/
|
||||
public function setProjectRoot($projectRoot)
|
||||
{
|
||||
$this->config->setProjectRoot($projectRoot);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path that should be stripped from the beginning of
|
||||
* any stacktrace file line. This helps to normalise filenames
|
||||
* for grouping and reduces the noise in stack traces.
|
||||
*
|
||||
* @param String $stripPath the path to strip from filenames
|
||||
* @return $this
|
||||
*/
|
||||
public function setStripPath($stripPath)
|
||||
{
|
||||
$this->config->setStripPath($stripPath);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the a regular expression for matching filenames in stacktrace lines
|
||||
* that are part of your application.
|
||||
*
|
||||
* @param String $projectRootRegex regex matching paths belong to your project
|
||||
* @return $this
|
||||
*/
|
||||
public function setProjectRootRegex($projectRootRegex)
|
||||
{
|
||||
$this->config->projectRootRegex = $projectRootRegex;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the strings to filter out from metaData arrays before sending then
|
||||
* to Bugsnag. Eg. array("password", "credit_card")
|
||||
*
|
||||
* @param Array $filters an array of metaData filters
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilters(array $filters)
|
||||
{
|
||||
$this->config->filters = $filters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set information about the current user of your app, including
|
||||
* id, name and email.
|
||||
*
|
||||
* @param Array $user an array of user information. Eg:
|
||||
* array(
|
||||
* 'name' => 'Bob Hoskins',
|
||||
* 'email' => 'bob@hoskins.com'
|
||||
* )
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(array $user)
|
||||
{
|
||||
$this->config->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated deprecated since version 2.1
|
||||
* @param $userId
|
||||
* @return $this
|
||||
*/
|
||||
public function setUserId($userId)
|
||||
{
|
||||
if (!is_array($this->config->user)) {
|
||||
$this->config->user = array();
|
||||
}
|
||||
|
||||
$this->config->user['id'] = $userId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a context representing the current type of request, or location in code.
|
||||
*
|
||||
* @param String $context the current context
|
||||
* @return $this
|
||||
*/
|
||||
public function setContext($context)
|
||||
{
|
||||
$this->config->context = $context;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of application executing the code. This is usually used to
|
||||
* represent if you are running plain PHP code "php", via a framework,
|
||||
* eg "laravel", or executing through delayed worker code, eg "resque".
|
||||
*
|
||||
* @param String $type the current type
|
||||
* @return $this
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->config->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom metadata to send to Bugsnag with every error. You can use
|
||||
* this to add custom tabs of data to each error on your Bugsnag dashboard
|
||||
*
|
||||
* @param Array $metaData an array of arrays of custom data. Eg:
|
||||
* array(
|
||||
* "user" => array(
|
||||
* "name" => "James",
|
||||
* "email" => "james@example.com"
|
||||
* )
|
||||
* )
|
||||
* @return $this
|
||||
*/
|
||||
public function setMetaData(array $metaData)
|
||||
{
|
||||
$this->config->metaData = $metaData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set proxy configuration
|
||||
*
|
||||
* @param Array $proxySettings an array with proxy settings. Eg:
|
||||
* array(
|
||||
* 'host' => "bugsnag.com",
|
||||
* 'port' => 42,
|
||||
* 'user' => "username"
|
||||
* 'password' => "password123"
|
||||
* )
|
||||
* @return $this
|
||||
*/
|
||||
public function setProxySettings(array $proxySettings)
|
||||
{
|
||||
$this->config->proxySettings = $proxySettings;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom curl options
|
||||
*
|
||||
* @param Array $curlOptions an array with curl options. Eg:
|
||||
* array(
|
||||
* CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4
|
||||
* )
|
||||
* @return $this
|
||||
*/
|
||||
public function setCurlOptions(array $curlOptions)
|
||||
{
|
||||
$this->config->curlOptions = $curlOptions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a custom function to call before notifying Bugsnag of an error.
|
||||
* You can use this to call your own error handling functions, or to add
|
||||
* custom tabs of data to each error on your Bugsnag dashboard.
|
||||
*
|
||||
* // Adding meta-data example
|
||||
* function before_bugsnag_notify($error) {
|
||||
* $error->addMetaData(array(
|
||||
* "user" => array(
|
||||
* "name" => "James"
|
||||
* )
|
||||
* ));
|
||||
* }
|
||||
* $bugsnag->setBeforeNotifyFunction("before_bugsnag_notify");
|
||||
* @param callable $beforeNotifyFunction
|
||||
* @return $this
|
||||
*/
|
||||
public function setBeforeNotifyFunction($beforeNotifyFunction)
|
||||
{
|
||||
$this->config->beforeNotifyFunction = $beforeNotifyFunction;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Bugsnag's error reporting level.
|
||||
* If this is not set, we'll use your current PHP error_reporting value
|
||||
* from your ini file or error_reporting(...) calls.
|
||||
*
|
||||
* @param Integer $errorReportingLevel the error reporting level integer
|
||||
* exactly as you would pass to PHP's error_reporting
|
||||
* @return $this
|
||||
*/
|
||||
public function setErrorReportingLevel($errorReportingLevel)
|
||||
{
|
||||
$this->config->errorReportingLevel = $errorReportingLevel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Bugsnag should be automatically notified of unhandled
|
||||
* exceptions and errors.
|
||||
*
|
||||
* @param Boolean $autoNotify whether to auto notify or not
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutoNotify($autoNotify)
|
||||
{
|
||||
$this->config->autoNotify = $autoNotify;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether errors should be batched together and send at the end of
|
||||
* each request.
|
||||
*
|
||||
* @param Boolean $batchSending whether to batch together errors
|
||||
* @return $this
|
||||
*/
|
||||
public function setBatchSending($batchSending)
|
||||
{
|
||||
$this->config->batchSending = $batchSending;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the notifier to report as to Bugsnag. This should only be
|
||||
* set by other notifier libraries.
|
||||
*
|
||||
* @param Array $notifier an array of name, version, url.
|
||||
* @return $this
|
||||
*/
|
||||
public function setNotifier($notifier)
|
||||
{
|
||||
$this->config->notifier = $notifier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Bugsnag should send $_ENV with each error.
|
||||
*
|
||||
* @param Boolean $sendEnvironment whether to send the environment
|
||||
* @return $this
|
||||
*/
|
||||
public function setSendEnvironment($sendEnvironment)
|
||||
{
|
||||
$this->config->sendEnvironment = $sendEnvironment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Bugsnag should send $_COOKIE with each error.
|
||||
*
|
||||
* @param Boolean $sendCookies whether to send the environment
|
||||
* @return $this
|
||||
*/
|
||||
public function setSendCookies($sendCookies)
|
||||
{
|
||||
$this->config->sendCookies = $sendCookies;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Bugsnag should send $_SESSION with each error.
|
||||
*
|
||||
* @param Boolean $sendSession whether to send the environment
|
||||
* @return $this
|
||||
*/
|
||||
public function setSendSession($sendSession)
|
||||
{
|
||||
$this->config->sendSession = $sendSession;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we send a small snippet of the code that crashed to help you
|
||||
* diagnose even faster from within your dashboard.
|
||||
*
|
||||
* @param Boolean $sendCode whether to send code to Bugsnag
|
||||
* @return $this
|
||||
*/
|
||||
public function setSendCode($sendCode)
|
||||
{
|
||||
$this->config->sendCode = $sendCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Bugsnag of a non-fatal/handled throwable
|
||||
*
|
||||
* @param Throwable $throwable the throwable to notify Bugsnag about
|
||||
* @param Array $metaData optional metaData to send with this error
|
||||
* @param String $severity optional severity of this error (fatal/error/warning/info)
|
||||
*/
|
||||
public function notifyException($throwable, array $metaData = null, $severity = null)
|
||||
{
|
||||
if (is_subclass_of($throwable, 'Throwable') || is_subclass_of($throwable, 'Exception') || get_class($throwable) == 'Exception') {
|
||||
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
|
||||
$error->setSeverity($severity);
|
||||
|
||||
$this->notify($error, $metaData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Bugsnag of a non-fatal/handled error
|
||||
*
|
||||
* @param String $name the name of the error, a short (1 word) string
|
||||
* @param String $message the error message
|
||||
* @param Array $metaData optional metaData to send with this error
|
||||
* @param String $severity optional severity of this error (fatal/error/warning/info)
|
||||
*/
|
||||
public function notifyError($name, $message, array $metaData = null, $severity = null)
|
||||
{
|
||||
$error = Bugsnag_Error::fromNamedError($this->config, $this->diagnostics, $name, $message);
|
||||
$error->setSeverity($severity);
|
||||
|
||||
$this->notify($error, $metaData);
|
||||
}
|
||||
|
||||
// Exception handler callback, should only be called internally by PHP's set_exception_handler
|
||||
public function exceptionHandler($throwable)
|
||||
{
|
||||
if(!$this->config->autoNotify) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
|
||||
$error->setSeverity("error");
|
||||
$this->notify($error);
|
||||
}
|
||||
|
||||
// Exception handler callback, should only be called internally by PHP's set_error_handler
|
||||
public function errorHandler($errno, $errstr, $errfile = '', $errline = 0)
|
||||
{
|
||||
if(!$this->config->autoNotify || $this->config->shouldIgnoreErrorCode($errno)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = Bugsnag_Error::fromPHPError($this->config, $this->diagnostics, $errno, $errstr, $errfile, $errline);
|
||||
$this->notify($error);
|
||||
}
|
||||
|
||||
// Shutdown handler callback, called when the PHP process has finished running
|
||||
// Should only be called internally by PHP's register_shutdown_function
|
||||
public function shutdownHandler()
|
||||
{
|
||||
// Get last error
|
||||
$lastError = error_get_last();
|
||||
|
||||
// Check if a fatal error caused this shutdown
|
||||
if (!is_null($lastError) && Bugsnag_ErrorTypes::isFatal($lastError['type']) && $this->config->autoNotify && !$this->config->shouldIgnoreErrorCode($lastError['type'])) {
|
||||
$error = Bugsnag_Error::fromPHPError($this->config, $this->diagnostics, $lastError['type'], $lastError['message'], $lastError['file'], $lastError['line'], true);
|
||||
$error->setSeverity("error");
|
||||
$this->notify($error);
|
||||
}
|
||||
|
||||
// Flush any buffered errors
|
||||
if ($this->notification) {
|
||||
$this->notification->deliver();
|
||||
$this->notification = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batches up errors into notifications for later sending
|
||||
*
|
||||
* @param Bugsnag_Error $error the error to batch up
|
||||
* @param array $metaData optional meta data to send with the error
|
||||
*/
|
||||
public function notify(Bugsnag_Error $error, $metaData = array())
|
||||
{
|
||||
// Queue or send the error
|
||||
if ($this->sendErrorsOnShutdown()) {
|
||||
// Create a batch notification unless we already have one
|
||||
if (is_null($this->notification)) {
|
||||
$this->notification = new Bugsnag_Notification($this->config);
|
||||
}
|
||||
|
||||
// Add this error to the notification
|
||||
$this->notification->addError($error, $metaData);
|
||||
} else {
|
||||
// Create and deliver notification immediately
|
||||
$notif = new Bugsnag_Notification($this->config);
|
||||
$notif->addError($error, $metaData);
|
||||
$notif->deliver();
|
||||
}
|
||||
}
|
||||
|
||||
// Should we send errors immediately or on shutdown
|
||||
private function sendErrorsOnShutdown()
|
||||
{
|
||||
return $this->config->batchSending && Bugsnag_Request::isRequest();
|
||||
}
|
||||
}
|
101
vendor/bugsnag/bugsnag/src/Bugsnag/Configuration.php
vendored
101
vendor/bugsnag/bugsnag/src/Bugsnag/Configuration.php
vendored
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Configuration
|
||||
{
|
||||
public static $DEFAULT_TIMEOUT = 10;
|
||||
public static $DEFAULT_ENDPOINT = 'https://notify.bugsnag.com';
|
||||
public static $DEFAULT_NON_SSL_ENDPOINT = 'http://notify.bugsnag.com';
|
||||
|
||||
public $apiKey;
|
||||
public $autoNotify = true;
|
||||
public $batchSending = true;
|
||||
public $useSSL = true;
|
||||
public $endpoint;
|
||||
public $notifyReleaseStages;
|
||||
public $filters = array('password');
|
||||
public $projectRoot;
|
||||
public $projectRootRegex;
|
||||
public $proxySettings = array();
|
||||
public $notifier = array(
|
||||
'name' => 'Bugsnag PHP (Official)',
|
||||
'version' => '2.6.1',
|
||||
'url' => 'https://bugsnag.com',
|
||||
);
|
||||
public $sendEnvironment = false;
|
||||
public $sendCookies = true;
|
||||
public $sendSession = true;
|
||||
public $sendCode = true;
|
||||
public $stripPath;
|
||||
public $stripPathRegex;
|
||||
|
||||
public $context;
|
||||
public $type;
|
||||
public $user;
|
||||
public $releaseStage = 'production';
|
||||
public $appVersion;
|
||||
public $hostname;
|
||||
|
||||
public $metaData;
|
||||
public $beforeNotifyFunction;
|
||||
public $errorReportingLevel;
|
||||
|
||||
public $curlOptions = array();
|
||||
|
||||
public $debug = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->timeout = Bugsnag_Configuration::$DEFAULT_TIMEOUT;
|
||||
}
|
||||
|
||||
public function getNotifyEndpoint()
|
||||
{
|
||||
if (is_null($this->endpoint)) {
|
||||
return $this->useSSL ? Bugsnag_Configuration::$DEFAULT_ENDPOINT : Bugsnag_Configuration::$DEFAULT_NON_SSL_ENDPOINT;
|
||||
} elseif (preg_match('/^(http:\/\/|https:\/\/)/', $this->endpoint)) {
|
||||
return $this->endpoint;
|
||||
} else {
|
||||
return ($this->useSSL ? "https" : "http")."://".$this->endpoint;
|
||||
}
|
||||
}
|
||||
|
||||
public function shouldNotify()
|
||||
{
|
||||
return is_null($this->notifyReleaseStages) || (is_array($this->notifyReleaseStages) && in_array($this->releaseStage, $this->notifyReleaseStages));
|
||||
}
|
||||
|
||||
public function shouldIgnoreErrorCode($code)
|
||||
{
|
||||
if (isset($this->errorReportingLevel)) {
|
||||
return !($this->errorReportingLevel & $code);
|
||||
} else {
|
||||
return !(error_reporting() & $code);
|
||||
}
|
||||
}
|
||||
|
||||
public function setProjectRoot($projectRoot)
|
||||
{
|
||||
$this->projectRoot = $projectRoot;
|
||||
$this->projectRootRegex = '/'.preg_quote($projectRoot, '/')."[\\/]?/i";
|
||||
if (is_null($this->stripPath)) {
|
||||
$this->setStripPath($projectRoot);
|
||||
}
|
||||
}
|
||||
|
||||
public function setStripPath($stripPath)
|
||||
{
|
||||
$this->stripPath = $stripPath;
|
||||
$this->stripPathRegex = '/'.preg_quote($stripPath, '/')."[\\/]?/i";
|
||||
}
|
||||
|
||||
public function get($prop, $default = null)
|
||||
{
|
||||
$configured = $this->$prop;
|
||||
|
||||
if (is_array($configured) && is_array($default)) {
|
||||
return array_merge($default, $configured);
|
||||
} else {
|
||||
return $configured ? $configured : $default;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Diagnostics
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct(Bugsnag_Configuration $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getAppData()
|
||||
{
|
||||
$appData = array();
|
||||
|
||||
if (!is_null($this->config->appVersion)) {
|
||||
$appData['version'] = $this->config->appVersion;
|
||||
}
|
||||
|
||||
if (!is_null($this->config->releaseStage)) {
|
||||
$appData['releaseStage'] = $this->config->releaseStage;
|
||||
}
|
||||
|
||||
if (!is_null($this->config->type)) {
|
||||
$appData['type'] = $this->config->type;
|
||||
}
|
||||
|
||||
return $appData;
|
||||
}
|
||||
|
||||
public function getDeviceData()
|
||||
{
|
||||
return array(
|
||||
'hostname' => $this->config->get('hostname', php_uname('n')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getContext()
|
||||
{
|
||||
return $this->config->get('context', Bugsnag_Request::getContext());
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
$defaultUser = array();
|
||||
$userId = Bugsnag_Request::getUserId();
|
||||
|
||||
if (!is_null($userId)) {
|
||||
$defaultUser['id'] = $userId;
|
||||
}
|
||||
|
||||
return $this->config->get('user', $defaultUser);
|
||||
}
|
||||
}
|
245
vendor/bugsnag/bugsnag/src/Bugsnag/Error.php
vendored
245
vendor/bugsnag/bugsnag/src/Bugsnag/Error.php
vendored
@@ -1,245 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Error
|
||||
{
|
||||
private static $VALID_SEVERITIES = array(
|
||||
'error',
|
||||
'warning',
|
||||
'info',
|
||||
);
|
||||
|
||||
public $name;
|
||||
public $payloadVersion = "2";
|
||||
public $message;
|
||||
public $severity = "warning";
|
||||
/** @var Bugsnag_Stacktrace */
|
||||
public $stacktrace;
|
||||
public $metaData = array();
|
||||
public $config;
|
||||
public $diagnostics;
|
||||
/** @var Bugsnag_Error|null */
|
||||
public $previous;
|
||||
public $groupingHash;
|
||||
|
||||
// Static error creation methods, to ensure that Error object is always complete
|
||||
public static function fromPHPError(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $code, $message, $file, $line, $fatal = false)
|
||||
{
|
||||
$error = new Bugsnag_Error($config, $diagnostics);
|
||||
$error->setPHPError($code, $message, $file, $line, $fatal);
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $throwable)
|
||||
{
|
||||
$error = new Bugsnag_Error($config, $diagnostics);
|
||||
$error->setPHPException($throwable);
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
public static function fromNamedError(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $name, $message = null)
|
||||
{
|
||||
$error = new Bugsnag_Error($config, $diagnostics);
|
||||
$error->setName($name)
|
||||
->setMessage($message)
|
||||
->setStacktrace(Bugsnag_Stacktrace::generate($config));
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// Private constructor (for use only by the static methods above)
|
||||
private function __construct(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->diagnostics = $diagnostics;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setGroupingHash($groupingHash)
|
||||
{
|
||||
$this->groupingHash = $groupingHash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setStacktrace(Bugsnag_Stacktrace $stacktrace)
|
||||
{
|
||||
$this->stacktrace = $stacktrace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSeverity($severity)
|
||||
{
|
||||
if (!is_null($severity)) {
|
||||
if (in_array($severity, Bugsnag_Error::$VALID_SEVERITIES)) {
|
||||
$this->severity = $severity;
|
||||
} else {
|
||||
error_log('Bugsnag Warning: Tried to set error severity to '.$severity.' which is not allowed.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPHPException($exception)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
|
||||
if (!$exception instanceof \Throwable) {
|
||||
error_log('Bugsnag Warning: Exception must implement interface \Throwable.');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!$exception instanceof \Exception) {
|
||||
error_log('Bugsnag Warning: Exception must be instance of \Exception.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setName(get_class($exception))
|
||||
->setMessage($exception->getMessage())
|
||||
->setStacktrace(Bugsnag_Stacktrace::fromBacktrace($this->config, $exception->getTrace(), $exception->getFile(), $exception->getLine()));
|
||||
|
||||
if (method_exists($exception, 'getPrevious')) {
|
||||
$this->setPrevious($exception->getPrevious());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPHPError($code, $message, $file, $line, $fatal = false)
|
||||
{
|
||||
if ($fatal) {
|
||||
// Generating stacktrace for PHP fatal errors is not possible,
|
||||
// since this code executes when the PHP process shuts down,
|
||||
// rather than at the time of the crash.
|
||||
//
|
||||
// In these situations, we generate a "stacktrace" containing only
|
||||
// the line and file number where the crash occurred.
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $file, $line);
|
||||
} else {
|
||||
$stacktrace = Bugsnag_Stacktrace::generate($this->config);
|
||||
}
|
||||
|
||||
$this->setName(Bugsnag_ErrorTypes::getName($code))
|
||||
->setMessage($message)
|
||||
->setSeverity(Bugsnag_ErrorTypes::getSeverity($code))
|
||||
->setStacktrace($stacktrace);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMetaData($metaData)
|
||||
{
|
||||
if (is_array($metaData)) {
|
||||
$this->metaData = array_merge_recursive($this->metaData, $metaData);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPrevious($exception)
|
||||
{
|
||||
if ($exception) {
|
||||
$this->previous = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$errorArray = array(
|
||||
'app' => $this->diagnostics->getAppData(),
|
||||
'device' => $this->diagnostics->getDeviceData(),
|
||||
'user' => $this->diagnostics->getUser(),
|
||||
'context' => $this->diagnostics->getContext(),
|
||||
'payloadVersion' => $this->payloadVersion,
|
||||
'severity' => $this->severity,
|
||||
'exceptions' => $this->exceptionArray(),
|
||||
'metaData' => $this->cleanupObj($this->metaData),
|
||||
);
|
||||
|
||||
if (isset($this->groupingHash)) {
|
||||
$errorArray['groupingHash'] = $this->groupingHash;
|
||||
}
|
||||
|
||||
return $errorArray;
|
||||
}
|
||||
|
||||
public function exceptionArray()
|
||||
{
|
||||
if ($this->previous) {
|
||||
$exceptionArray = $this->previous->exceptionArray();
|
||||
} else {
|
||||
$exceptionArray = array();
|
||||
}
|
||||
|
||||
$exceptionArray[] = array(
|
||||
'errorClass' => $this->name,
|
||||
'message' => $this->message,
|
||||
'stacktrace' => $this->stacktrace->toArray(),
|
||||
);
|
||||
|
||||
return $this->cleanupObj($exceptionArray);
|
||||
}
|
||||
|
||||
private function cleanupObj($obj)
|
||||
{
|
||||
if (is_null($obj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array($obj)) {
|
||||
$cleanArray = array();
|
||||
foreach ($obj as $key => $value) {
|
||||
// Apply filters if required
|
||||
if (is_array($this->config->filters)) {
|
||||
// Check if this key should be filtered
|
||||
$shouldFilter = false;
|
||||
foreach ($this->config->filters as $filter) {
|
||||
if (strpos($key, $filter) !== false) {
|
||||
$shouldFilter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply filters
|
||||
if ($shouldFilter) {
|
||||
$cleanArray[$key] = '[FILTERED]';
|
||||
} else {
|
||||
$cleanArray[$key] = $this->cleanupObj($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $cleanArray;
|
||||
} elseif (is_string($obj)) {
|
||||
// UTF8-encode if not already encoded
|
||||
if (function_exists('mb_detect_encoding') && !mb_detect_encoding($obj, 'UTF-8', true)) {
|
||||
return utf8_encode($obj);
|
||||
} else {
|
||||
return $obj;
|
||||
}
|
||||
} elseif (is_object($obj)) {
|
||||
// json_encode -> json_decode trick turns an object into an array
|
||||
return $this->cleanupObj(json_decode(json_encode($obj), true));
|
||||
} else {
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
}
|
118
vendor/bugsnag/bugsnag/src/Bugsnag/ErrorTypes.php
vendored
118
vendor/bugsnag/bugsnag/src/Bugsnag/ErrorTypes.php
vendored
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_ErrorTypes
|
||||
{
|
||||
private static $ERROR_TYPES = array(
|
||||
E_ERROR => array(
|
||||
'name' => 'PHP Fatal Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
E_WARNING => array(
|
||||
'name' => 'PHP Warning',
|
||||
'severity' => 'warning',
|
||||
),
|
||||
|
||||
E_PARSE => array(
|
||||
'name' => 'PHP Parse Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
E_NOTICE => array(
|
||||
'name' => 'PHP Notice',
|
||||
'severity' => 'info',
|
||||
),
|
||||
|
||||
E_CORE_ERROR => array(
|
||||
'name' => 'PHP Core Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
E_CORE_WARNING => array(
|
||||
'name' => 'PHP Core Warning',
|
||||
'severity' => 'warning',
|
||||
),
|
||||
|
||||
E_COMPILE_ERROR => array(
|
||||
'name' => 'PHP Compile Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
E_COMPILE_WARNING => array(
|
||||
'name' => 'PHP Compile Warning',
|
||||
'severity' => 'warning',
|
||||
),
|
||||
|
||||
E_USER_ERROR => array(
|
||||
'name' => 'User Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
E_USER_WARNING => array(
|
||||
'name' => 'User Warning',
|
||||
'severity' => 'warning',
|
||||
),
|
||||
|
||||
E_USER_NOTICE => array(
|
||||
'name' => 'User Notice',
|
||||
'severity' => 'info',
|
||||
),
|
||||
|
||||
E_STRICT => array(
|
||||
'name' => 'PHP Strict',
|
||||
'severity' => 'info',
|
||||
),
|
||||
|
||||
E_RECOVERABLE_ERROR => array(
|
||||
'name' => 'PHP Recoverable Error',
|
||||
'severity' => 'error',
|
||||
),
|
||||
|
||||
// E_DEPRECATED (Since PHP 5.3.0)
|
||||
8192 => array(
|
||||
'name' => 'PHP Deprecated',
|
||||
'severity' => 'info',
|
||||
),
|
||||
|
||||
// E_USER_DEPRECATED (Since PHP 5.3.0)
|
||||
16384 => array(
|
||||
'name' => 'User Deprecated',
|
||||
'severity' => 'info',
|
||||
),
|
||||
);
|
||||
|
||||
public static function isFatal($code)
|
||||
{
|
||||
return self::getSeverity($code) == 'error';
|
||||
}
|
||||
|
||||
public static function getName($code)
|
||||
{
|
||||
if (array_key_exists($code, self::$ERROR_TYPES)) {
|
||||
return self::$ERROR_TYPES[$code]['name'];
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSeverity($code)
|
||||
{
|
||||
if (array_key_exists($code, self::$ERROR_TYPES)) {
|
||||
return self::$ERROR_TYPES[$code]['severity'];
|
||||
} else {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLevelsForSeverity($severity)
|
||||
{
|
||||
$levels = 0;
|
||||
foreach (Bugsnag_ErrorTypes::$ERROR_TYPES as $level => $info) {
|
||||
if ($info['severity'] == $severity) {
|
||||
$levels |= $level;
|
||||
}
|
||||
}
|
||||
|
||||
return $levels;
|
||||
}
|
||||
}
|
202
vendor/bugsnag/bugsnag/src/Bugsnag/Notification.php
vendored
202
vendor/bugsnag/bugsnag/src/Bugsnag/Notification.php
vendored
@@ -1,202 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Notification
|
||||
{
|
||||
private static $CONTENT_TYPE_HEADER = 'Content-type: application/json';
|
||||
|
||||
private $config;
|
||||
/** @var Bugsnag_Error[] */
|
||||
private $errorQueue = array();
|
||||
|
||||
public function __construct(Bugsnag_Configuration $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function addError(Bugsnag_Error $error, $passedMetaData = array())
|
||||
{
|
||||
// Check if this error should be sent to Bugsnag
|
||||
if (!$this->config->shouldNotify()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add global meta-data to error
|
||||
$error->setMetaData($this->config->metaData);
|
||||
|
||||
// Add request meta-data to error
|
||||
if (Bugsnag_Request::isRequest()) {
|
||||
$error->setMetaData(Bugsnag_Request::getRequestMetaData());
|
||||
}
|
||||
|
||||
// Session Tab
|
||||
if ($this->config->sendSession && !empty($_SESSION)) {
|
||||
$error->setMetaData(array('session' => $_SESSION));
|
||||
}
|
||||
|
||||
// Cookies Tab
|
||||
if ($this->config->sendCookies && !empty($_COOKIE)) {
|
||||
$error->setMetaData(array('cookies' => $_COOKIE));
|
||||
}
|
||||
|
||||
// Add environment meta-data to error
|
||||
if ($this->config->sendEnvironment && !empty($_ENV)) {
|
||||
$error->setMetaData(array("Environment" => $_ENV));
|
||||
}
|
||||
|
||||
// Add user-specified meta-data to error
|
||||
$error->setMetaData($passedMetaData);
|
||||
|
||||
// Run beforeNotify function (can cause more meta-data to be merged)
|
||||
if (isset($this->config->beforeNotifyFunction) && is_callable($this->config->beforeNotifyFunction)) {
|
||||
$beforeNotifyReturn = call_user_func($this->config->beforeNotifyFunction, $error);
|
||||
}
|
||||
|
||||
// Skip this error if the beforeNotify function returned FALSE
|
||||
if (!isset($beforeNotifyReturn) || $beforeNotifyReturn !== false) {
|
||||
$this->errorQueue[] = $error;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$events = array();
|
||||
foreach ($this->errorQueue as $error) {
|
||||
$errorArray = $error->toArray();
|
||||
|
||||
if (!is_null($errorArray)) {
|
||||
$events[] = $errorArray;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'apiKey' => $this->config->apiKey,
|
||||
'notifier' => $this->config->notifier,
|
||||
'events' => $events,
|
||||
);
|
||||
}
|
||||
|
||||
public function deliver()
|
||||
{
|
||||
if (!empty($this->errorQueue)) {
|
||||
// Post the request to bugsnag
|
||||
$this->postJSON($this->config->getNotifyEndpoint(), $this->toArray());
|
||||
|
||||
// Clear the error queue
|
||||
$this->errorQueue = array();
|
||||
}
|
||||
}
|
||||
|
||||
public function postJSON($url, $data)
|
||||
{
|
||||
$body = json_encode($data);
|
||||
|
||||
// Prefer cURL if it is installed, otherwise fall back to fopen()
|
||||
// cURL supports both timeouts and proxies
|
||||
if (function_exists('curl_version')) {
|
||||
$this->postWithCurl($url, $body);
|
||||
} elseif (ini_get('allow_url_fopen')) {
|
||||
$this->postWithFopen($url, $body);
|
||||
} else {
|
||||
error_log('Bugsnag Warning: Couldn\'t notify (neither cURL or allow_url_fopen are available on your PHP installation)');
|
||||
}
|
||||
}
|
||||
|
||||
private function postWithCurl($url, $body)
|
||||
{
|
||||
$http = curl_init($url);
|
||||
|
||||
// Default curl settings
|
||||
curl_setopt($http, CURLOPT_HEADER, false);
|
||||
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($http, CURLOPT_POST, true);
|
||||
curl_setopt($http, CURLOPT_HTTPHEADER, array(Bugsnag_Notification::$CONTENT_TYPE_HEADER));
|
||||
curl_setopt($http, CURLOPT_POSTFIELDS, $body);
|
||||
curl_setopt($http, CURLOPT_CONNECTTIMEOUT, $this->config->timeout);
|
||||
curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($http, CURLOPT_VERBOSE, false);
|
||||
if (defined('HHVM_VERSION')) {
|
||||
curl_setopt($http, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
} else {
|
||||
curl_setopt($http, CURL_IPRESOLVE_V4, true);
|
||||
}
|
||||
|
||||
if (!empty($this->config->curlOptions)) {
|
||||
foreach ($this->config->curlOptions as $option => $value) {
|
||||
curl_setopt($http, $option, $value);
|
||||
}
|
||||
}
|
||||
// Apply proxy settings (if present)
|
||||
if (count($this->config->proxySettings)) {
|
||||
if (isset($this->config->proxySettings['host'])) {
|
||||
curl_setopt($http, CURLOPT_PROXY, $this->config->proxySettings['host']);
|
||||
}
|
||||
if (isset($this->config->proxySettings['port'])) {
|
||||
curl_setopt($http, CURLOPT_PROXYPORT, $this->config->proxySettings['port']);
|
||||
}
|
||||
if (isset($this->config->proxySettings['user'])) {
|
||||
$userPassword = $this->config->proxySettings['user'].':';
|
||||
$userPassword .= isset($this->config->proxySettings['password']) ? $this->config->proxySettings['password'] : '';
|
||||
curl_setopt($http, CURLOPT_PROXYUSERPWD, $userPassword);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the request and fetch the response
|
||||
$responseBody = curl_exec($http);
|
||||
$statusCode = curl_getinfo($http, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($statusCode > 200) {
|
||||
error_log('Bugsnag Warning: Couldn\'t notify ('.$responseBody.')');
|
||||
|
||||
if($this->config->debug) {
|
||||
error_log('Bugsnag Debug: Attempted to post to URL - "'.$url.'"');
|
||||
error_log('Bugsnag Debug: Attempted to post payload - "'.$body.'"');
|
||||
}
|
||||
}
|
||||
|
||||
if (curl_errno($http)) {
|
||||
error_log('Bugsnag Warning: Couldn\'t notify ('.curl_error($http).')');
|
||||
}
|
||||
|
||||
curl_close($http);
|
||||
}
|
||||
|
||||
private function postWithFopen($url, $body)
|
||||
{
|
||||
// Warn about lack of proxy support if we are using fopen()
|
||||
if (count($this->config->proxySettings)) {
|
||||
error_log('Bugsnag Warning: Can\'t use proxy settings unless cURL is installed');
|
||||
}
|
||||
|
||||
// Warn about lack of timeout support if we are using fopen()
|
||||
if ($this->config->timeout != Bugsnag_Configuration::$DEFAULT_TIMEOUT) {
|
||||
error_log('Bugsnag Warning: Can\'t change timeout settings unless cURL is installed');
|
||||
}
|
||||
|
||||
// Create the request context
|
||||
$context = stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => Bugsnag_Notification::$CONTENT_TYPE_HEADER.'\r\n',
|
||||
'content' => $body,
|
||||
),
|
||||
'ssl' => array(
|
||||
'verify_peer' => false,
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the request and fetch the response
|
||||
if ($stream = fopen($url, 'rb', false, $context)) {
|
||||
$response = stream_get_contents($stream);
|
||||
|
||||
if (!$response) {
|
||||
error_log('Bugsnag Warning: Couldn\'t notify (no response)');
|
||||
}
|
||||
} else {
|
||||
error_log('Bugsnag Warning: Couldn\'t notify (fopen failed)');
|
||||
}
|
||||
}
|
||||
}
|
88
vendor/bugsnag/bugsnag/src/Bugsnag/Request.php
vendored
88
vendor/bugsnag/bugsnag/src/Bugsnag/Request.php
vendored
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Request
|
||||
{
|
||||
public static function isRequest()
|
||||
{
|
||||
return isset($_SERVER['REQUEST_METHOD']);
|
||||
}
|
||||
|
||||
public static function getRequestMetaData()
|
||||
{
|
||||
$requestData = array();
|
||||
|
||||
// Request Tab
|
||||
$requestData['request'] = array();
|
||||
$requestData['request']['url'] = self::getCurrentUrl();
|
||||
if (isset($_SERVER['REQUEST_METHOD'])) {
|
||||
$requestData['request']['httpMethod'] = $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$requestData['request']['params'] = $_POST;
|
||||
} else {
|
||||
if (isset($_SERVER['CONTENT_TYPE']) && stripos($_SERVER['CONTENT_TYPE'], 'application/json') === 0) {
|
||||
$requestData['request']['params'] = json_decode(file_get_contents('php://input'));
|
||||
}
|
||||
}
|
||||
|
||||
$requestData['request']['ip'] = self::getRequestIp();
|
||||
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
||||
$requestData['request']['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
}
|
||||
|
||||
$headers = self::getRequestHeaders();
|
||||
if (!empty($headers)) {
|
||||
$requestData['request']['headers'] = $headers;
|
||||
}
|
||||
|
||||
return $requestData;
|
||||
}
|
||||
|
||||
public static function getContext()
|
||||
{
|
||||
if (self::isRequest() && isset($_SERVER['REQUEST_METHOD']) && isset($_SERVER["REQUEST_URI"])) {
|
||||
return $_SERVER['REQUEST_METHOD'].' '.strtok($_SERVER["REQUEST_URI"], '?');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUserId()
|
||||
{
|
||||
if (self::isRequest()) {
|
||||
return self::getRequestIp();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCurrentUrl()
|
||||
{
|
||||
$schema = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? 'https://' : 'http://';
|
||||
|
||||
return $schema.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
public static function getRequestIp()
|
||||
{
|
||||
return isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
public static function getRequestHeaders()
|
||||
{
|
||||
if (function_exists('getallheaders')) {
|
||||
return getallheaders();
|
||||
}
|
||||
|
||||
$headers = array();
|
||||
|
||||
foreach ($_SERVER as $name => $value) {
|
||||
if (substr($name, 0, 5) == 'HTTP_') {
|
||||
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
}
|
145
vendor/bugsnag/bugsnag/src/Bugsnag/Stacktrace.php
vendored
145
vendor/bugsnag/bugsnag/src/Bugsnag/Stacktrace.php
vendored
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Bugsnag_Stacktrace
|
||||
{
|
||||
private static $DEFAULT_NUM_LINES = 7;
|
||||
private static $MAX_LINE_LENGTH = 200;
|
||||
|
||||
public $frames = array();
|
||||
private $config;
|
||||
|
||||
public static function generate($config)
|
||||
{
|
||||
// Reduce memory usage by omitting args and objects from backtrace
|
||||
if (version_compare(PHP_VERSION, '5.3.6') >= 0) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS & ~DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
||||
} elseif (version_compare(PHP_VERSION, '5.2.5') >= 0) {
|
||||
$backtrace = debug_backtrace(false);
|
||||
} else {
|
||||
$backtrace = debug_backtrace();
|
||||
}
|
||||
|
||||
return self::fromBacktrace($config, $backtrace, "[generator]", 0);
|
||||
}
|
||||
|
||||
public static function fromFrame($config, $file, $line)
|
||||
{
|
||||
$stacktrace = new Bugsnag_Stacktrace($config);
|
||||
$stacktrace->addFrame($file, $line, "[unknown]");
|
||||
|
||||
return $stacktrace;
|
||||
}
|
||||
|
||||
public static function fromBacktrace($config, $backtrace, $topFile, $topLine)
|
||||
{
|
||||
$stacktrace = new Bugsnag_Stacktrace($config);
|
||||
|
||||
// PHP backtrace's are misaligned, we need to shift the file/line down a frame
|
||||
foreach ($backtrace as $frame) {
|
||||
if (!self::frameInsideBugsnag($frame)) {
|
||||
$stacktrace->addFrame(
|
||||
$topFile,
|
||||
$topLine,
|
||||
isset($frame['function']) ? $frame['function'] : null,
|
||||
isset($frame['class']) ? $frame['class'] : null
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($frame['file']) && isset($frame['line'])) {
|
||||
$topFile = $frame['file'];
|
||||
$topLine = $frame['line'];
|
||||
} else {
|
||||
$topFile = "[internal]";
|
||||
$topLine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a final stackframe for the "main" method
|
||||
$stacktrace->addFrame($topFile, $topLine, '[main]');
|
||||
|
||||
return $stacktrace;
|
||||
}
|
||||
|
||||
public static function frameInsideBugsnag($frame)
|
||||
{
|
||||
return isset($frame['class']) && strpos($frame['class'], 'Bugsnag_') === 0;
|
||||
}
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->frames;
|
||||
}
|
||||
|
||||
public function addFrame($file, $line, $method, $class = null)
|
||||
{
|
||||
// Account for special "filenames" in eval'd code
|
||||
$matches = array();
|
||||
if (preg_match("/^(.*?)\((\d+)\) : (?:eval\(\)'d code|runtime-created function)$/", $file, $matches)) {
|
||||
$file = $matches[1];
|
||||
$line = $matches[2];
|
||||
}
|
||||
|
||||
// Construct the frame
|
||||
$frame = array(
|
||||
'lineNumber' => $line,
|
||||
'method' => $class ? "$class::$method" : $method,
|
||||
);
|
||||
|
||||
// Attach some lines of code for context
|
||||
if($this->config->sendCode) {
|
||||
$frame['code'] = $this->getCode($file, $line, Bugsnag_Stacktrace::$DEFAULT_NUM_LINES);
|
||||
}
|
||||
|
||||
// Check if this frame is inProject
|
||||
$frame['inProject'] = !is_null($this->config->projectRootRegex) && preg_match($this->config->projectRootRegex, $file);
|
||||
|
||||
// Strip out projectRoot from start of file path
|
||||
if (is_null($this->config->stripPathRegex)) {
|
||||
$frame['file'] = $file;
|
||||
} else {
|
||||
$frame['file'] = preg_replace($this->config->stripPathRegex, '', $file);
|
||||
}
|
||||
|
||||
$this->frames[] = $frame;
|
||||
}
|
||||
|
||||
private function getCode($path, $line, $numLines)
|
||||
{
|
||||
if (empty($path) || empty($line) || !file_exists($path)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the number of lines in the file
|
||||
$file = new SplFileObject($path);
|
||||
$file->seek(PHP_INT_MAX);
|
||||
$totalLines = $file->key() + 1;
|
||||
|
||||
// Work out which lines we should fetch
|
||||
$start = max($line - floor($numLines / 2), 1);
|
||||
$end = $start + ($numLines - 1);
|
||||
if ($end > $totalLines) {
|
||||
$end = $totalLines;
|
||||
$start = max($end - ($numLines - 1), 1);
|
||||
}
|
||||
|
||||
// Get the code for this range
|
||||
$code = array();
|
||||
|
||||
$file->seek($start - 1);
|
||||
while ($file->key() < $end) {
|
||||
$code[$file->key() + 1] = rtrim(substr($file->current(), 0, Bugsnag_Stacktrace::$MAX_LINE_LENGTH));
|
||||
$file->next();
|
||||
}
|
||||
|
||||
return $code;
|
||||
} catch (RuntimeException $ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
abstract class Bugsnag_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
/** @var Bugsnag_Diagnostics */
|
||||
protected $diagnostics;
|
||||
|
||||
protected function getError($name = "Name", $message = "Message")
|
||||
{
|
||||
return Bugsnag_Error::fromNamedError($this->config, $this->diagnostics, $name, $message);
|
||||
}
|
||||
|
||||
protected function getFixturePath($file)
|
||||
{
|
||||
return realpath(dirname(__FILE__)."/../fixtures/".$file);
|
||||
}
|
||||
|
||||
protected function getFixture($file)
|
||||
{
|
||||
return file_get_contents($this->getFixturePath($file));
|
||||
}
|
||||
|
||||
protected function getJsonFixture($file)
|
||||
{
|
||||
return json_decode($this->getFixture($file), true);
|
||||
}
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = explode('.', PHP_VERSION);
|
||||
|
||||
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 50207) {
|
||||
define('PHP_MAJOR_VERSION', $version[0]);
|
||||
define('PHP_MINOR_VERSION', $version[1]);
|
||||
define('PHP_RELEASE_VERSION', $version[2]);
|
||||
}
|
||||
|
||||
class ClientTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var PHPUnit_Framework_MockObject_MockObject|Bugsnag_Client */
|
||||
protected $client;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// Mock the notify function
|
||||
$this->client = $this->getMockBuilder('Bugsnag_Client')
|
||||
->setMethods(array('notify'))
|
||||
->setConstructorArgs(array('example-api-key'))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testErrorHandler()
|
||||
{
|
||||
$this->client->expects($this->once())
|
||||
->method('notify');
|
||||
|
||||
$this->client->errorHandler(E_WARNING, "Something broke", "somefile.php", 123);
|
||||
}
|
||||
|
||||
public function testExceptionHandler()
|
||||
{
|
||||
$this->client->expects($this->once())
|
||||
->method('notify');
|
||||
|
||||
$this->client->exceptionHandler(new Exception("Something broke"));
|
||||
}
|
||||
|
||||
public function testManualErrorNotification()
|
||||
{
|
||||
$this->client->expects($this->once())
|
||||
->method('notify');
|
||||
|
||||
$this->client->notifyError("SomeError", "Some message");
|
||||
}
|
||||
|
||||
public function testManualExceptionNotification()
|
||||
{
|
||||
$this->client->expects($this->once())
|
||||
->method('notify');
|
||||
|
||||
$this->client->notifyException(new Exception("Something broke"));
|
||||
}
|
||||
|
||||
public function testErrorReportingLevel()
|
||||
{
|
||||
$this->client->expects($this->once())
|
||||
->method('notify');
|
||||
|
||||
$this->client->setErrorReportingLevel(E_NOTICE)
|
||||
->errorHandler(E_NOTICE, "Something broke", "somefile.php", 123);
|
||||
}
|
||||
|
||||
public function testErrorReportingLevelFails()
|
||||
{
|
||||
$this->client->expects($this->never())
|
||||
->method('notify');
|
||||
|
||||
$this->client->setErrorReportingLevel(E_NOTICE)
|
||||
->errorHandler(E_WARNING, "Something broke", "somefile.php", 123);
|
||||
}
|
||||
|
||||
public function testErrorReportingWithoutNotice()
|
||||
{
|
||||
$this->client->expects($this->never())
|
||||
->method('notify');
|
||||
|
||||
$this->client->setErrorReportingLevel(E_ALL & ~E_NOTICE)
|
||||
->errorHandler(E_NOTICE, "Something broke", "somefile.php", 123);
|
||||
}
|
||||
|
||||
public function testSetInvalidCurlOptions()
|
||||
{
|
||||
if (PHP_MAJOR_VERSION >= 7) {
|
||||
$this->setExpectedException('TypeError');
|
||||
} else {
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
}
|
||||
$this->client->setCurlOptions("option");
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
}
|
||||
|
||||
public function testDefaultEndpoint()
|
||||
{
|
||||
$this->assertEquals($this->config->getNotifyEndpoint(), "https://notify.bugsnag.com");
|
||||
}
|
||||
|
||||
public function testNonSSLEndpoint()
|
||||
{
|
||||
$this->config->useSSL = false;
|
||||
$this->assertEquals($this->config->getNotifyEndpoint(), "http://notify.bugsnag.com");
|
||||
}
|
||||
|
||||
public function testCustomEndpoint()
|
||||
{
|
||||
$this->config->useSSL = false;
|
||||
$this->config->endpoint = "localhost";
|
||||
$this->assertEquals($this->config->getNotifyEndpoint(), "http://localhost");
|
||||
}
|
||||
|
||||
public function testDefaultReleaseStageShouldNotify()
|
||||
{
|
||||
$this->assertTrue($this->config->shouldNotify());
|
||||
}
|
||||
|
||||
public function testCustomReleaseStageShouldNotify()
|
||||
{
|
||||
$this->config->releaseStage = "staging";
|
||||
$this->assertTrue($this->config->shouldNotify());
|
||||
}
|
||||
|
||||
public function testCustomNotifyReleaseStagesShouldNotify()
|
||||
{
|
||||
$this->config->notifyReleaseStages = array("banana");
|
||||
$this->assertFalse($this->config->shouldNotify());
|
||||
}
|
||||
|
||||
public function testBothCustomShouldNotify()
|
||||
{
|
||||
$this->config->releaseStage = "banana";
|
||||
$this->config->notifyReleaseStages = array("banana");
|
||||
$this->assertTrue($this->config->shouldNotify());
|
||||
}
|
||||
|
||||
public function testNotifier()
|
||||
{
|
||||
$this->assertEquals($this->config->notifier['name'], "Bugsnag PHP (Official)");
|
||||
$this->assertEquals($this->config->notifier['url'], "https://bugsnag.com");
|
||||
}
|
||||
|
||||
public function testShouldIgnore()
|
||||
{
|
||||
$this->config->errorReportingLevel = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
|
||||
|
||||
$this->assertTrue($this->config->shouldIgnoreErrorCode(E_NOTICE));
|
||||
}
|
||||
|
||||
public function testShouldNotIgnore()
|
||||
{
|
||||
$this->config->errorReportingLevel = E_ALL;
|
||||
|
||||
$this->assertfalse($this->config->shouldIgnoreErrorCode(E_NOTICE));
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
class DiagnosticsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
/** @var Bugsnag_Diagnostics */
|
||||
protected $diagnostics;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
|
||||
}
|
||||
|
||||
public function testDefaultAppData()
|
||||
{
|
||||
$this->config->releaseStage = 'qa1';
|
||||
$this->config->appVersion = '1.2.3';
|
||||
$this->config->type = "laravel";
|
||||
|
||||
$appData = $this->diagnostics->getAppData();
|
||||
|
||||
$this->assertEquals($appData['releaseStage'], 'qa1');
|
||||
$this->assertEquals($appData['version'], '1.2.3');
|
||||
$this->assertEquals($appData['type'], 'laravel');
|
||||
}
|
||||
|
||||
public function testDefaultDeviceData()
|
||||
{
|
||||
$this->config->hostname = 'web1.example.com';
|
||||
|
||||
$deviceData = $this->diagnostics->getDeviceData();
|
||||
|
||||
$this->assertEquals($deviceData['hostname'], 'web1.example.com');
|
||||
}
|
||||
|
||||
public function testDefaultContext()
|
||||
{
|
||||
$this->config->context = 'herp#derp';
|
||||
$this->assertEquals($this->diagnostics->getContext(), 'herp#derp');
|
||||
}
|
||||
|
||||
public function testDefaultUser()
|
||||
{
|
||||
$this->config->user = array('id' => 123, 'email' => "test@email.com", 'name' => "Bob Hoskins");
|
||||
|
||||
$userData = $this->diagnostics->getUser();
|
||||
|
||||
$this->assertEquals($userData['id'], 123);
|
||||
$this->assertEquals($userData['email'], "test@email.com");
|
||||
$this->assertEquals($userData['name'], "Bob Hoskins");
|
||||
}
|
||||
}
|
137
vendor/bugsnag/bugsnag/tests/Bugsnag/ErrorTest.php
vendored
137
vendor/bugsnag/bugsnag/tests/Bugsnag/ErrorTest.php
vendored
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'Bugsnag_TestCase.php';
|
||||
|
||||
class ErrorTest extends Bugsnag_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
/** @var Bugsnag_Diagnostics */
|
||||
protected $diagnostics;
|
||||
/** @var Bugsnag_Error */
|
||||
protected $error;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
|
||||
$this->error = $this->getError();
|
||||
}
|
||||
|
||||
public function testMetaData()
|
||||
{
|
||||
$this->error->setMetaData(array("Testing" => array("globalArray" => "hi")));
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['metaData']["Testing"]["globalArray"], "hi");
|
||||
}
|
||||
|
||||
public function testMetaDataMerging()
|
||||
{
|
||||
$this->error->setMetaData(array("Testing" => array("globalArray" => "hi")));
|
||||
$this->error->setMetaData(array("Testing" => array("localArray" => "yo")));
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['metaData']["Testing"]["globalArray"], "hi");
|
||||
$this->assertEquals($errorArray['metaData']["Testing"]["localArray"], "yo");
|
||||
}
|
||||
|
||||
public function testFiltering()
|
||||
{
|
||||
$this->error->setMetaData(array("Testing" => array("password" => "123456")));
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['metaData']['Testing']['password'], '[FILTERED]');
|
||||
}
|
||||
|
||||
public function testNoticeName()
|
||||
{
|
||||
$this->error->setPHPError(E_NOTICE, "Broken", "file", 123);
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['exceptions'][0]['errorClass'], 'PHP Notice');
|
||||
}
|
||||
|
||||
public function testErrorName()
|
||||
{
|
||||
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['exceptions'][0]['errorClass'], 'PHP Fatal Error');
|
||||
}
|
||||
|
||||
public function testErrorPayloadVersion()
|
||||
{
|
||||
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['payloadVersion'], '2');
|
||||
}
|
||||
|
||||
public function testNoticeSeverity()
|
||||
{
|
||||
$this->error->setPHPError(E_NOTICE, "Broken", "file", 123);
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['severity'], 'info');
|
||||
}
|
||||
|
||||
public function testErrorSeverity()
|
||||
{
|
||||
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['severity'], 'error');
|
||||
}
|
||||
|
||||
public function testManualSeverity()
|
||||
{
|
||||
$this->error->setSeverity("error");
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['severity'], 'error');
|
||||
}
|
||||
|
||||
public function testInvalidSeverity()
|
||||
{
|
||||
$this->error->setSeverity("bunk");
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['severity'], 'warning');
|
||||
}
|
||||
|
||||
public function testPreviousException()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
||||
$exception = new Exception("secondly", 65533, new Exception("firstly"));
|
||||
|
||||
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);
|
||||
|
||||
$errorArray = $error->toArray();
|
||||
|
||||
$this->assertEquals(count($errorArray['exceptions']), 2);
|
||||
$this->assertEquals($errorArray['exceptions'][0]['message'], 'firstly');
|
||||
$this->assertEquals($errorArray['exceptions'][1]['message'], 'secondly');
|
||||
}
|
||||
}
|
||||
|
||||
public function testErrorGroupingHash()
|
||||
{
|
||||
$this->error->setGroupingHash('herp#derp');
|
||||
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertEquals($errorArray['groupingHash'], 'herp#derp');
|
||||
}
|
||||
|
||||
public function testErrorGroupingHashNotSet()
|
||||
{
|
||||
$errorArray = $this->error->toArray();
|
||||
$this->assertArrayNotHasKey('groupingHash', $errorArray);
|
||||
}
|
||||
|
||||
public function testSetPHPException()
|
||||
{
|
||||
$exception = version_compare(PHP_VERSION, '7.0.0', '>=') ? new \Error() : new Exception();
|
||||
$this->error->setPHPException($exception);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ErrorTypesTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetLevelsForSeverity()
|
||||
{
|
||||
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("error"), 4437);
|
||||
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("warning"), 674);
|
||||
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("info"), 27656);
|
||||
}
|
||||
}
|
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'Bugsnag_TestCase.php';
|
||||
|
||||
class NotificationTest extends Bugsnag_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
/** @var Bugsnag_Diagnostics */
|
||||
protected $diagnostics;
|
||||
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $notification;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
$this->config->apiKey = "6015a72ff14038114c3d12623dfb018f";
|
||||
$this->config->beforeNotifyFunction = "before_notify_skip_error";
|
||||
|
||||
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
|
||||
|
||||
$this->notification = $this->getMockBuilder('Bugsnag_Notification')
|
||||
->setMethods(array("postJSON"))
|
||||
->setConstructorArgs(array($this->config))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testNotification()
|
||||
{
|
||||
// Create a mock notification object
|
||||
$this->notification = $this->getMockBuilder('Bugsnag_Notification')
|
||||
->setMethods(array("postJSON"))
|
||||
->setConstructorArgs(array($this->config))
|
||||
->getMock();
|
||||
|
||||
// Expect postJSON to be called
|
||||
$this->notification->expects($this->once())
|
||||
->method("postJSON")
|
||||
->with($this->equalTo("https://notify.bugsnag.com"),
|
||||
$this->anything());
|
||||
|
||||
// Add an error to the notification and deliver it
|
||||
$this->notification->addError($this->getError());
|
||||
$this->notification->deliver();
|
||||
}
|
||||
|
||||
public function testBeforeNotifySkipsError()
|
||||
{
|
||||
$this->notification->expects($this->never())
|
||||
->method("postJSON");
|
||||
|
||||
$this->notification->addError($this->getError("SkipMe", "Message"));
|
||||
$this->notification->deliver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ensuring that the addError method calls shouldNotify
|
||||
*
|
||||
* If shouldNotify returns false, the error should not be added
|
||||
*/
|
||||
public function testAddErrorChecksShouldNotifyFalse()
|
||||
{
|
||||
$config = $this->getMockBuilder('Bugsnag_Configuration')
|
||||
->setMethods(array("shouldNotify"))
|
||||
->getMock();
|
||||
$config->expects($this->once())
|
||||
->method('shouldNotify')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
/** @var Bugsnag_Notification $notification */
|
||||
$notification = $this->getMockBuilder('Bugsnag_Notification')
|
||||
->setMethods(array("postJSON"))
|
||||
->setConstructorArgs(array($config))
|
||||
->getMock();
|
||||
|
||||
$this->assertFalse($notification->addError($this->getError()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for ensuring that the deliver method calls shouldNotify
|
||||
*
|
||||
* If shouldNotify returns false, the error should not be sent
|
||||
*/
|
||||
public function testDeliverChecksShouldNotify()
|
||||
{
|
||||
$config = $this->getMockBuilder('Bugsnag_Configuration')
|
||||
->setMethods(array("shouldNotify"))
|
||||
->getMock();
|
||||
$config->expects($this->once())
|
||||
->method('shouldNotify')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject $notification */
|
||||
$notification = $this->getMockBuilder('Bugsnag_Notification')
|
||||
->setMethods(array("postJSON"))
|
||||
->setConstructorArgs(array($config))
|
||||
->getMock();
|
||||
|
||||
$notification->expects($this->never())
|
||||
->method("postJSON");
|
||||
|
||||
$notification->addError($this->getError());
|
||||
$notification->deliver();
|
||||
}
|
||||
|
||||
public function testNoEnvironmentByDefault()
|
||||
{
|
||||
$_ENV["SOMETHING"] = "blah";
|
||||
|
||||
$notification = new Bugsnag_Notification($this->config);
|
||||
$notification->addError($this->getError());
|
||||
$notificationArray = $notification->toArray();
|
||||
$this->assertArrayNotHasKey("Environment", $notificationArray["events"][0]["metaData"]);
|
||||
}
|
||||
|
||||
public function testEnvironmentPresentWhenRequested()
|
||||
{
|
||||
$_ENV["SOMETHING"] = "blah";
|
||||
|
||||
$this->config->sendEnvironment = true;
|
||||
$notification = new Bugsnag_Notification($this->config);
|
||||
$notification->addError($this->getError());
|
||||
$notificationArray = $notification->toArray();
|
||||
$this->assertEquals($notificationArray["events"][0]["metaData"]["Environment"]["SOMETHING"], "blah");
|
||||
}
|
||||
}
|
||||
|
||||
function before_notify_skip_error($error)
|
||||
{
|
||||
return $error->name != "SkipMe";
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
class RequestTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = "GET";
|
||||
$_SERVER['REQUEST_URI'] = "/blah/blah.php?some=param";
|
||||
$_SERVER['REMOTE_ADDR'] = "123.45.67.8";
|
||||
$_SERVER['SERVER_PORT'] = "80";
|
||||
$_SERVER['HTTP_HOST'] = "example.com";
|
||||
$_SERVER['HTTP_USER_AGENT'] = "Example Browser 1.2.3";
|
||||
|
||||
$_COOKIE = array("cookie" => "cookieval");
|
||||
$_SESSION = array("session" => "sessionval");
|
||||
}
|
||||
|
||||
public function testIsRequest()
|
||||
{
|
||||
$this->assertTrue(Bugsnag_Request::isRequest());
|
||||
}
|
||||
|
||||
public function testGetContext()
|
||||
{
|
||||
$this->assertEquals(Bugsnag_Request::getContext(), "GET /blah/blah.php");
|
||||
}
|
||||
|
||||
public function testGetCurrentUrl()
|
||||
{
|
||||
$this->assertEquals(Bugsnag_Request::getCurrentUrl(), "http://example.com/blah/blah.php?some=param");
|
||||
}
|
||||
|
||||
public function testRequestIp()
|
||||
{
|
||||
$this->assertEquals(Bugsnag_Request::getRequestIp(), "123.45.67.8");
|
||||
}
|
||||
}
|
@@ -1,211 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'Bugsnag_TestCase.php';
|
||||
|
||||
class StacktraceTest extends Bugsnag_TestCase
|
||||
{
|
||||
/** @var Bugsnag_Configuration */
|
||||
protected $config;
|
||||
/** @var Bugsnag_Diagnostics */
|
||||
protected $diagnostics;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->config = new Bugsnag_Configuration();
|
||||
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
|
||||
}
|
||||
|
||||
protected function assertFrameEquals($frame, $method, $file, $line)
|
||||
{
|
||||
$this->assertEquals($frame["method"], $method);
|
||||
$this->assertEquals($frame["file"], $file);
|
||||
$this->assertEquals($frame["lineNumber"], $line);
|
||||
}
|
||||
|
||||
protected function assertCodeEquals($expected, $actual)
|
||||
{
|
||||
$this->assertEquals(rtrim(substr($expected, 0, 200)), $actual);
|
||||
}
|
||||
|
||||
public function testFromFrame()
|
||||
{
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, "some_file.php", 123)->toarray();
|
||||
|
||||
$this->assertCount(1, $stacktrace);
|
||||
$this->assertFrameEquals($stacktrace[0], "[unknown]", "some_file.php", 123);
|
||||
}
|
||||
|
||||
public function testFrameInsideBugsnag()
|
||||
{
|
||||
$frame = $this->getJsonFixture('frames/non_bugsnag.json');
|
||||
$bugsnagFrame = $this->getJsonFixture('frames/bugsnag.json');
|
||||
|
||||
$this->assertFalse(Bugsnag_Stacktrace::frameInsideBugsnag($frame));
|
||||
$this->assertTrue(Bugsnag_Stacktrace::frameInsideBugsnag($bugsnagFrame));
|
||||
}
|
||||
|
||||
public function testTriggeredErrorStacktrace()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/trigger_error.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
|
||||
|
||||
$this->assertCount(4, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], "trigger_error", "[internal]", 0);
|
||||
$this->assertFrameEquals($stacktrace[1], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 17);
|
||||
$this->assertFrameEquals($stacktrace[2], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
|
||||
$this->assertFrameEquals($stacktrace[3], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 20);
|
||||
}
|
||||
|
||||
public function testErrorHandlerStacktrace()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/error_handler.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
|
||||
|
||||
$this->assertCount(3, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 22);
|
||||
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
|
||||
$this->assertFrameEquals($stacktrace[2], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 25);
|
||||
}
|
||||
|
||||
public function testExceptionHandlerStacktrace()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/exception_handler.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
|
||||
|
||||
$this->assertCount(3, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 25);
|
||||
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
|
||||
$this->assertFrameEquals($stacktrace[2], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 28);
|
||||
}
|
||||
|
||||
public function testAnonymousFunctionStackframes()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/anonymous_frame.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], "somefile.php", 123)->toArray();
|
||||
|
||||
$this->assertCount(5, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], "Illuminate\\Support\\Facades\\Facade::__callStatic", "somefile.php", 123);
|
||||
$this->assertFrameEquals($stacktrace[1], "Bugsnag\\BugsnagLaravel\\BugsnagFacade::notifyError", "controllers/ExampleController.php", 12);
|
||||
$this->assertFrameEquals($stacktrace[2], "ExampleController::index", "controllers/ExampleController.php", 12);
|
||||
$this->assertFrameEquals($stacktrace[3], "call_user_func_array", "[internal]", 0);
|
||||
$this->assertFrameEquals($stacktrace[4], "[main]", "Routing/Controller.php", 194);
|
||||
}
|
||||
|
||||
public function testXdebugErrorStackframes()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/xdebug_error.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
|
||||
|
||||
$this->assertCount(7, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], null, "somefile.php", 123);
|
||||
$this->assertFrameEquals($stacktrace[1], "Illuminate\\View\\Engines\\PhpEngine::evaluatePath", "/View/Engines/PhpEngine.php", 39);
|
||||
$this->assertFrameEquals($stacktrace[2], "Illuminate\\View\\Engines\\CompilerEngine::get", "View/Engines/CompilerEngine.php", 57);
|
||||
$this->assertFrameEquals($stacktrace[3], "Illuminate\\View\\View::getContents", "View/View.php", 136);
|
||||
$this->assertFrameEquals($stacktrace[4], "Illuminate\\View\\View::renderContents", "View/View.php", 104);
|
||||
$this->assertFrameEquals($stacktrace[5], "Illuminate\\View\\View::render", "View/View.php", 78);
|
||||
$this->assertFrameEquals($stacktrace[6], "[main]", "storage/views/f2df2d6b49591efeb36fc46e6dc25e0e", 5);
|
||||
}
|
||||
|
||||
public function testEvaledStackframes()
|
||||
{
|
||||
$evalFrame = $this->getJsonFixture('frames/eval.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $evalFrame["file"], $evalFrame["line"])->toArray();
|
||||
$topFrame = $stacktrace[0];
|
||||
|
||||
$this->assertEquals($topFrame["file"], "path/some/file.php");
|
||||
$this->assertEquals($topFrame["lineNumber"], 123);
|
||||
|
||||
$evalFrame = $this->getJsonFixture('frames/runtime_created.json');
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $evalFrame["file"], $evalFrame["line"])->toArray();
|
||||
$topFrame = $stacktrace[0];
|
||||
|
||||
$this->assertEquals($topFrame["file"], "path/some/file.php");
|
||||
$this->assertEquals($topFrame["lineNumber"], 123);
|
||||
}
|
||||
|
||||
public function testStrippingPaths()
|
||||
{
|
||||
$fixture = $this->getJsonFixture('backtraces/exception_handler.json');
|
||||
$this->config->setStripPath("/Users/james/src/bugsnag/bugsnag-php/");
|
||||
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
|
||||
|
||||
$this->assertCount(3, $stacktrace);
|
||||
|
||||
$this->assertFrameEquals($stacktrace[0], "crashy_function", "testing.php", 25);
|
||||
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "testing.php", 13);
|
||||
$this->assertFrameEquals($stacktrace[2], "[main]", "testing.php", 28);
|
||||
}
|
||||
|
||||
public function testCode()
|
||||
{
|
||||
$fileContents = explode("\n", $this->getFixture('code/File.php'));
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 12)->toArray();
|
||||
$this->assertCount(1, $stacktrace);
|
||||
|
||||
$topFrame = $stacktrace[0];
|
||||
$this->assertCount(7, $topFrame["code"]);
|
||||
|
||||
for ($i=9; $i<=15; $i++) {
|
||||
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCodeShortFile()
|
||||
{
|
||||
$fileContents = explode("\n", $this->getFixture('code/ShortFile.php'));
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/ShortFile.php'), 1)->toArray();
|
||||
$this->assertCount(1, $stacktrace);
|
||||
|
||||
$topFrame = $stacktrace[0];
|
||||
$this->assertCount(3, $topFrame["code"]);
|
||||
|
||||
for ($i=1; $i<=2; $i++) {
|
||||
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCodeEndOfFile()
|
||||
{
|
||||
$fileContents = explode("\n", $this->getFixture('code/File.php'));
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 22)->toArray();
|
||||
$this->assertCount(1, $stacktrace);
|
||||
|
||||
$topFrame = $stacktrace[0];
|
||||
$this->assertCount(7, $topFrame["code"]);
|
||||
|
||||
for ($i=16; $i<=22; $i++) {
|
||||
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCodeStartOfFile()
|
||||
{
|
||||
$fileContents = explode("\n", $this->getFixture('code/File.php'));
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 1)->toArray();
|
||||
$this->assertCount(1, $stacktrace);
|
||||
|
||||
$topFrame = $stacktrace[0];
|
||||
$this->assertCount(7, $topFrame["code"]);
|
||||
|
||||
for ($i=1; $i<=7; $i++) {
|
||||
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCodeDisabled()
|
||||
{
|
||||
$config = new Bugsnag_Configuration();
|
||||
$config->sendCode = false;
|
||||
|
||||
$stacktrace = Bugsnag_Stacktrace::fromFrame($config, $this->getFixturePath('code/File.php'), 1)->toArray();
|
||||
$this->assertCount(1, $stacktrace);
|
||||
|
||||
$topFrame = $stacktrace[0];
|
||||
$this->assertArrayNotHasKey('code', $topFrame);
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "controllers/ExampleController.php",
|
||||
"line": "12",
|
||||
"class": "Illuminate\\Support\\Facades\\Facade",
|
||||
"function": "__callStatic"
|
||||
},
|
||||
{
|
||||
"file": "controllers/ExampleController.php",
|
||||
"line": "12",
|
||||
"class": "Bugsnag\\BugsnagLaravel\\BugsnagFacade",
|
||||
"function": "notifyError"
|
||||
},
|
||||
{
|
||||
"class": "ExampleController",
|
||||
"function": "index"
|
||||
},
|
||||
{
|
||||
"file": "Routing/Controller.php",
|
||||
"line": "194",
|
||||
"function": "call_user_func_array"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 22,
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
|
||||
"line": 116,
|
||||
"function": "generate",
|
||||
"class": "Bugsnag_Stacktrace"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
|
||||
"line": 25,
|
||||
"function": "setPHPError",
|
||||
"class": "Bugsnag_Error"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Client.php",
|
||||
"line": 346,
|
||||
"function": "fromPHPError",
|
||||
"class": "Bugsnag_Error"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 22,
|
||||
"function": "errorHandler",
|
||||
"class": "Bugsnag_Client"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 13,
|
||||
"function": "crashy_function"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 25,
|
||||
"function": "parent_of_crashy_function"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 25,
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 13,
|
||||
"function": "crashy_function"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 28,
|
||||
"function": "parent_of_crashy_function"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 17,
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
|
||||
"line": 116,
|
||||
"function": "generate",
|
||||
"class": "Bugsnag_Stacktrace"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
|
||||
"line": 25,
|
||||
"function": "setPHPError",
|
||||
"class": "Bugsnag_Error"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Client.php",
|
||||
"line": 346,
|
||||
"function": "fromPHPError",
|
||||
"class": "Bugsnag_Error"
|
||||
},
|
||||
{
|
||||
"function": "errorHandler",
|
||||
"class": "Bugsnag_Client"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 17,
|
||||
"function": "trigger_error"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 13,
|
||||
"function": "crashy_function"
|
||||
},
|
||||
{
|
||||
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
|
||||
"line": 20,
|
||||
"function": "parent_of_crashy_function"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"file": "somefile.php",
|
||||
"line": 123,
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "/View/Engines/PhpEngine.php",
|
||||
"line": 39,
|
||||
"include_filename": "storage/framework/views/9159822bf9c110749a4f033b96974fef",
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"function": "evaluatePath",
|
||||
"type": "->",
|
||||
"class": "Illuminate\\View\\Engines\\PhpEngine",
|
||||
"file": "View/Engines/CompilerEngine.php",
|
||||
"line": 57,
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"function": "get",
|
||||
"type": "->",
|
||||
"class": "Illuminate\\View\\Engines\\CompilerEngine",
|
||||
"file": "View/View.php",
|
||||
"line": 136,
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"function": "getContents",
|
||||
"type": "->",
|
||||
"class": "Illuminate\\View\\View",
|
||||
"file": "View/View.php",
|
||||
"line": 104,
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"function": "renderContents",
|
||||
"type": "->",
|
||||
"class": "Illuminate\\View\\View",
|
||||
"file": "View/View.php",
|
||||
"line": 78,
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"function": "render",
|
||||
"type": "->",
|
||||
"class": "Illuminate\\View\\View",
|
||||
"file": "storage/views/f2df2d6b49591efeb36fc46e6dc25e0e",
|
||||
"line": 5,
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
<?
|
||||
|
||||
//
|
||||
// Example PHP file
|
||||
//
|
||||
|
||||
// Some variables
|
||||
$a = 1;
|
||||
$b = 2;
|
||||
|
||||
// Create an exception
|
||||
$exception = new Exception("Exception!");
|
||||
|
||||
// Throw the exception
|
||||
throw $exception;
|
||||
|
||||
// Some more variables
|
||||
$c = 3;
|
||||
$d = 4;
|
||||
|
||||
?>
|
@@ -1,2 +0,0 @@
|
||||
$a = 1;
|
||||
$b = 2;
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"file": "Bugsnag/Client.php",
|
||||
"line": "123",
|
||||
"class": "Bugsnag_Client",
|
||||
"function": "example_function"
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"file": "path/some/file.php(123) : eval()'d code",
|
||||
"line": "12",
|
||||
"function": "something"
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"file": "controllers/ExampleController.php",
|
||||
"line": "12",
|
||||
"class": "Illuminate\\Support\\Facades\\Facade",
|
||||
"function": "__callStatic"
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"file": "path/some/file.php(123) : runtime-created function",
|
||||
"line": "12",
|
||||
"function": "something"
|
||||
}
|
22
vendor/chumper/datatable/.gitattributes
vendored
22
vendor/chumper/datatable/.gitattributes
vendored
@@ -1,22 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
6
vendor/chumper/datatable/.gitignore
vendored
6
vendor/chumper/datatable/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
datatable.sublime-project
|
||||
.DS_Store
|
||||
.idea
|
12
vendor/chumper/datatable/.travis.yml
vendored
12
vendor/chumper/datatable/.travis.yml
vendored
@@ -1,12 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev
|
||||
|
||||
script: phpunit
|
614
vendor/chumper/datatable/README.md
vendored
614
vendor/chumper/datatable/README.md
vendored
@@ -1,614 +0,0 @@
|
||||
Datatable
|
||||
=========
|
||||
|
||||
This is a __Laravel 5 package__ for the server and client side of datatables at http://datatables.net/
|
||||
|
||||

|
||||
|
||||
##Known Issues
|
||||
|
||||
* none i know of so far
|
||||
|
||||
##TODO
|
||||
|
||||
* fix incoming bugs
|
||||
* code documentaion
|
||||
|
||||
##Features
|
||||
|
||||
This package supports:
|
||||
|
||||
* Support for Collections and Query Builder
|
||||
* Easy to add and order columns
|
||||
* Includes a simple helper for the HTML side
|
||||
* Use your own functions and presenters in your columns
|
||||
* Search in your custom defined columns ( Collection only!!! )
|
||||
* Define your specific fields for searching and ordering
|
||||
* Add custom javascript values for the table
|
||||
* Tested! (Ok, maybe not fully, but I did my best :) )
|
||||
|
||||
## Please note!
|
||||
|
||||
There are some differences between the collection part and the query part of this package.
|
||||
The differences are:
|
||||
|
||||
| Difference | Collection | Query |
|
||||
| --- |:----------:| :----:|
|
||||
|Speed | - | + |
|
||||
Custom fields | + | +
|
||||
Search in custom fields | + | -
|
||||
Order by custom fields | + | -
|
||||
Search outside the shown data (e.g.) database | - | +
|
||||
|
||||
For a detailed explanation please see the video below.
|
||||
http://www.youtube.com/watch?v=c9fao_5Jo3Y
|
||||
|
||||
Please let me know any issues or features you want to have in the issues section.
|
||||
I would be really thankful if you can provide a test that points to the issue.
|
||||
|
||||
##Installation
|
||||
|
||||
This package is available on http://packagist.org, just add it to your composer.json
|
||||
|
||||
"chumper/datatable": "dev-develop"
|
||||
|
||||
Alternatively, you can install it using the `composer` command:
|
||||
|
||||
composer require chumper/datatable "dev-develop"
|
||||
|
||||
|
||||
In Config/App.php: Add line Provider:
|
||||
|
||||
```php
|
||||
'Chumper\Datatable\DatatableServiceProvider',
|
||||
```
|
||||
|
||||
__If using Laravel 5.1:__ you will want to add:
|
||||
```php
|
||||
Chumper\Datatable\DatatableServiceProvider::class,
|
||||
```
|
||||
|
||||
Add line Alias:
|
||||
```php
|
||||
//new
|
||||
'Datatable' => 'Chumper\Datatable\Facades\DatatableFacade',
|
||||
```
|
||||
|
||||
You can then access it under the `Datatable` alias.
|
||||
|
||||
##Basic Usage
|
||||
|
||||
There are two ways you can use the plugin, within one route or within two routes:
|
||||
|
||||
###Two routes
|
||||
|
||||
* Create two routes: One to deliver the view to the user, the other for datatable data, eg:
|
||||
|
||||
```php
|
||||
Route::resource('users', 'UsersController');
|
||||
Route::get('api/users', array('as'=>'api.users', 'uses'=>'UsersController@getDatatable'));
|
||||
```
|
||||
|
||||
* Your main route will deliver a view to the user. This view should include references to your local copy of [datatables](http://datatables.net/). In the example below, files were copied from the datatables/media directories and written to public/assets. Please note that the scripts must be located above the call to Datatable:
|
||||
|
||||
```php
|
||||
<link rel="stylesheet" type="text/css" href="/assets/css/jquery.dataTables.css">
|
||||
<script type="text/javascript" src="/assets/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="/assets/js/jquery.dataTables.min.js"></script>
|
||||
|
||||
{!! Datatable::table()
|
||||
->addColumn('id','Name') // these are the column headings to be shown
|
||||
->setUrl(route('api.users')) // this is the route where data will be retrieved
|
||||
->render() !!}
|
||||
```
|
||||
|
||||
* Create a controller function to return your data in a way that can be read by Datatables:
|
||||
|
||||
```php
|
||||
public function getDatatable()
|
||||
{
|
||||
return Datatable::collection(User::all(array('id','name')))
|
||||
->showColumns('id', 'name')
|
||||
->searchColumns('name')
|
||||
->orderColumns('id','name')
|
||||
->make();
|
||||
}
|
||||
```
|
||||
|
||||
You should now have a working datatable on your page.
|
||||
|
||||
###One route
|
||||
|
||||
In your route you should use the Datatable::shouldHandle method which will check whether the plugin should handle the request or not.
|
||||
|
||||
```php
|
||||
if(Datatable::shouldHandle())
|
||||
{
|
||||
return Datatable::collection(User::all(array('id','name')))
|
||||
->showColumns('id', 'name')
|
||||
->searchColumns('name')
|
||||
->orderColumns('id','name')
|
||||
->make();
|
||||
}
|
||||
```
|
||||
|
||||
The plugin will then query the same url for information. The shouldHandle method just checks for an ajax request and if sEcho is set.
|
||||
|
||||
##HTML Example
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn('id',Lang::get('user.lastname'))
|
||||
->setUrl(URL::to('auth/users/table'))
|
||||
->render();
|
||||
```
|
||||
|
||||
With seperate table and script:
|
||||
```php
|
||||
$table = Datatable::table()
|
||||
->addColumn('Email2','Email', "Test")
|
||||
->noScript();
|
||||
|
||||
// to render the table:
|
||||
$table->render()
|
||||
|
||||
// later in the view you can render the javascript:
|
||||
$table->script();
|
||||
```
|
||||
|
||||
This will generate a HTML table with two columns (id, lastname -> your translation) and will set the URL for the ajax request.
|
||||
|
||||
> Note: This package will **NOT** include the `datatable.js`, that is your work to do.
|
||||
> The reason is that for example i use Basset and everybody wants to do it their way...
|
||||
|
||||
If you want to provide your own template for the table just provide the path to the view in laravel style.
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn('id',Lang::get('user.lastname'))
|
||||
->setUrl(URL::to('auth/users/table'))
|
||||
->render('views.templates.datatable');
|
||||
```
|
||||
##Server Example
|
||||
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->showColumns('id')
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->getPresenter()->yourProperty;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
|
||||
This will generate a server side datatable handler from the collection `User::all()`.
|
||||
It will add the `id` column to the result and also a custom column called `name`.
|
||||
Please note that we need to pass a function as a second parameter, it will **always** be called
|
||||
with the object the collection holds. In this case it would be the `User` model.
|
||||
|
||||
You could now also access all relationship, so it would be easy for a book model to show the author relationship.
|
||||
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->showColumns('id')
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->author->name;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
|
||||
> Note: If you pass a collection of arrays to the `collection` method you will have an array in the function, not a model.
|
||||
|
||||
The order of the columns is always defined by the user and will be the same order the user adds the columns to the Datatable.
|
||||
|
||||
##Query or Collection?
|
||||
|
||||
There is a difference between query() and collection().
|
||||
A collection will be compiled before any operation - like search or order - will be performed so that it can also include your custom fields.
|
||||
This said the collection method is not as performing as the query method where the search and order will be tackled before we query the database.
|
||||
|
||||
So if you have a lot of Entries (100k+) a collection will not perform well because we need to compile the whole amount of entries to provide accurate sets.
|
||||
A query on the other side is not able to perform a search or orderBy correctly on your custom field functions.
|
||||
|
||||
> TLTR: If you have no custom fields, then use query() it will be much faster
|
||||
> If you have custom fields but don't want to provide search and/or order on the fields use query().
|
||||
> Collection is the choice if you have data from somewhere else, just wrap it into a collection and you are good to go.
|
||||
> If you have custom fields and want to provide search and/or order on these, you need to use a collection.
|
||||
|
||||
Please also note that there is a significant difference betweeen the search and order functionality if you use query compared to collections.
|
||||
Please see the following video for more details.
|
||||
|
||||
http://www.youtube.com/watch?v=c9fao_5Jo3Y
|
||||
|
||||
##Available functions
|
||||
|
||||
This package is separated into two smaller parts:
|
||||
|
||||
1. Datatable::table()
|
||||
2. Datatable::collection()
|
||||
3. Datatable::query()
|
||||
|
||||
The second and third one is for the server side, the first one is a helper to generate the needed table and javascript calls.
|
||||
|
||||
###Collection & Query
|
||||
|
||||
**collection($collection)**
|
||||
|
||||
Will set the internal engine to the collection.
|
||||
For further performance improvement you can limit the number of columns and rows, i.e.:
|
||||
|
||||
$users = User::activeOnly()->get('id','name');
|
||||
Datatable::collection($users)->...
|
||||
|
||||
**query($query)**
|
||||
|
||||
This will set the internal engine to a Eloquent query...
|
||||
E.g.:
|
||||
|
||||
$users = DB::table('users');
|
||||
Datatable::query($users)->...
|
||||
|
||||
The query engine is much faster than the collection engine but also lacks some functionality,
|
||||
for further information look at the table above.
|
||||
|
||||
**showColumns(...$columns)**
|
||||
|
||||
This will add the named columns to the result.
|
||||
> Note: You need to pass the name in the format you would access it on the model or array.
|
||||
> example: in the db: `last_name`, on the model `lastname` -> showColumns('lastname')
|
||||
|
||||
You can provide as many names as you like
|
||||
|
||||
**searchColumns(..$fields)**
|
||||
|
||||
Will enable the table to allow search only in the given columns.
|
||||
Please note that a collection behaves different to a builder object.
|
||||
|
||||
Note: If you want to search on number columns with the query engine, then you can also pass a search column like this
|
||||
```
|
||||
//mysql
|
||||
->searchColumns(array('id:char:255', 'first_name', 'last_name', 'address', 'email', 'age:char:255'))
|
||||
|
||||
//postgree
|
||||
->searchColumns(array('id:text', 'first_name', 'last_name', 'address', 'email', 'age:text'))
|
||||
```
|
||||
|
||||
This will cast the columns int the given types when searching on this columns
|
||||
|
||||
**orderColumns(..$fields)**
|
||||
|
||||
Will enable the table to allow ordering only in the given columns.
|
||||
Please note that a collection behaves different to a builder object.
|
||||
|
||||
**addColumn($name, $function)**
|
||||
|
||||
Will add a custom field to the result set, in the function you will get the whole model or array for that row
|
||||
E.g.:
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->author->name;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
You can also just add a predefined Column, like a DateColumn, a FunctionColumn, or a TextColumn
|
||||
E.g.:
|
||||
|
||||
```php
|
||||
$column = new TextColumn('foo', 'bar'); // Will always return the text bar
|
||||
//$column = new FunctionColumn('foo', function($model){return $model->bar}); // Will return the bar column
|
||||
//$column = new DateColumn('foo', DateColumn::TIME); // Will return the foo date object as toTimeString() representation
|
||||
//$column = new DateColumn('foo', DateColumn::CUSTOM, 'd.M.Y H:m:i'); // Will return the foo date object as custom representation
|
||||
|
||||
Datatable::collection(User::all())
|
||||
->addColumn($column)
|
||||
->make();
|
||||
```
|
||||
|
||||
You can also overwrite the results returned by the QueryMethod by using addColumn in combination with showColumns.
|
||||
You must name the column exactly like the database column that you're displaying using showColumns in order for this to work.
|
||||
|
||||
```php
|
||||
$column = new FunctionColumn('foo', function ($row) { return strtolower($row->foo); }
|
||||
Datatable::query(DB::table('table')->lists('foo'))
|
||||
->showColumns('foo')
|
||||
->addColumn($column)
|
||||
->orderColumns('foo')
|
||||
->searchColumns('foo')
|
||||
->make()
|
||||
```
|
||||
This will allow you to have sortable and searchable columns using the QueryEngine while also allowing you to modify the return value of that database column entry.
|
||||
|
||||
Eg: linking an user_id column to it's page listing
|
||||
```php
|
||||
$column = new FunctionColumn('user_id', function ($row) { return link_to('users/'.$row->user_id, $row->username) }
|
||||
Datatable::query(DB::table('table')->lists('user_id', 'username'))
|
||||
->showColumns('user_id')
|
||||
->addColumn($column)
|
||||
->orderColumns('user_id')
|
||||
->searchColumns('user_id')
|
||||
```
|
||||
|
||||
|
||||
Please look into the specific Columns for further information.
|
||||
|
||||
**setAliasMapping()**
|
||||
|
||||
Will advise the Datatable to return the data mapped with the column name.
|
||||
So instead of
|
||||
```javascript
|
||||
{
|
||||
"aaData":[
|
||||
[3,"name","2014-02-02 23:28:14"]
|
||||
],
|
||||
"sEcho":9,
|
||||
"iTotalRecords":2,
|
||||
"iTotalDisplayRecords":1
|
||||
}
|
||||
```
|
||||
you will get something like this as response
|
||||
```javascript
|
||||
{
|
||||
"aaData":[
|
||||
{"id":2,"name":"Datatable","created_at":"Sun, Feb 2, 2014 7:17 PM"}
|
||||
],
|
||||
"sEcho":2,
|
||||
"iTotalRecords":2,
|
||||
"iTotalDisplayRecords":1
|
||||
}
|
||||
```
|
||||
|
||||
**make()**
|
||||
|
||||
This will handle the input data of the request and provides the result set.
|
||||
> Without this command no response will be returned.
|
||||
|
||||
**clearColumns()**
|
||||
|
||||
This will reset all columns, mainly used for testing and debugging, not really useful for you.
|
||||
> If you don't provide any column with `showColumn` or `addColumn` then no column will be shown.
|
||||
> The columns in the query or collection do not have any influence which column will be shown.
|
||||
|
||||
**getOrder()**
|
||||
|
||||
This will return an array with the columns that will be shown, mainly used for testing and debugging, not really useful for you.
|
||||
|
||||
**getColumn($name)**
|
||||
|
||||
Will get a column by its name, mainly used for testing and debugging, not really useful for you.
|
||||
|
||||
###Specific QueryEngine methods
|
||||
|
||||
**setSearchWithAlias()**
|
||||
|
||||
If you want to use an alias column on the query engine and you don't get the correct results back while searching then you should try this flag.
|
||||
E.g.:
|
||||
```php
|
||||
Datatable::from(DB::table("users")->select('firstname', "users.email as email2")->join('partners','users.partner_id','=','partners.id'))
|
||||
->showColumns('firstname','email2')
|
||||
->setSearchWithAlias()
|
||||
->searchColumns("email2")
|
||||
```
|
||||
|
||||
In SQL it is not allowed to have an alias in the where part (used for searching) and therefore the results will not counted correctly.
|
||||
|
||||
With this flag you enable aliases in the search part (email2 in searchColumns).
|
||||
|
||||
Please be aware that this flag will slow down your application, since we are getting the results back twice to count them manually.
|
||||
|
||||
|
||||
**setSearchOperator($value = "LIKE")**
|
||||
|
||||
With this method you can set the operator on searches like "ILIKE" on PostgreSQL for case insensitivity.
|
||||
|
||||
**setExactWordSearch**
|
||||
|
||||
Will advice the engines only to search for the exact given search string.
|
||||
|
||||
###Specific CollectionEngine methods
|
||||
|
||||
**setSearchStrip() & setOrderStrip()**
|
||||
|
||||
If you use the search functionality then you can advice
|
||||
all columns to strip any HTML and PHP tags before searching this column.
|
||||
|
||||
This can be useful if you return a link to the model detail but still want to provide search ability in this column.
|
||||
|
||||
**setCaseSensitive($boolean = 'false')**
|
||||
|
||||
Set the search method to case sensitive or not, default is false
|
||||
|
||||
###Table
|
||||
|
||||
**noScript()**
|
||||
|
||||
With setting this property the Table will not render the javascript part.
|
||||
|
||||
You can render it manually with
|
||||
|
||||
**script($view = null)**
|
||||
|
||||
Will render the javascript if no view is given or the default one and will pass the class name, the options and the callbacks.
|
||||
|
||||
Example:
|
||||
|
||||
```php
|
||||
$table = Datatable::table()
|
||||
->addColumn('Email2','Email', "Test")
|
||||
->noScript();
|
||||
|
||||
// to render the table:
|
||||
$table->render()
|
||||
|
||||
// later in the view you can render the javascript:
|
||||
$table->script();
|
||||
```
|
||||
|
||||
**setUrl($url)**
|
||||
|
||||
Will set the URL and options for fetching the content via ajax.
|
||||
|
||||
**setOptions($name, $value) OR setOptions($array)**
|
||||
|
||||
Will set a single option or an array of options for the jquery call.
|
||||
|
||||
You can pass as paramater something like this ('MyOption', 'ValueMyOption') or an Array with parameters, but some values in DataTable is a JSON so how can i pass a JSON in values? Use another array, like that:
|
||||
setOptions(array("MyOption"=> array('MyAnotherOption'=> 'MyAnotherValue', 'MyAnotherOption2'=> 'MyAnotherValue2')));
|
||||
|
||||
```js
|
||||
|
||||
//GENERATE
|
||||
|
||||
jQuery(.Myclass).DataTable({
|
||||
MyOption: {
|
||||
MyAnotherOption: MyAnotherValue,
|
||||
MyAnotherOption2: MyAnotherValue2,
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
As a sugestion, take a look at this 2 files javascript.blade.php && template.blade.php in vendor/Chumper/datatable/src/views. You'll understand all the logic and see why it's important to pass the parameter like an array (json_encode and others stuffs).
|
||||
|
||||
**setCallbacks($name, $value) OR setCallbacks($array)**
|
||||
|
||||
Will set a single callback function or an array of callbacks for the jquery call. DataTables callback functions are described at https://datatables.net/usage/callbacks. For example,
|
||||
|
||||
```php
|
||||
->setCallbacks(
|
||||
'fnServerParams', 'function ( aoData ) {
|
||||
aoData.push( { "name": "more_data", "value": "my_value" } );
|
||||
}'
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
**addColumn($name)**
|
||||
|
||||
Will add a column to the table, where the name will be rendered on the table head.
|
||||
So you can provide the string that should be shown.
|
||||
|
||||
if you want to use the alias mapping feature of the server side table then you need to add an array like this
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn(array(
|
||||
'id' => 'ID',
|
||||
'name' => 'Name',
|
||||
'created_at' => 'Erstellt'
|
||||
))
|
||||
->render();
|
||||
```
|
||||
Please note that passing an assosiative array to the addColumn function will automatically enable the alias function on the table
|
||||
|
||||
**setAliasMapping(boolean)**
|
||||
|
||||
Here you can explicitly set if the table should be aliased or not.
|
||||
|
||||
**countColumns()**
|
||||
|
||||
This will return the number of columns that will be rendered later. Mainly for testing and debugging.
|
||||
|
||||
**getData()**
|
||||
|
||||
Will return the data that will be rendered into the table as an array.
|
||||
|
||||
**getOptions()**
|
||||
|
||||
Get all options as an array.
|
||||
|
||||
**render($view = template.blade)**
|
||||
|
||||
Renders the table. You can customize this by passing a view name.
|
||||
Please see the template inside the package for further information of how the data is passed to the view.
|
||||
|
||||
**setData($data)**
|
||||
|
||||
Expects an array of arrays and will render this data when the table is shown.
|
||||
|
||||
**setCustomValues($name, $value) OR setCustomValues($array)**
|
||||
|
||||
Will set a single custom value, or an array of custom values, which will be passed to the view. You can access these values in your custom view file. For example, if you wanted to click anywhere on a row to go to a record (where the record id is in the first column of the table):
|
||||
|
||||
In the calling view:
|
||||
|
||||
```php
|
||||
{{ DataTable::table()
|
||||
->addColumn($columns)
|
||||
->setUrl($ajaxRouteToTableData)
|
||||
->setCustomValues('table-url', $pathToTableDataLinks)
|
||||
->render('my.datatable.template') }}
|
||||
```
|
||||
|
||||
In the datatable view (eg, 'my.datatable.template'):
|
||||
|
||||
```js
|
||||
@if (isset($values['table-url']))
|
||||
$('.{{$class}}').hover(function() {
|
||||
$(this).css('cursor', 'pointer');
|
||||
});
|
||||
$('.{{$class}}').on('click', 'tbody tr', function(e) {
|
||||
$id = e.currentTarget.children[0].innerHTML;
|
||||
$url = e.currentTarget.baseURI;
|
||||
document.location.href = "{{ $values['table-url'] }}/" + $id;
|
||||
});
|
||||
@endif
|
||||
```
|
||||
|
||||
|
||||
**setOrder(array $order)**
|
||||
|
||||
Defines the order that a datatable will be ordered by on first page load.
|
||||
```php
|
||||
{{ DataTable::table()
|
||||
->addColumn('ID', 'First Name', 'Last Name')
|
||||
->setUrl($ajaxRouteToTableData)
|
||||
->setOrder(array(2=>'asc', 1=>'asc')) // sort by last name then first name
|
||||
->render('my.datatable.template') }}
|
||||
```
|
||||
##Extras
|
||||
Some extras features, using the Datatables api.
|
||||
|
||||
### - TableTools
|
||||
|
||||
To use TableTools you will need to add some files in your project (https://datatables.net/extensions/tabletools/), if you want some help download the datatable's package and inside the extension folder go to /tabletools and study the examples. After, all the files include, don't forget to pass the parameters like this:
|
||||
|
||||
```js
|
||||
//In view:
|
||||
|
||||
{{
|
||||
Datatable::table()
|
||||
->addColumn('your columns here separated by comma')
|
||||
->setUrl('your URL for server side')
|
||||
->setOptions(array(
|
||||
'dom' =>"T<'clear'>lfrtip",
|
||||
'tabletools' => array(
|
||||
"aSwfPath" => "your/path/to/swf/copy_csv_cls_pdf.swf",
|
||||
"aButtons" => array("copy", "pdf", "xls")
|
||||
)
|
||||
))
|
||||
}}
|
||||
|
||||
```
|
||||
If you want to get some properties like "which row did i click?", see the javascript.blade.php and the variable $values.
|
||||
|
||||
##Contributors
|
||||
|
||||
* [jgoux](https://github.com/jgoux) for helping with searching on number columns in the database
|
||||
* [jijoel](https://github.com/jijoel) for helping with callback options and documentation
|
||||
|
||||
##Changelog
|
||||
|
||||
* 2.0.0:
|
||||
* Seperated Query and Collection Engine
|
||||
* Added single column search
|
||||
* Code cleanup
|
||||
|
||||
##Applications
|
||||
|
||||
https://github.com/hillelcoren/invoice-ninja (by Hillel Coren)
|
||||
|
||||
##License
|
||||
|
||||
This package is licensed under the MIT License
|
38
vendor/chumper/datatable/composer.json
vendored
38
vendor/chumper/datatable/composer.json
vendored
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"name": "chumper/datatable",
|
||||
"description": "This is a laravel 4 package for the server and client side of datatablaes at http://datatables.net/",
|
||||
"keywords" : ["laravel","datatables", "ajax", "jquery"],
|
||||
"license": "MIT",
|
||||
"homepage": "http://github.com/Chumper/datatable",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nils Plaschke",
|
||||
"email": "github@nilsplaschke.de",
|
||||
"homepage": "http://nilsplaschke.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/support": "~5.0",
|
||||
"illuminate/view": "~5.0",
|
||||
"illuminate/config": "~5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"mockery/mockery": "dev-master",
|
||||
"orchestra/testbench": "3.1.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Chumper\\Datatable": "src/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "git://github.com/orchestral/phpseclib.git"
|
||||
}
|
||||
]
|
||||
}
|
BIN
vendor/chumper/datatable/datatable.jpg
vendored
BIN
vendor/chumper/datatable/datatable.jpg
vendored
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
18
vendor/chumper/datatable/phpunit.xml
vendored
18
vendor/chumper/datatable/phpunit.xml
vendored
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
@@ -1,37 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
/**
|
||||
* Class BaseColumn
|
||||
* @package Chumper\Datatable\Columns
|
||||
*/
|
||||
abstract class BaseColumn {
|
||||
|
||||
/**
|
||||
* @var String name of the column
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $model The data to pass to the column,
|
||||
* could be a model or an array
|
||||
* @return mixed the return value of the implementation,
|
||||
* should be text in most of the cases
|
||||
*/
|
||||
public abstract function run($model);
|
||||
|
||||
/**
|
||||
* @return String The name of the column
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class DateColumn extends BaseColumn {
|
||||
|
||||
/**
|
||||
* Constants for the time representation
|
||||
*/
|
||||
const DATE = 0;
|
||||
const TIME = 1;
|
||||
const DATE_TIME = 2;
|
||||
const CUSTOM = 4;
|
||||
const FORMATTED_DATE = 5;
|
||||
const DAY_DATE = 6;
|
||||
|
||||
/**
|
||||
* @var int The format to show
|
||||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* @var string custom show string if chosen
|
||||
*/
|
||||
private $custom;
|
||||
|
||||
function __construct($name, $format = 2, $custom = "")
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->format = $format;
|
||||
$this->custom = $custom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $model The data to pass to the column,
|
||||
* could be a model or an array
|
||||
* @return mixed the return value of the implementation,
|
||||
* should be text in most of the cases
|
||||
*/
|
||||
public function run($model)
|
||||
{
|
||||
|
||||
if(is_string(is_array($model) ? $model[$this->name]: $model->{$this->name}))
|
||||
{
|
||||
return is_array($model) ? $model[$this->name]: $model->{$this->name};
|
||||
}
|
||||
|
||||
switch($this->format)
|
||||
{
|
||||
case DateColumn::DATE:
|
||||
return is_array($model) ? $model[$this->name]->toDateString(): $model->{$this->name}->toDateString();
|
||||
break;
|
||||
case DateColumn::TIME:
|
||||
return is_array($model) ? $model[$this->name]->toTimeString(): $model->{$this->name}->toTimeString();
|
||||
break;
|
||||
case DateColumn::DATE_TIME:
|
||||
return is_array($model) ? $model[$this->name]->toDateTimeString(): $model->{$this->name}->toDateTimeString();
|
||||
break;
|
||||
case DateColumn::CUSTOM:
|
||||
return is_array($model) ? $model[$this->name]->format($this->custom): $model->{$this->name}->format($this->custom);
|
||||
break;
|
||||
case DateColumn::FORMATTED_DATE:
|
||||
return is_array($model) ? $model[$this->name]->toFormattedDateString(): $model->{$this->name}->toFormattedDateString();
|
||||
break;
|
||||
case DateColumn::DAY_DATE:
|
||||
return is_array($model) ? $model[$this->name]->toDayDateTimeString(): $model->{$this->name}->toDayDateTimeString();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class FunctionColumn extends BaseColumn {
|
||||
|
||||
private $callable;
|
||||
|
||||
function __construct($name, $callable)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->callable = $callable;
|
||||
}
|
||||
|
||||
public function run($model)
|
||||
{
|
||||
return call_user_func($this->callable,$model);
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class TextColumn extends BaseColumn {
|
||||
|
||||
private $text;
|
||||
|
||||
function __construct($name, $text)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function run($model)
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Chumper\Datatable\Engines\CollectionEngine;
|
||||
use Chumper\Datatable\Engines\QueryEngine;
|
||||
use Input;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Class Datatable
|
||||
* @package Chumper\Datatable
|
||||
*/
|
||||
class Datatable {
|
||||
|
||||
private $columnNames = array();
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @return \Chumper\Datatable\Engines\QueryEngine
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
$class = config('chumper.datatable.classmap.QueryEngine');
|
||||
return new $class($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collection
|
||||
* @return \Chumper\Datatable\Engines\CollectionEngine
|
||||
*/
|
||||
public function collection($collection)
|
||||
{
|
||||
$class = config('chumper.datatable.classmap.CollectionEngine');
|
||||
return new $class($collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Chumper\Datatable\Table
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
$class = config('chumper.datatable.classmap.Table');
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True if the plugin should handle this request, false otherwise
|
||||
*/
|
||||
public function shouldHandle()
|
||||
{
|
||||
$echo = Input::get('sEcho',null);
|
||||
if(/*Request::ajax() && */!is_null($echo) && is_numeric($echo))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use View;
|
||||
|
||||
class DatatableServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__.'/../../config/config.php' => config_path('chumper.datatable.php'),
|
||||
__DIR__.'/../../views' => base_path('resources/views/vendor/chumper.datatable'),
|
||||
]);
|
||||
|
||||
$this->loadViewsFrom(__DIR__ . '/../../views', 'chumper.datatable');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'chumper.datatable');
|
||||
|
||||
$this->app['datatable'] = $this->app->share(function($app)
|
||||
{
|
||||
return new Datatable;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('datatable');
|
||||
}
|
||||
|
||||
}
|
@@ -1,553 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Exception;
|
||||
use Assetic\Extension\Twig\AsseticFilterFunction;
|
||||
use Chumper\Datatable\Columns\DateColumn;
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
use Chumper\Datatable\Columns\TextColumn;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
|
||||
/**
|
||||
* Class BaseEngine
|
||||
* @package Chumper\Datatable\Engines
|
||||
*/
|
||||
abstract class BaseEngine {
|
||||
|
||||
const ORDER_ASC = 'asc';
|
||||
const ORDER_DESC = 'desc';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $rowClass = null;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $rowId = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $rowData = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $columnSearches = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* support for DB::raw fields on where
|
||||
*/
|
||||
protected $fieldSearches = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* support for DB::raw fields on where
|
||||
* sburkett - added for column-based exact matching
|
||||
*/
|
||||
protected $columnSearchExact = array();
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $sEcho;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $searchColumns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $showColumns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $orderColumns = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $skip = 0;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $limit = null;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $search = null;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
* Will be an array if order is set
|
||||
* array(
|
||||
* 0 => column
|
||||
* 1 => name:cast:length
|
||||
* )
|
||||
*/
|
||||
protected $orderColumn = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $orderDirection = BaseEngine::ORDER_ASC;
|
||||
|
||||
/**
|
||||
* @var boolean If the return should be alias mapped
|
||||
*/
|
||||
protected $aliasMapping = false;
|
||||
|
||||
/**
|
||||
* @var bool If the search should be done with exact matching
|
||||
*/
|
||||
protected $exactWordSearch = false;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->columns = new Collection();
|
||||
$this->config = Config::get('chumper.datatable.engine');
|
||||
$this->setExactWordSearch( $this->config['exactWordSearch'] );
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addColumn()
|
||||
{
|
||||
if(func_num_args() != 2 && func_num_args() != 1)
|
||||
throw new Exception('Invalid number of arguments');
|
||||
|
||||
if(func_num_args() == 1)
|
||||
{
|
||||
//add a predefined column
|
||||
$this->columns->put(func_get_arg(0)->getName(), func_get_arg(0));
|
||||
}
|
||||
else if(is_callable(func_get_arg(1)))
|
||||
{
|
||||
$this->columns->put(func_get_arg(0), new FunctionColumn(func_get_arg(0), func_get_arg(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns->put(func_get_arg(0), new TextColumn(func_get_arg(0),func_get_arg(1)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getColumn($name)
|
||||
{
|
||||
return $this->columns->get($name,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return array_keys($this->columns->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderingColumns()
|
||||
{
|
||||
return $this->orderColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchingColumns()
|
||||
{
|
||||
return $this->searchColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function clearColumns()
|
||||
{
|
||||
$this->columns = new Collection();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function showColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
foreach ($cols as $property) {
|
||||
//quick fix for created_at and updated_at columns
|
||||
if(in_array($property, array('created_at', 'updated_at')))
|
||||
{
|
||||
$this->columns->put($property, new DateColumn($property, DateColumn::DAY_DATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns->put($property, new FunctionColumn($property, function($model) use($property){
|
||||
try{return is_array($model)?$model[$property]:$model->$property;}catch(Exception $e){return null;}
|
||||
}));
|
||||
}
|
||||
$this->showColumns[] = $property;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function make()
|
||||
{
|
||||
//TODO Handle all inputs
|
||||
$this->handleInputs();
|
||||
$this->prepareSearchColumns();
|
||||
|
||||
$output = array(
|
||||
"aaData" => $this->internalMake($this->columns, $this->searchColumns)->toArray(),
|
||||
"sEcho" => intval($this->sEcho),
|
||||
"iTotalRecords" => $this->totalCount(),
|
||||
"iTotalDisplayRecords" => $this->count(),
|
||||
);
|
||||
return Response::json($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function searchColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
$this->searchColumns = $cols;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function orderColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
if (count($cols) == 1 && $cols[0] == '*')
|
||||
$cols = $this->showColumns;
|
||||
|
||||
$this->orderColumns = $cols;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for a dynamic row class
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowClass($function)
|
||||
{
|
||||
$this->rowClass = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for a dynamic row id
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowId($function)
|
||||
{
|
||||
$this->rowId = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for dynamic html5 data attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowData($function)
|
||||
{
|
||||
$this->rowData = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAliasMapping($value = true)
|
||||
{
|
||||
$this->aliasMapping = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setExactWordSearch($value = true)
|
||||
{
|
||||
$this->exactWordSearch = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $columnNames Sets up a lookup table for which columns should use exact matching -sburkett
|
||||
* @return $this
|
||||
*/
|
||||
public function setExactMatchColumns($columnNames)
|
||||
{
|
||||
foreach($columnNames as $columnIndex)
|
||||
$this->columnSearchExact[ $columnIndex ] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRowClass()
|
||||
{
|
||||
return $this->rowClass;
|
||||
}
|
||||
|
||||
public function getRowId()
|
||||
{
|
||||
return $this->rowId;
|
||||
}
|
||||
|
||||
public function getRowData()
|
||||
{
|
||||
return $this->rowData;
|
||||
}
|
||||
|
||||
public function getAliasMapping()
|
||||
{
|
||||
return $this->aliasMapping;
|
||||
}
|
||||
//-------------protected functionS-------------------
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiDisplayStart($value)
|
||||
{
|
||||
//skip
|
||||
$this->skip($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiDisplayLength($value)
|
||||
{
|
||||
//limit nicht am query, sondern den ganzen
|
||||
//holen und dann dynamisch in der Collection taken und skippen
|
||||
$this->take($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handlesEcho($value)
|
||||
{
|
||||
$this->sEcho = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handlesSearch($value)
|
||||
{
|
||||
//handle search on columns sSearch, bRegex
|
||||
$this->search($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiSortCol_0($value)
|
||||
{
|
||||
if(Input::get('sSortDir_0') == 'desc')
|
||||
$direction = BaseEngine::ORDER_DESC;
|
||||
else
|
||||
$direction = BaseEngine::ORDER_ASC;
|
||||
|
||||
//check if order is allowed
|
||||
if(empty($this->orderColumns))
|
||||
{
|
||||
$this->order(array(0 => $value, 1 => $this->getNameByIndex($value)), $direction);
|
||||
return;
|
||||
}
|
||||
|
||||
//prepare order array
|
||||
$cleanNames = array();
|
||||
foreach($this->orderColumns as $c)
|
||||
{
|
||||
if(strpos($c,':') !== FALSE)
|
||||
{
|
||||
$cleanNames[] = substr($c, 0, strpos($c,':'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cleanNames[] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach($this->columns as $name => $column)
|
||||
{
|
||||
if($i == $value && in_array($name, $cleanNames))
|
||||
{
|
||||
$this->order(array(0 => $value, 1 => $this->orderColumns[array_search($name,$cleanNames)]), $direction);
|
||||
return;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $columnIndex
|
||||
* @param string $searchValue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handleSingleColumnSearch($columnIndex, $searchValue)
|
||||
{
|
||||
//dd($columnIndex, $searchValue, $this->searchColumns);
|
||||
if (!isset($this->searchColumns[$columnIndex])) return;
|
||||
if (empty($searchValue) && $searchValue !== '0') return;
|
||||
|
||||
$columnName = $this->searchColumns[$columnIndex];
|
||||
$this->searchOnColumn($columnName, $searchValue);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function handleInputs()
|
||||
{
|
||||
//Handle all inputs magically
|
||||
foreach (Input::all() as $key => $input) {
|
||||
|
||||
// handle single column search
|
||||
if ($this->isParameterForSingleColumnSearch($key))
|
||||
{
|
||||
$columnIndex = str_replace('sSearch_','',$key);
|
||||
$this->handleSingleColumnSearch($columnIndex, $input);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(method_exists($this, $function = 'handle'.$key))
|
||||
$this->$function($input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parameterName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isParameterForSingleColumnSearch($parameterName)
|
||||
{
|
||||
static $parameterNamePrefix = 'sSearch_';
|
||||
return str_contains($parameterName, $parameterNamePrefix);
|
||||
}
|
||||
|
||||
protected function prepareSearchColumns()
|
||||
{
|
||||
if(count($this->searchColumns) == 0 || empty($this->searchColumns))
|
||||
$this->searchColumns = $this->showColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $column
|
||||
* @param $order
|
||||
*/
|
||||
protected function order($column, $order = BaseEngine::ORDER_ASC)
|
||||
{
|
||||
$this->orderColumn = $column;
|
||||
$this->orderDirection = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function search($value)
|
||||
{
|
||||
$this->search = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function searchOnColumn($columnName, $value)
|
||||
{
|
||||
$this->fieldSearches[] = $columnName;
|
||||
$this->columnSearches[] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function skip($value)
|
||||
{
|
||||
$this->skip = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function take($value)
|
||||
{
|
||||
$this->limit = $value;
|
||||
}
|
||||
|
||||
public function getNameByIndex($index)
|
||||
{
|
||||
$i = 0;
|
||||
foreach($this->columns as $name => $col)
|
||||
{
|
||||
if($index == $i)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
public function getExactWordSearch()
|
||||
{
|
||||
return $this->exactWordSearch;
|
||||
}
|
||||
|
||||
abstract protected function totalCount();
|
||||
abstract protected function count();
|
||||
abstract protected function internalMake(Collection $columns, array $searchColumns = array());
|
||||
}
|
@@ -1,324 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* This handles the collections,
|
||||
* it needs to compile first, so we wait for the make command and then
|
||||
* do all the operations
|
||||
*
|
||||
* Class CollectionEngine
|
||||
* @package Chumper\Datatable\Engines
|
||||
*/
|
||||
class CollectionEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* Constant for OR queries in internal search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OR_CONDITION = 'OR';
|
||||
/**
|
||||
* Constant for AND queries in internal search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const AND_CONDITION = 'AND';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
private $workingCollection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
private $options = array(
|
||||
'sortFlags' => SORT_NATURAL,
|
||||
'stripOrder' => false,
|
||||
'stripSearch' => false,
|
||||
'caseSensitive' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
function __construct(Collection $collection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->collection = $collection;
|
||||
$this->workingCollection = $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->workingCollection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function totalCount()
|
||||
{
|
||||
return $this->collection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArray()
|
||||
{
|
||||
$this->handleInputs();
|
||||
$this->compileArray($this->columns);
|
||||
$this->doInternalSearch(new Collection(), array());
|
||||
$this->doInternalOrder();
|
||||
|
||||
return array_values($this->workingCollection
|
||||
->slice($this->skip,$this->limit)
|
||||
->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all operations performed on the collection
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->workingCollection = $this->collection;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stripSearch()
|
||||
{
|
||||
$this->options['stripSearch'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stripOrder($callback = true)
|
||||
{
|
||||
$this->options['stripOrder'] = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearchStrip()
|
||||
{
|
||||
$this->options['stripSearch'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrderStrip($callback = true)
|
||||
{
|
||||
return $this->stripOrder($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sort behaviour of the doInternalOrder() function.
|
||||
*
|
||||
* @param int $sort_flags For details see: http://php.net/manual/en/function.sort.php
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderFlags($sort_flags = SORT_NATURAL)
|
||||
{
|
||||
$this->options['sortFlags'] = $sort_flags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCaseSensitive($value)
|
||||
{
|
||||
$this->options['caseSensitive'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOption($value)
|
||||
{
|
||||
return $this->options[$value];
|
||||
}
|
||||
//--------------PRIVATE FUNCTIONS-----------------
|
||||
|
||||
protected function internalMake(Collection $columns, array $searchColumns = array())
|
||||
{
|
||||
$this->compileArray($columns);
|
||||
$this->doInternalSearch($columns, $searchColumns);
|
||||
$this->doInternalOrder();
|
||||
|
||||
return $this->workingCollection->slice($this->skip,$this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a collection based on the DataTables search parameters (sSearch_0 etc)
|
||||
* See http://legacy.datatables.net/usage/server-side
|
||||
*
|
||||
* @param Collection $columns All the columns in the DataTable
|
||||
* @param array $searchColumns Columns to search on - values are case-sensitive (must match definition from $columns)
|
||||
*/
|
||||
private function doInternalSearch(Collection $columns, array $searchColumns)
|
||||
{
|
||||
if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches))
|
||||
return;
|
||||
|
||||
$value = $this->search;
|
||||
$caseSensitive = $this->options['caseSensitive'];
|
||||
|
||||
$toSearch = array();
|
||||
$searchType = self::AND_CONDITION;
|
||||
// Map the searchColumns to the real columns
|
||||
$ii = 0;
|
||||
foreach($columns as $i => $col)
|
||||
{
|
||||
if(in_array($columns->get($i)->getName(), $searchColumns) || in_array($columns->get($i)->getName(), $this->fieldSearches))
|
||||
{
|
||||
// map values to columns, where there is no value use the global value
|
||||
if(($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE)
|
||||
{
|
||||
$toSearch[$ii] = $this->columnSearches[$field];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($value)
|
||||
$searchType = self::OR_CONDITION;
|
||||
$toSearch[$ii] = $value;
|
||||
}
|
||||
}
|
||||
$ii++;
|
||||
}
|
||||
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->workingCollection->filter(function($row) use ($toSearch, $caseSensitive, $self, $searchType)
|
||||
{
|
||||
for($i=0, $stack=array(), $nb=count($row); $i<$nb; $i++)
|
||||
{
|
||||
if(!array_key_exists($i, $toSearch))
|
||||
continue;
|
||||
|
||||
$column = $i;
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$column = $self->getNameByIndex($i);
|
||||
}
|
||||
|
||||
if($self->getOption('stripSearch'))
|
||||
{
|
||||
$search = strip_tags($row[$column]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $row[$column];
|
||||
}
|
||||
if($caseSensitive)
|
||||
{
|
||||
if($self->exactWordSearch)
|
||||
{
|
||||
if($toSearch[$i] === $search)
|
||||
$stack[$i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(str_contains($search,$toSearch[$i]))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($self->getExactWordSearch())
|
||||
{
|
||||
if(mb_strtolower($toSearch[$i]) === mb_strtolower($search))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(str_contains(mb_strtolower($search),mb_strtolower($toSearch[$i])))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($searchType == $self::AND_CONDITION)
|
||||
{
|
||||
$result = array_diff_key(array_filter($toSearch), $stack);
|
||||
if(empty($result))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!empty($stack))
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function doInternalOrder()
|
||||
{
|
||||
if(is_null($this->orderColumn))
|
||||
return;
|
||||
|
||||
$column = $this->orderColumn[0];
|
||||
$stripOrder = $this->options['stripOrder'];
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->workingCollection->sortBy(function($row) use ($column,$stripOrder,$self) {
|
||||
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$column = $self->getNameByIndex($column);
|
||||
}
|
||||
if($stripOrder)
|
||||
{
|
||||
if(is_callable($stripOrder)){
|
||||
return $stripOrder($row, $column);
|
||||
}else{
|
||||
return strip_tags($row[$column]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $row[$column];
|
||||
}
|
||||
}, $this->options['sortFlags']);
|
||||
|
||||
if($this->orderDirection == BaseEngine::ORDER_DESC)
|
||||
$this->workingCollection = $this->workingCollection->reverse();
|
||||
}
|
||||
|
||||
private function compileArray($columns)
|
||||
{
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->collection->map(function($row) use ($columns, $self) {
|
||||
$entry = array();
|
||||
|
||||
// add class and id if needed
|
||||
if(!is_null($self->getRowClass()) && is_callable($self->getRowClass()))
|
||||
{
|
||||
$entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowId()) && is_callable($self->getRowId()))
|
||||
{
|
||||
$entry['DT_RowId'] = call_user_func($self->getRowId(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowData()) && is_callable($self->getRowData()))
|
||||
{
|
||||
$entry['DT_RowData'] = call_user_func($self->getRowData(),$row);
|
||||
}
|
||||
$i=0;
|
||||
foreach ($columns as $col)
|
||||
{
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$entry[$col->getName()] = $col->run($row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$entry[$i] = $col->run($row);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
return $entry;
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,306 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Chumper\Datatable\Datatable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class QueryEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
public $builder;
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
public $originalBuilder;
|
||||
|
||||
/**
|
||||
* @var array single column searches
|
||||
*/
|
||||
public $columnSearches = array();
|
||||
|
||||
/**
|
||||
* @var Collection the returning collection
|
||||
*/
|
||||
private $resultCollection;
|
||||
|
||||
/**
|
||||
* @var Collection the resulting collection
|
||||
*/
|
||||
private $collection = null;
|
||||
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
protected $options = array(
|
||||
'searchOperator' => 'LIKE',
|
||||
'searchWithAlias' => false,
|
||||
'orderOrder' => null,
|
||||
'counter' => 0,
|
||||
'noGroupByOnCount' => false,
|
||||
);
|
||||
|
||||
function __construct($builder)
|
||||
{
|
||||
parent::__construct();
|
||||
if($builder instanceof Relation)
|
||||
{
|
||||
$this->builder = $builder->getBaseQuery();
|
||||
$this->originalBuilder = clone $builder->getBaseQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->builder = $builder;
|
||||
$this->originalBuilder = clone $builder;
|
||||
}
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->options['counter'];
|
||||
}
|
||||
|
||||
public function totalCount()
|
||||
{
|
||||
// Store temporary copy as we may modify it, we'd be stupid to modify
|
||||
// the actual "original" copy...
|
||||
$originalBuilder = $this->originalBuilder;
|
||||
|
||||
if ($this->options['noGroupByOnCount']) {
|
||||
$originalBuilder = $this->removeGroupBy($originalBuilder);
|
||||
}
|
||||
|
||||
return $originalBuilder->count();
|
||||
}
|
||||
|
||||
public function getArray()
|
||||
{
|
||||
return $this->getCollection($this->builder)->toArray();
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->builder = $this->originalBuilder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setSearchOperator($value = "LIKE")
|
||||
{
|
||||
$this->options['searchOperator'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearchWithAlias()
|
||||
{
|
||||
$this->options['searchWithAlias'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNoGroupByOnCount()
|
||||
{
|
||||
$this->options['noGroupByOnCount'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------PRIVATE FUNCTIONS
|
||||
|
||||
protected function internalMake(Collection $columns, array $searchColumns = array())
|
||||
{
|
||||
$builder = clone $this->builder;
|
||||
$countBuilder = clone $this->builder;
|
||||
|
||||
$builder = $this->doInternalSearch($builder, $searchColumns);
|
||||
$countBuilder = $this->doInternalSearch($countBuilder, $searchColumns);
|
||||
|
||||
if($this->options['searchWithAlias'])
|
||||
{
|
||||
$this->options['counter'] = count($countBuilder->get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the GROUP BY clause for the count
|
||||
if ($this->options['noGroupByOnCount']) {
|
||||
$countBuilder = $this->removeGroupBy($countBuilder);
|
||||
}
|
||||
$this->options['counter'] = $countBuilder->count();
|
||||
}
|
||||
|
||||
$builder = $this->doInternalOrder($builder, $columns);
|
||||
$collection = $this->compile($builder, $columns);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the GROUP BY clause from a builder.
|
||||
*
|
||||
* @param Builder|QueryBuilder $builder
|
||||
* @return Builder|QueryBuilder $builder with the groups property set to null.
|
||||
*/
|
||||
private function removeGroupBy($builder)
|
||||
{
|
||||
// Handle \Illuminate\Database\Eloquent\Builder
|
||||
if ($builder instanceof Builder) {
|
||||
$query = $builder->getQuery();
|
||||
$query->groups = null;
|
||||
$builder->setQuery($query);
|
||||
}
|
||||
// Handle \Illuminate\Database\Query\Builder
|
||||
else {
|
||||
$builder->groups = null;
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* @return Collection
|
||||
*/
|
||||
private function getCollection($builder)
|
||||
{
|
||||
if($this->collection == null)
|
||||
{
|
||||
if($this->skip > 0)
|
||||
{
|
||||
$builder = $builder->skip($this->skip);
|
||||
}
|
||||
if($this->limit > 0)
|
||||
{
|
||||
$builder = $builder->take($this->limit);
|
||||
}
|
||||
//dd($this->builder->toSql());
|
||||
$this->collection = $builder->get();
|
||||
|
||||
if(is_array($this->collection))
|
||||
$this->collection = new Collection($this->collection);
|
||||
}
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
private function doInternalSearch($builder, $columns)
|
||||
{
|
||||
if (!empty($this->search)) {
|
||||
$this->buildSearchQuery($builder, $columns);
|
||||
}
|
||||
|
||||
if (!empty($this->columnSearches)) {
|
||||
$this->buildSingleColumnSearches($builder);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
protected function buildSearchQuery($builder, $columns)
|
||||
{
|
||||
$like = $this->options['searchOperator'];
|
||||
$search = $this->search;
|
||||
$exact = $this->exactWordSearch;
|
||||
$builder = $builder->where(function($query) use ($columns, $search, $like, $exact) {
|
||||
foreach ($columns as $c) {
|
||||
//column to search within relationships : relatedModel::column
|
||||
if(strrpos($c, '::')) {
|
||||
$c = explode('::', $c);
|
||||
$query->orWhereHas($c[0], function($q) use($c, $like, $exact, $search){
|
||||
$q->where($c[1], $like, $exact ? $search : '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
//column to CAST following the pattern column:newType:[maxlength]
|
||||
elseif(strrpos($c, ':')){
|
||||
$c = explode(':', $c);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$query->orWhereRaw("cast($c[0] as $c[1]) ".$like." ?", array($exact ? "$search" : "%$search%"));
|
||||
}
|
||||
else
|
||||
$query->orWhere($c, $like, $exact ? $search : '%' . $search . '%');
|
||||
}
|
||||
});
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* Modified by sburkett to facilitate individual exact match searching on individual columns (rather than for all columns)
|
||||
*/
|
||||
|
||||
private function buildSingleColumnSearches($builder)
|
||||
{
|
||||
foreach ($this->columnSearches as $index => $searchValue) {
|
||||
if(@$this->columnSearchExact[ $this->fieldSearches[$index] ] == 1) {
|
||||
$builder->where($this->fieldSearches[$index], '=', $searchValue );
|
||||
} else {
|
||||
$builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%' . $searchValue . '%');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function compile($builder, $columns)
|
||||
{
|
||||
$this->resultCollection = $this->getCollection($builder);
|
||||
|
||||
$self = $this;
|
||||
$this->resultCollection = $this->resultCollection->map(function($row) use ($columns,$self) {
|
||||
$entry = array();
|
||||
// add class and id if needed
|
||||
if(!is_null($self->getRowClass()) && is_callable($self->getRowClass()))
|
||||
{
|
||||
$entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowId()) && is_callable($self->getRowId()))
|
||||
{
|
||||
$entry['DT_RowId'] = call_user_func($self->getRowId(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowData()) && is_callable($self->getRowData()))
|
||||
{
|
||||
$entry['DT_RowData'] = call_user_func($self->getRowData(),$row);
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($columns as $col)
|
||||
{
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$entry[$col->getName()] = $col->run($row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$entry[$i] = $col->run($row);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $entry;
|
||||
});
|
||||
return $this->resultCollection;
|
||||
}
|
||||
|
||||
private function doInternalOrder($builder, $columns)
|
||||
{
|
||||
//var_dump($this->orderColumn);
|
||||
if(!is_null($this->orderColumn))
|
||||
{
|
||||
$i = 0;
|
||||
foreach($columns as $col)
|
||||
{
|
||||
|
||||
if($i === (int) $this->orderColumn[0])
|
||||
{
|
||||
if(strrpos($this->orderColumn[1], ':')){
|
||||
$c = explode(':', $this->orderColumn[1]);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$builder = $builder->orderByRaw("cast($c[0] as $c[1]) ".$this->orderDirection);
|
||||
}
|
||||
else
|
||||
$builder = $builder->orderBy($col->getName(), $this->orderDirection);
|
||||
return $builder;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class DatatableFacade extends Facade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'datatable'; }
|
||||
|
||||
}
|
@@ -1,441 +0,0 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Class Table
|
||||
* @package Chumper\Datatable
|
||||
*/
|
||||
class Table {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $columns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $callbacks = array();
|
||||
|
||||
/**
|
||||
* Values to be sent to custom templates
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $customValues = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data = array();
|
||||
|
||||
/**
|
||||
* @var boolean Determines if the template should echo the javascript
|
||||
*/
|
||||
private $noScript = false;
|
||||
|
||||
/**
|
||||
* @var String The name of the id the table will have later
|
||||
*/
|
||||
protected $idName;
|
||||
|
||||
/**
|
||||
* @var String The name of the class the table will have later
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* @var String The view used to render the table
|
||||
*/
|
||||
protected $table_view;
|
||||
|
||||
/**
|
||||
* @var String The view used to render the javascript
|
||||
*/
|
||||
protected $script_view;
|
||||
|
||||
/**
|
||||
* @var boolean indicates if the mapping was already added to the options
|
||||
*/
|
||||
private $createdMapping = true;
|
||||
|
||||
/**
|
||||
* @var array name of mapped columns
|
||||
*/
|
||||
private $aliasColumns = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->config = Config::get('chumper.datatable.table');
|
||||
|
||||
$this->setId( $this->config['id'] );
|
||||
$this->setClass( $this->config['class'] );
|
||||
$this->setOptions( $this->config['options'] );
|
||||
$this->setCallbacks( $this->config['callbacks'] );
|
||||
|
||||
$this->noScript = $this->config['noScript'];
|
||||
$this->table_view = $this->config['table_view'];
|
||||
$this->script_view = $this->config['script_view'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addColumn()
|
||||
{
|
||||
foreach (func_get_args() as $title)
|
||||
{
|
||||
if(is_array($title))
|
||||
{
|
||||
foreach ($title as $mapping => $arrayTitle)
|
||||
{
|
||||
$this->columns[] = $arrayTitle;
|
||||
$this->aliasColumns[] = $mapping;
|
||||
if(is_string($mapping))
|
||||
{
|
||||
$this->createdMapping = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[] = $title;
|
||||
$this->aliasColumns[] = count($this->aliasColumns)+1;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countColumns()
|
||||
{
|
||||
return count($this->columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function removeOption($key)
|
||||
{
|
||||
if(isset($this->options[$key])) unset($this->options[$key]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setOptions()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->options[func_get_arg(0)] =func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $option)
|
||||
{
|
||||
$this->options[$key] = $option;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of options provided for the method "setOptions"');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setOrder($order = array())
|
||||
{
|
||||
$_orders = array();
|
||||
foreach ($order as $number => $sort)
|
||||
{
|
||||
$_orders[] = [$number, $sort];
|
||||
}
|
||||
|
||||
$this->callbacks['aaSorting'] = $_orders;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setCallbacks()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->callbacks[func_get_arg(0)] = func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $value)
|
||||
{
|
||||
$this->callbacks[$key] = $value;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of callbacks provided for the method "setCallbacks"');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setCustomValues()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->customValues[func_get_arg(0)] = func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $value)
|
||||
{
|
||||
$this->customValues[$key] = $value;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of custom values provided for the method "setCustomValues"');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return $this
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->options['sAjaxSource'] = $url;
|
||||
$this->options['bServerSide'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCallbacks()
|
||||
{
|
||||
return $this->callbacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomValues()
|
||||
{
|
||||
return $this->customValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $view
|
||||
* @return mixed
|
||||
*/
|
||||
public function render($view = null)
|
||||
{
|
||||
if( ! is_null($view))
|
||||
$this->table_view = $view;
|
||||
|
||||
return View::make($this->table_view, $this->getViewParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with the parameters that will be passed to the view when it's rendered
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters()
|
||||
{
|
||||
if(!isset($this->options['sAjaxSource']))
|
||||
{
|
||||
$this->setUrl(Request::url());
|
||||
}
|
||||
|
||||
// create mapping for frontend
|
||||
if(!$this->createdMapping)
|
||||
{
|
||||
$this->createMapping();
|
||||
}
|
||||
return array(
|
||||
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
|
||||
'values' => $this->customValues,
|
||||
'data' => $this->data,
|
||||
'columns' => array_combine($this->aliasColumns,$this->columns),
|
||||
'noScript' => $this->noScript,
|
||||
'id' => $this->idName,
|
||||
'class' => $this->className,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the table not to echo the javascript
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noScript()
|
||||
{
|
||||
$this->noScript = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function convertData($options) {
|
||||
$is_obj = false;
|
||||
$first = true;
|
||||
$data = "";
|
||||
foreach ($options as $k => $o) {
|
||||
if ($first == true) {
|
||||
if (!is_numeric($k)) {
|
||||
$is_obj = true;
|
||||
}
|
||||
$first = false;
|
||||
} else {
|
||||
$data .= ",\n";
|
||||
}
|
||||
if (!is_numeric($k)) {
|
||||
$data .= json_encode($k) . ":";
|
||||
}
|
||||
if (is_string($o)) {
|
||||
if (@preg_match("#^\s*function\s*\([^\)]*#", $o)) {
|
||||
$data .= $o;
|
||||
} else {
|
||||
$data .= json_encode($o);
|
||||
}
|
||||
} else {
|
||||
if (is_array($o)) {
|
||||
$data .= $this->convertData($o);
|
||||
} else {
|
||||
$data .= json_encode($o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_obj) {
|
||||
$data = "{ $data }";
|
||||
} else {
|
||||
$data = "[ $data ]";
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function script($view = null)
|
||||
{
|
||||
if( ! is_null($view))
|
||||
$this->script_view = $view;
|
||||
|
||||
// create mapping for frontend
|
||||
if(!$this->createdMapping)
|
||||
{
|
||||
$this->createMapping();
|
||||
}
|
||||
|
||||
return View::make($this->script_view,array(
|
||||
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
|
||||
'id' => $this->idName,
|
||||
));
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->idName;
|
||||
}
|
||||
|
||||
public function setId($id = '')
|
||||
{
|
||||
$this->idName = empty($id)? str_random(8) : $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->className = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAliasMapping($value)
|
||||
{
|
||||
$this->createdMapping = !$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------PRIVATE FUNCTIONS
|
||||
|
||||
private function createMapping()
|
||||
{
|
||||
// set options for better handling
|
||||
// merge with existing options
|
||||
if(!array_key_exists('aoColumns', $this->options))
|
||||
{
|
||||
$this->options['aoColumns'] = array();
|
||||
}
|
||||
$matching = array();
|
||||
$i = 0;
|
||||
foreach($this->aliasColumns as $name)
|
||||
{
|
||||
if(array_key_exists($i,$this->options['aoColumns']))
|
||||
{
|
||||
$this->options['aoColumns'][$i] = array_merge_recursive($this->options['aoColumns'][$i],array('mData' => $name));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options['aoColumns'][$i] = array('mData' => $name);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->createdMapping = true;
|
||||
//dd($matching);
|
||||
return $matching;
|
||||
}
|
||||
}
|
146
vendor/chumper/datatable/src/config/config.php
vendored
146
vendor/chumper/datatable/src/config/config.php
vendored
@@ -1,146 +0,0 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table specific configuration options.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table class
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Class(es) added to the table
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'class' => 'table table-bordered',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table ID
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| ID given to the table. Used for connecting the table and the Datatables
|
||||
| jQuery plugin. If left empty a random ID will be generated.
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'id' => '',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DataTable options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| jQuery dataTable plugin options. The array will be json_encoded and
|
||||
| passed through to the plugin. See https://datatables.net/usage/options
|
||||
| for more information.
|
||||
| Supported: array
|
||||
|
|
||||
*/
|
||||
|
||||
'options' => array(
|
||||
|
||||
"sPaginationType" => "full_numbers",
|
||||
|
||||
"bProcessing" => false
|
||||
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DataTable callbacks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| jQuery dataTable plugin callbacks. The array will be json_encoded and
|
||||
| passed through to the plugin. See https://datatables.net/usage/callbacks
|
||||
| for more information.
|
||||
| Supported: array
|
||||
|
|
||||
*/
|
||||
|
||||
'callbacks' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Skip javascript in table template
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines if the template should echo the javascript
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
|
||||
'noScript' => false,
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table view
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Template used to render the table
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'table_view' => 'chumper.datatable::template',
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Script view
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Template used to render the javascript
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'script_view' => 'chumper.datatable::javascript',
|
||||
),
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Engine specific configuration options.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
|
||||
'engine' => array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Search for exact words
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If the search should be done with exact matching
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
|
||||
'exactWordSearch' => false,
|
||||
|
||||
),
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allow overrides Datatable core classes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
'classmap' => array(
|
||||
'CollectionEngine' => 'Chumper\Datatable\Engines\CollectionEngine',
|
||||
'QueryEngine' => 'Chumper\Datatable\Engines\QueryEngine',
|
||||
'Table' => 'Chumper\Datatable\Table',
|
||||
)
|
||||
);
|
@@ -1,8 +0,0 @@
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function(){
|
||||
// dynamic table
|
||||
oTable = jQuery('#{!! $id !!}').dataTable(
|
||||
{!! $options !!}
|
||||
);
|
||||
});
|
||||
</script>
|
@@ -1,27 +0,0 @@
|
||||
<table id="{!! $id !!}" class="{!! $class !!}">
|
||||
<colgroup>
|
||||
@for ($i = 0; $i < count($columns); $i++)
|
||||
<col class="con{!! $i !!}" />
|
||||
@endfor
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach($columns as $i => $c)
|
||||
<th align="center" valign="middle" class="head{!! $i !!}">{!! $c !!}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($data as $d)
|
||||
<tr>
|
||||
@foreach($d as $dd)
|
||||
<td>{!! $dd !!}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if (!$noScript)
|
||||
@include(Config::get('chumper.datatable.table.script_view'), array('id' => $id, 'options' => $options))
|
||||
@endif
|
0
vendor/chumper/datatable/tests/.gitkeep
vendored
0
vendor/chumper/datatable/tests/.gitkeep
vendored
@@ -1,56 +0,0 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Mockery;
|
||||
|
||||
class DateColumnTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$c = Mockery::mock('Carbon\Carbon');
|
||||
|
||||
$column1 = new DateColumn('foo', DateColumn::DATE, 'foo');
|
||||
$c->shouldReceive('toDateString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column2 = new DateColumn('foo', DateColumn::TIME, 'foo');
|
||||
$c->shouldReceive('toTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column3 = new DateColumn('foo', DateColumn::DATE_TIME, 'foo');
|
||||
$c->shouldReceive('toDateTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column4 = new DateColumn('foo', DateColumn::CUSTOM, 'foo');
|
||||
$c->shouldReceive('format')
|
||||
->with('foo')->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column5 = new DateColumn('foo', DateColumn::FORMATTED_DATE, 'foo');
|
||||
$c->shouldReceive('toFormattedDateString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column6 = new DateColumn('foo', DateColumn::DAY_DATE, 'foo');
|
||||
$c->shouldReceive('toDayDateTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
//now test
|
||||
$this->assertEquals('fooBar', $column1->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column2->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column3->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column4->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column5->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column6->run(array('foo' => $c)));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
|
||||
class FunctionColumnTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testSimple()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return "FooBar";
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array()));
|
||||
}
|
||||
|
||||
public function testAdvanced()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return $model['text'];
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array('text' => 'FooBar')));
|
||||
}
|
||||
|
||||
public function testAdvanced2()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return $model['text'].'Bar';
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array('text' => 'Foo')));
|
||||
}
|
||||
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Columns\TextColumn;
|
||||
|
||||
class TextColumnTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testWorking()
|
||||
{
|
||||
$column = new TextColumn('foo', 'FooBar');
|
||||
$this->assertEquals('FooBar', $column->run(array()));
|
||||
}
|
||||
|
||||
}
|
61
vendor/chumper/datatable/tests/DatatableTest.php
vendored
61
vendor/chumper/datatable/tests/DatatableTest.php
vendored
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Datatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class DatatableTest extends \Orchestra\Testbench\TestCase {
|
||||
|
||||
/**
|
||||
* @var Datatable
|
||||
*/
|
||||
private $dt;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
// set up config
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.engine")->andReturn(
|
||||
array(
|
||||
'exactWordSearch' => false,
|
||||
)
|
||||
);
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.classmap.QueryEngine",NULL)->andReturn('Chumper\Datatable\Engines\QueryEngine');
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.classmap.CollectionEngine",NULL)->andReturn('Chumper\Datatable\Engines\CollectionEngine');
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.classmap.Table",NULL)->andReturn('Chumper\Datatable\Table');
|
||||
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.table")->andReturn(
|
||||
array(
|
||||
'class' => 'table table-bordered',
|
||||
'id' => '',
|
||||
'options' => array(
|
||||
"sPaginationType" => "full_numbers",
|
||||
"bProcessing" => false
|
||||
),
|
||||
'callbacks' => array(),
|
||||
'noScript' => false,
|
||||
'table_view' => 'datatable::template',
|
||||
'script_view' => 'datatable::javascript',
|
||||
)
|
||||
);
|
||||
|
||||
$this->dt = new Datatable;
|
||||
$this->mock = Mockery::mock('Illuminate\Database\Query\Builder');
|
||||
}
|
||||
|
||||
public function testReturnInstances()
|
||||
{
|
||||
$api = $this->dt->query($this->mock);
|
||||
|
||||
$this->assertInstanceOf('Chumper\Datatable\Engines\QueryEngine', $api);
|
||||
|
||||
$api = $this->dt->collection(new Collection());
|
||||
|
||||
$this->assertInstanceOf('Chumper\Datatable\Engines\CollectionEngine', $api);
|
||||
|
||||
$table = $this->dt->table();
|
||||
|
||||
$this->assertInstanceOf('Chumper\Datatable\Table', $table);
|
||||
}
|
||||
|
||||
}
|
@@ -1,113 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Engines\CollectionEngine;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class BaseEngineTest extends TestCase {
|
||||
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var CollectionEngine
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// set up config
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.engine")->andReturn(
|
||||
array(
|
||||
'exactWordSearch' => false,
|
||||
)
|
||||
);
|
||||
|
||||
$this->collection = new Collection();
|
||||
$this->engine = new CollectionEngine($this->collection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testAddColumn()
|
||||
{
|
||||
$this->engine->addColumn('foo', 'bar');
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Chumper\Datatable\Columns\TextColumn',
|
||||
$this->engine->getColumn('foo')
|
||||
);
|
||||
|
||||
$this->engine->addColumn('foo2', function($model){return $model->fooBar;});
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Chumper\Datatable\Columns\FunctionColumn',
|
||||
$this->engine->getColumn('foo2')
|
||||
);
|
||||
|
||||
$this->assertEquals(array(1 => 'foo2', 0 => 'foo'), $this->engine->getOrder());
|
||||
|
||||
$this->engine->addColumn();
|
||||
}
|
||||
|
||||
public function testClearColumns()
|
||||
{
|
||||
$this->engine->addColumn('foo','Bar');
|
||||
$this->assertInstanceOf(
|
||||
'Chumper\Datatable\Columns\TextColumn',
|
||||
$this->engine->getColumn('foo')
|
||||
);
|
||||
|
||||
$this->engine->clearColumns();
|
||||
$this->assertEquals(array(), $this->engine->getOrder());
|
||||
}
|
||||
|
||||
public function testSearchColumns()
|
||||
{
|
||||
$this->engine->searchColumns('id');
|
||||
|
||||
$this->assertEquals(array('id'), $this->engine->getSearchingColumns());
|
||||
|
||||
$this->engine->searchColumns('name', 'email');
|
||||
|
||||
$this->assertEquals(array('name','email'), $this->engine->getSearchingColumns());
|
||||
|
||||
$this->engine->searchColumns(array('foo', 'bar'));
|
||||
|
||||
$this->assertEquals(array('foo', 'bar'), $this->engine->getSearchingColumns());
|
||||
}
|
||||
|
||||
public function testOrderColumns()
|
||||
{
|
||||
$this->engine->orderColumns('id');
|
||||
|
||||
$this->assertEquals(array('id'), $this->engine->getOrderingColumns());
|
||||
|
||||
$this->engine->orderColumns('name', 'email');
|
||||
|
||||
$this->assertEquals(array('name','email'), $this->engine->getOrderingColumns());
|
||||
|
||||
$this->engine->orderColumns(array('foo', 'bar'));
|
||||
|
||||
$this->assertEquals(array('foo', 'bar'), $this->engine->getOrderingColumns());
|
||||
}
|
||||
|
||||
public function testShowColumns()
|
||||
{
|
||||
$this->engine->showColumns('id');
|
||||
|
||||
$this->assertEquals(array('id'), $this->engine->getOrder());
|
||||
|
||||
$this->engine->showColumns('name', 'email');
|
||||
|
||||
$this->assertEquals(array('id','name','email'), $this->engine->getOrder());
|
||||
|
||||
$this->engine->showColumns(array('foo', 'bar'));
|
||||
|
||||
$this->assertEquals(array('id','name','email', 'foo', 'bar'), $this->engine->getOrder());
|
||||
}
|
||||
}
|
||||
|
@@ -1,328 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
use Chumper\Datatable\Engines\CollectionEngine;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class CollectionEngineTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var CollectionEngine
|
||||
*/
|
||||
public $c;
|
||||
|
||||
/**
|
||||
* @var \Mockery\Mock
|
||||
*/
|
||||
public $collection;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $input;
|
||||
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$app['config']->set('chumper.datatable.engine', array(
|
||||
'exactWordSearch' => false,
|
||||
));
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->collection = Mockery::mock('Illuminate\Support\Collection');
|
||||
$this->c = new CollectionEngine($this->collection);
|
||||
}
|
||||
|
||||
public function testOrder()
|
||||
{
|
||||
$should = array(
|
||||
array(
|
||||
'id' => 'eoo'
|
||||
),
|
||||
array(
|
||||
'id' => 'foo'
|
||||
)
|
||||
);
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'iSortCol_0' => 0,
|
||||
'sSortDir_0' => 'asc',
|
||||
)
|
||||
);
|
||||
|
||||
$engine = new CollectionEngine(new Collection($this->getTestArray()));
|
||||
$engine->addColumn(new FunctionColumn('id', function($model){return $model['id'];}));
|
||||
$engine->setAliasMapping();
|
||||
$this->assertEquals($should, $engine->getArray());
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'iSortCol_0' => 0,
|
||||
'sSortDir_0' => 'desc'
|
||||
)
|
||||
);
|
||||
|
||||
$should2 = array(
|
||||
array(
|
||||
'id' => 'foo'
|
||||
),
|
||||
array(
|
||||
'id' => 'eoo'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($should2, $engine->getArray());
|
||||
|
||||
}
|
||||
|
||||
public function testSearch()
|
||||
{
|
||||
// Facade expection
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'eoo'
|
||||
)
|
||||
);
|
||||
|
||||
$engine = new CollectionEngine(new Collection($this->getTestArray()));
|
||||
$engine->addColumn($this->getTestColumns());
|
||||
$engine->searchColumns('id');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
$should = '{"aaData":[{"id":"eoo"}],"sEcho":0,"iTotalRecords":2,"iTotalDisplayRecords":1}';
|
||||
$actual = $engine->make()->getContent();
|
||||
|
||||
$this->assertEquals($should,$actual);
|
||||
//------------------TEST 2-----------------
|
||||
// search in outputed data
|
||||
$engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'),array('bar', 'bar2', 'bar3'))));
|
||||
$engine->addColumn(new FunctionColumn('bla', function($row){return $row[0]." - ".$row[1];}));
|
||||
$engine->addColumn(new FunctionColumn('1', function($row){return $row[2];}));
|
||||
$engine->addColumn(new FunctionColumn('bla3', function($row){return $row[0]." - ".$row[2];}));
|
||||
$engine->searchColumns("bla",1);
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'foo2'
|
||||
)
|
||||
);
|
||||
|
||||
$should = array(
|
||||
array(
|
||||
'bla' => 'foo - foo2',
|
||||
'1' => 'foo3',
|
||||
'bla3' => 'foo - foo3'
|
||||
)
|
||||
);
|
||||
|
||||
$response = json_decode($engine->make()->getContent());
|
||||
$this->assertEquals(json_encode($should), json_encode((array)($response->aaData)));
|
||||
|
||||
//------------------TEST 3-----------------
|
||||
// search in initial data
|
||||
// TODO: Search in initial data columns?
|
||||
|
||||
$engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'),array('bar', 'bar2', 'bar3'))));
|
||||
$engine->addColumn(new FunctionColumn('bla3', function($row){return $row[0]." - ".$row[2];}));
|
||||
$engine->addColumn(new FunctionColumn('1', function($row){return $row[1];}));
|
||||
$engine->searchColumns("bla3",1);
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'foo2'
|
||||
)
|
||||
);
|
||||
|
||||
$should = array(
|
||||
array(
|
||||
'bla3' => 'foo - foo3',
|
||||
'1' => 'foo2'
|
||||
)
|
||||
);
|
||||
|
||||
$response = json_decode($engine->make()->getContent());
|
||||
$this->assertEquals(json_encode($should), json_encode($response->aaData));
|
||||
}
|
||||
|
||||
public function testSkip()
|
||||
{
|
||||
$engine = new CollectionEngine(new Collection($this->getTestArray()));
|
||||
|
||||
$engine->addColumn($this->getTestColumns());
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'iDisplayStart' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$should = array(
|
||||
array(
|
||||
'id' => 'eoo',
|
||||
)
|
||||
);
|
||||
$this->assertEquals($should, $engine->getArray());
|
||||
}
|
||||
|
||||
public function testTake()
|
||||
{
|
||||
Input::replace(
|
||||
array(
|
||||
'iDisplayLength' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$engine = new CollectionEngine(new Collection($this->getTestArray()));
|
||||
$engine->addColumn($this->getTestColumns());
|
||||
$engine->setAliasMapping();
|
||||
$engine->make();
|
||||
|
||||
$should = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
)
|
||||
);
|
||||
$this->assertEquals($should, $engine->getArray());
|
||||
}
|
||||
|
||||
public function testComplex()
|
||||
{
|
||||
$engine = new CollectionEngine(new Collection($this->getRealArray()));
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 't'
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',(array) $test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test));
|
||||
|
||||
//Test2
|
||||
$engine = new CollectionEngine(new Collection($this->getRealArray()));
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'plasch'
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',(array) $test));
|
||||
$this->assertFalse($this->arrayHasKeyValue('foo','Taylor',(array) $test));
|
||||
|
||||
//test3
|
||||
$engine = new CollectionEngine(new Collection($this->getRealArray()));
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'tay'
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
|
||||
|
||||
$this->assertFalse($this->arrayHasKeyValue('foo','Nils',(array) $test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test));
|
||||
|
||||
//test4
|
||||
$engine = new CollectionEngine(new Collection($this->getRealArray()));
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'O'
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertFalse($this->arrayHasKeyValue('foo','Nils',(array) $test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test));
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
private function getTestArray()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'id' => 'foo'
|
||||
),
|
||||
array(
|
||||
'id' => 'eoo'
|
||||
)
|
||||
);
|
||||
}
|
||||
private function getRealArray()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'name' => 'Nils Plaschke',
|
||||
'email'=> 'github@nilsplaschke.de'
|
||||
),
|
||||
array(
|
||||
'name' => 'Taylor Otwell',
|
||||
'email'=> 'taylorotwell@gmail.com'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addRealColumns($engine)
|
||||
{
|
||||
$engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];}));
|
||||
$engine->addColumn(new FunctionColumn('bar', function($m){return $m['email'];}));
|
||||
}
|
||||
|
||||
private function getTestColumns()
|
||||
{
|
||||
return new FunctionColumn('id', function($row){return $row['id'];});
|
||||
}
|
||||
|
||||
private function arrayHasKeyValue($key,$value,$array)
|
||||
{
|
||||
$array = array_pluck($array,$key);
|
||||
foreach ($array as $val)
|
||||
{
|
||||
if(str_contains($val, $value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
@@ -1,251 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
use Chumper\Datatable\Engines\BaseEngine;
|
||||
use Chumper\Datatable\Engines\EngineInterface;
|
||||
use Chumper\Datatable\Engines\QueryEngine;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class QueryEngineTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var QueryEngine
|
||||
*/
|
||||
public $c;
|
||||
|
||||
/**
|
||||
* @var \Mockery\Mock
|
||||
*/
|
||||
public $builder;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper.datatable.engine")->andReturn(
|
||||
array(
|
||||
'exactWordSearch' => false,
|
||||
)
|
||||
);
|
||||
|
||||
$this->builder = Mockery::mock('Illuminate\Database\Query\Builder');
|
||||
|
||||
$this->c = new QueryEngine($this->builder);
|
||||
}
|
||||
|
||||
public function testOrder()
|
||||
{
|
||||
$this->builder->shouldReceive('orderBy')->with('id', BaseEngine::ORDER_ASC);
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'iSortCol_0' => 0,
|
||||
'sSortDir_0' => 'asc'
|
||||
)
|
||||
);
|
||||
|
||||
//--
|
||||
|
||||
$this->builder->shouldReceive('orderBy')->with('id', BaseEngine::ORDER_DESC);
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'iSortCol_0' => 0,
|
||||
'sSortDir_0' => 'desc'
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testSearch()
|
||||
{
|
||||
$this->builder->shouldReceive('where')->withAnyArgs()->andReturn($this->builder);
|
||||
$this->builder->shouldReceive('get')->once()->andReturn(new Collection($this->getRealArray()));
|
||||
$this->builder->shouldReceive('count')->twice()->andReturn(10);
|
||||
$this->builder->shouldReceive('orderBy')->withAnyArgs()->andReturn($this->builder);
|
||||
|
||||
$this->c = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($this->c);
|
||||
$this->c->searchColumns('foo');
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'sSearch' => 'test'
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($this->c->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
}
|
||||
|
||||
public function testSkip()
|
||||
{
|
||||
$this->builder->shouldReceive('skip')->once()->with(1)->andReturn($this->builder);
|
||||
$this->builder->shouldReceive('get')->once()->andReturn(new Collection($this->getRealArray()));
|
||||
$this->builder->shouldReceive('count')->twice()->andReturn(10);
|
||||
$this->builder->shouldReceive('orderBy')->withAnyArgs()->andReturn($this->builder);
|
||||
|
||||
$this->c = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($this->c);
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'iDisplayStart' => 1,
|
||||
'sSearch' => null
|
||||
)
|
||||
);
|
||||
|
||||
$this->c->searchColumns('foo');
|
||||
|
||||
$test = json_decode($this->c->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
}
|
||||
|
||||
public function testTake()
|
||||
{
|
||||
$this->builder->shouldReceive('take')->once()->with(1)->andReturn($this->builder);
|
||||
$this->builder->shouldReceive('get')->once()->andReturn(new Collection($this->getRealArray()));
|
||||
$this->builder->shouldReceive('count')->twice()->andReturn(10);
|
||||
$this->builder->shouldReceive('orderBy')->withAnyArgs()->andReturn($this->builder);
|
||||
|
||||
$this->c = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($this->c);
|
||||
|
||||
Input::merge(
|
||||
array(
|
||||
'iDisplayLength' => 1,
|
||||
'sSearch' => null,
|
||||
'iDisplayStart' => null
|
||||
)
|
||||
);
|
||||
|
||||
$this->c->searchColumns('foo');
|
||||
|
||||
$test = json_decode($this->c->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
}
|
||||
|
||||
public function testComplex()
|
||||
{
|
||||
|
||||
|
||||
$this->builder->shouldReceive('get')->andReturn(new Collection($this->getRealArray()));
|
||||
$this->builder->shouldReceive('where')->withAnyArgs()->andReturn($this->builder);
|
||||
$this->builder->shouldReceive('count')->times(8)->andReturn(10);
|
||||
|
||||
$engine = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 't',
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test));
|
||||
|
||||
//Test2
|
||||
$engine = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'plasch',
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test));
|
||||
|
||||
//test3
|
||||
$engine = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => 'tay',
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test));
|
||||
|
||||
//test4
|
||||
$engine = new QueryEngine($this->builder);
|
||||
|
||||
$this->addRealColumns($engine);
|
||||
$engine->searchColumns('foo','bar');
|
||||
$engine->setAliasMapping();
|
||||
|
||||
Input::replace(
|
||||
array(
|
||||
'sSearch' => '0',
|
||||
)
|
||||
);
|
||||
|
||||
$test = json_decode($engine->make()->getContent());
|
||||
$test = $test->aaData;
|
||||
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test));
|
||||
$this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
private function getRealArray()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'name' => 'Nils Plaschke',
|
||||
'email'=> 'github@nilsplaschke.de'
|
||||
),
|
||||
array(
|
||||
'name' => 'Taylor Otwell',
|
||||
'email'=> 'taylorotwell@gmail.com'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addRealColumns($engine)
|
||||
{
|
||||
$engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];}));
|
||||
$engine->addColumn(new FunctionColumn('bar', function($m){return $m['email'];}));
|
||||
}
|
||||
|
||||
private function arrayHasKeyValue($key,$value,$array)
|
||||
{
|
||||
$array = array_pluck($array,$key);
|
||||
foreach ($array as $val)
|
||||
{
|
||||
if(str_contains($val, $value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
179
vendor/chumper/datatable/tests/TableTest.php
vendored
179
vendor/chumper/datatable/tests/TableTest.php
vendored
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Table;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
|
||||
class TableTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var Table
|
||||
*/
|
||||
private $table;
|
||||
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$app['config']->set('chumper.datatable.table', array(
|
||||
'class' => 'table table-bordered',
|
||||
'id' => '',
|
||||
'options' => array(
|
||||
"sPaginationType" => "full_numbers",
|
||||
"bProcessing" => false
|
||||
),
|
||||
'callbacks' => array(),
|
||||
'noScript' => false,
|
||||
'table_view' => 'datatable::template',
|
||||
'script_view' => 'datatable::javascript',
|
||||
));
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->table = new Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testSetOptions()
|
||||
{
|
||||
$this->table->setOptions('foo','bar');
|
||||
|
||||
$this->table->setOptions(array(
|
||||
'foo2' => 'bar2',
|
||||
'foo3' => 'bar3'
|
||||
));
|
||||
|
||||
$this->table->setOptions('foo', 'bar', 'baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testSetCallbacks()
|
||||
{
|
||||
$this->table->setCallbacks('foo', 'bar');
|
||||
$this->assertArrayHasKey('foo', $this->table->getCallbacks());
|
||||
|
||||
$this->table->setCallbacks(array(
|
||||
'foo2' => 'bar2',
|
||||
'foo3' => 'bar3'
|
||||
));
|
||||
$this->assertArrayHasKey('foo2', $this->table->getCallbacks());
|
||||
$this->assertArrayHasKey('foo3', $this->table->getCallbacks());
|
||||
|
||||
$this->table->setCallbacks('foo', 'bar', 'baz');
|
||||
$this->assertTrue(False); // should throw exception before here
|
||||
}
|
||||
|
||||
public function testSetNamedFunctionAsCallback()
|
||||
{
|
||||
//set an anonymous function
|
||||
$this->table->setCallbacks(['foo'=>'function(){ return foo; }']);
|
||||
//set a named function
|
||||
$this->table->setCallbacks(['bar'=>'myBar']);
|
||||
$parameters = $this->table->getViewParameters();
|
||||
|
||||
//an anonymous function should be included as it is.
|
||||
$this->assertThat($parameters['options'],$this->stringContains('"foo":function(){ return foo; }') );
|
||||
//the callback it's a function name, it shouldn't be quoted
|
||||
$this->assertThat($parameters['options'],$this->stringContains('"bar":myBar') );
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testSetCustomValues()
|
||||
{
|
||||
$this->table->setCustomValues('foo', 'bar');
|
||||
$this->assertArrayHasKey('foo', $this->table->getCustomValues());
|
||||
|
||||
$this->table->setCustomValues(array(
|
||||
'foo2' => 'bar2',
|
||||
'foo3' => 'bar3'
|
||||
));
|
||||
$this->assertArrayHasKey('foo2', $this->table->getCustomValues());
|
||||
$this->assertArrayHasKey('foo3', $this->table->getCustomValues());
|
||||
|
||||
$this->table->setCustomValues('foo', 'bar', 'baz');
|
||||
$this->assertTrue(False); // should throw exception before here
|
||||
}
|
||||
|
||||
public function testAddColumn()
|
||||
{
|
||||
$this->table->addColumn('foo');
|
||||
|
||||
$this->assertEquals(1, $this->table->countColumns());
|
||||
|
||||
$this->table->addColumn('foo1','foo2');
|
||||
|
||||
$this->assertEquals(3, $this->table->countColumns());
|
||||
|
||||
$this->table->addColumn(array('foo3','foo4'));
|
||||
|
||||
$this->assertEquals(5, $this->table->countColumns());
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
|
||||
View::shouldReceive('make')->once()
|
||||
->with('datatable::template', \Mockery::any())->andReturn(true);
|
||||
|
||||
$this->table->setUrl('fooBar');
|
||||
$table1 = $this->table->addColumn('foo')->render();
|
||||
$this->assertEquals(array(
|
||||
'options' => '{ "sPaginationType":"full_numbers",'.PHP_EOL
|
||||
. '"bProcessing":false,'.PHP_EOL
|
||||
. '"sAjaxSource":"fooBar",'.PHP_EOL
|
||||
. '"bServerSide":true }',
|
||||
'values' => array(),
|
||||
'data' => array(),
|
||||
'columns' => array(1=>'foo'),
|
||||
'noScript' => false,
|
||||
'class' => $this->table->getClass(),
|
||||
'id' => $this->table->getId(),
|
||||
|
||||
), $this->table->getViewParameters());
|
||||
$this->assertTrue($table1);
|
||||
}
|
||||
|
||||
public function testSetData()
|
||||
{
|
||||
$data = array(
|
||||
array(
|
||||
'foo',
|
||||
'bar'
|
||||
),
|
||||
array(
|
||||
'foo2',
|
||||
'bar2'
|
||||
),
|
||||
);
|
||||
|
||||
$this->table->setData($data);
|
||||
$this->assertEquals($data,$this->table->getData());
|
||||
|
||||
}
|
||||
|
||||
public function testSetUrl()
|
||||
{
|
||||
$this->table->setUrl('foo/url');
|
||||
|
||||
$this->assertArrayHasKey('bServerSide',$this->table->getOptions());
|
||||
$this->assertArrayHasKey('sAjaxSource',$this->table->getOptions());
|
||||
|
||||
$return = $this->table->getOptions();
|
||||
|
||||
$this->assertEquals('foo/url',$return['sAjaxSource']);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
}
|
5
vendor/chumper/zipper/.gitignore
vendored
5
vendor/chumper/zipper/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
||||
/.idea
|
11
vendor/chumper/zipper/.travis.yml
vendored
11
vendor/chumper/zipper/.travis.yml
vendored
@@ -1,11 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev
|
||||
|
||||
script: phpunit
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user