Skip to content

Commit

Permalink
Merge pull request #12 from codex-team/dev
Browse files Browse the repository at this point in the history
Dump-autoload automatically after requiring
  • Loading branch information
khaydarov authored Aug 14, 2017
2 parents bbcfb8d + e6b37e7 commit 9e74dc6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
composer.lock
vendor/
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ PHP errors Catcher module for [Hawk.so](https://hawk.so)
Use [composer](https://getcomposer.org) to install Catcher

```bash
composer require codex-team/hawk.php:*
$ composer require codex-team/hawk.php
$ composer install
```

#### Download and require php file

You can download `hawk.php` file from this repository and require it in your project.
You can download this repository and require `Hawk.php` file in your project.

```php
require 'hawk.php';
require './hawk.php/src/Hawk.php';
```

### Add namespaces

Add this line at the top of your PHP script. [Why?](http://php.net/manual/en/language.namespaces.importing.php)

```php
use \Hawk\HawkErrorManager;
use \Hawk\HawkCatcher;
```

### Enable Catcher

Create an instance and pass project token.

```php
HawkErrorManager::instance('abcd1234-1234-abcd-1234-123456abcdef');
HawkCatcher::instance('abcd1234-1234-abcd-1234-123456abcdef');
```

#### Custom Hawk server

If you want to use custom Hawk server then pass a url to this catcher.

```php
HawkErrorManager::instance(
HawkCatcher::instance(
'abcd1234-1234-abcd-1234-123456abcdef',
'http://myownhawk.com/catcher/php'
);
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"php": ">=5.6"
},
"autoload": {
"psr-4": {"Hawk\\": "hawk"}
"classmap": [
"src/Hawk.php"
],
"psr-4": {"Hawk\\": "src/"}
}
}
17 changes: 9 additions & 8 deletions Hawk/hawk.php → src/Hawk.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


namespace Hawk;

/**
Expand All @@ -9,29 +10,29 @@
* @example https://hawk.so/docs#add-server-handler
*
* Use namespaces
* > use \Hawk\HawkErrorManager;
* > use \Hawk\HawkCatcher;
*
* Initialize Hawk this way
* > HawkErrorManager::instance('abcd1234-1234-abcd-1234-123456abcdef');
* > HawkCatcher::instance('abcd1234-1234-abcd-1234-123456abcdef');
*
* Or this way if you want to use custom Hawk server
* > HawkErrorManager::instance(
* > HawkCatcher::instance(
* > 'abcd1234-1234-abcd-1234-123456abcdef',
* > 'http://myownhawk.coms/catcher/php'
* > );
*
*/
class HawkErrorManager
class HawkCatcher
{
/**
* Define error handlers
*/
private function __construct ($accessToken) {
self::$_accessToken = $accessToken;

register_shutdown_function(array('\Hawk\HawkErrorManager', 'checkForFatal'));
set_error_handler(array('\Hawk\HawkErrorManager', 'Log'), E_ALL);
set_exception_handler(array('\Hawk\HawkErrorManager', 'LogException'));
register_shutdown_function(array('\Hawk\HawkCatcher', 'checkForFatal'));
set_error_handler(array('\Hawk\HawkCatcher', 'Log'), E_ALL);
set_exception_handler(array('\Hawk\HawkCatcher', 'LogException'));
error_reporting(E_ALL | E_STRICT);
}

Expand All @@ -41,7 +42,7 @@ private function __construct ($accessToken) {
private static $_instance;

/**
* Set private functions cause Singleton
* Set private functions cause Singleton
*/
private function __clone () {}
private function __sleep () {}
Expand Down

0 comments on commit 9e74dc6

Please sign in to comment.