Skip to content

Commit 3ee0c7d

Browse files
committed
first version
1 parent 831ed5d commit 3ee0c7d

File tree

14 files changed

+652
-2
lines changed

14 files changed

+652
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: php
2+
3+
php:
4+
- 7.1
5+
- 7.2
6+
7+
env:
8+
- # default environment without variables
9+
- COMPOSER_DEPENDENCIES_OPTIONS="--prefer-lowest --prefer-stable"
10+
11+
install:
12+
- composer update --no-progress --no-interaction --no-suggest ${COMPOSER_DEPENDENCIES_OPTIONS}
13+
14+
script:
15+
- composer run build
16+
17+
after_script:
18+
- php vendor/bin/coveralls -v

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Martin Hujer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# JavaScriptErrorHandlerBundle
2+
[![Build Status](https://travis-ci.org/mhujer/JavaScriptErrorHandlerBundle.svg?branch=master)](https://travis-ci.org/mhujer/JavaScriptErrorHandlerBundle) [![Coverage Status](https://coveralls.io/repos/github/mhujer/JavaScriptErrorHandlerBundle/badge.svg?branch=dev)](https://coveralls.io/github/mhujer/JavaScriptErrorHandlerBundle?branch=dev) [![Latest Stable Version](https://poser.pugx.org/mhujer/javascript-error-handler-bundle/v/stable)](https://packagist.org/packages/mhujer/javascript-error-handler-bundle) [![License](https://poser.pugx.org/mhujer/javascript-error-handler-bundle/license)](https://packagist.org/packages/mhujer/javascript-error-handler-bundle)
3+
4+
It is easy to break the JavaScript in the application while doing some non-JS change. And if you don't have the browser console open, you may not notice it.
5+
6+
This Bundle injects a JavaScript handler, which converts JavaScript errors to `alert()`. So they can't hide in the console unnoticed.
7+
8+
9+
Usage
10+
----
11+
1. Install the latest version with `composer require mhujer/javascript-error-handler-bundle`
12+
2. Register the Bundle in the `AppKernel.php`:
13+
14+
```php
15+
<?php
16+
17+
class AppKernel extends \Symfony\Component\HttpKernel\Kernel
18+
{
19+
20+
...
21+
22+
public function registerBundles()
23+
{
24+
$bundles = [
25+
...
26+
new \Mhujer\JavaScriptErrorHandlerBundle\JavaScriptErrorHandlerBundle(),
27+
];
28+
29+
}
30+
31+
```
32+
33+
Configuration
34+
-------
35+
The Bundle is automatically enabled only in `dev` mode (by using `kernel.debug` configuration option).
36+
37+
You can configure it manually by adding this to your `config.yml`:
38+
39+
```yaml
40+
java_script_error_handler:
41+
enabled: '%kernel.debug%'
42+
```
43+
44+
45+
Requirements
46+
------------
47+
PHP 7.1/7.2 and Symfony 3.3+.
48+
49+
50+
Author
51+
------
52+
[Martin Hujer](https://www.martinhujer.cz)
53+
54+
55+
Changelog
56+
----------
57+
58+
### 0.1 (2017-10-23)
59+
- initial release

build/logs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage-report
2+
clover.xml

composer.json

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mhujer/javascript-error-handler-bundle",
33
"type": "library",
4-
"description": "",
4+
"description": "Converts JavaScript errors to alerts, so you won't miss them if you don't have the browser console open.",
55
"keywords": [
66
"javascript",
77
"symfony",
@@ -15,5 +15,46 @@
1515
"email": "[email protected]",
1616
"homepage": "https://www.martinhujer.cz"
1717
}
18-
]
18+
],
19+
"require": {
20+
"php": "7.1.*||7.2.*",
21+
"symfony/symfony": "~3.3|~4.0"
22+
},
23+
"require-dev": {
24+
"consistence/coding-standard": "2.2.1",
25+
"jakub-onderka/php-parallel-lint": "0.9.2",
26+
"phpstan/phpstan-shim": "0.8.4",
27+
"phpunit/phpunit": "6.4.3",
28+
"satooshi/php-coveralls": "1.0.1"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Mhujer\\JavaScriptErrorHandlerBundle\\": [
33+
"src"
34+
]
35+
},
36+
"classmap": [
37+
"src"
38+
]
39+
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"Mhujer\\JavaScriptErrorHandlerBundle\\": [
43+
"tests"
44+
]
45+
}
46+
},
47+
"scripts": {
48+
"build": [
49+
"@composer validate --no-check-all",
50+
"@phplint",
51+
"@phpcs",
52+
"@phpstan",
53+
"@phpunit"
54+
],
55+
"phplint": "parallel-lint src tests",
56+
"phpcs": "phpcs --standard=ruleset.xml src tests",
57+
"phpstan": "php vendor/phpstan/phpstan-shim/phpstan.phar analyse src tests --level 7 --no-progress",
58+
"phpunit": "phpunit"
59+
}
1960
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.4/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
failOnRisky="true"
9+
verbose="true"
10+
beStrictAboutChangesToGlobalState="true"
11+
beStrictAboutOutputDuringTests="true"
12+
>
13+
<testsuites>
14+
<testsuite name="Project Test Suite">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist processUncoveredFilesFromWhitelist="true">
21+
<directory suffix=".php">src</directory>
22+
</whitelist>
23+
</filter>
24+
25+
<logging>
26+
<log type="coverage-clover" target="build/logs/clover.xml"/>
27+
<log type="coverage-html" target="build/logs/coverage-report"/>
28+
</logging>
29+
</phpunit>

ruleset.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="JavaScriptErrorHandlerBundle">
3+
<exclude-pattern>vendor/</exclude-pattern>
4+
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
5+
<!-- we don't want to have FQCN after extends/implements -->
6+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
7+
</rule>
8+
</ruleset>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Mhujer\JavaScriptErrorHandlerBundle\DependencyInjection;
6+
7+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8+
use Symfony\Component\Config\Definition\ConfigurationInterface;
9+
10+
class Configuration implements ConfigurationInterface
11+
{
12+
13+
/** @var bool */
14+
private $enabledDefaultValue;
15+
16+
public function __construct(
17+
bool $enabledDefaultValue
18+
)
19+
{
20+
$this->enabledDefaultValue = $enabledDefaultValue;
21+
}
22+
23+
public function getConfigTreeBuilder(): TreeBuilder
24+
{
25+
$treeBuilder = new TreeBuilder();
26+
$rootNode = $treeBuilder->root('java_script_error_handler');
27+
28+
// @codingStandardsIgnoreStart tree is indented for better readability
29+
$rootNode
30+
->children()
31+
->booleanNode('enabled')->defaultValue($this->enabledDefaultValue)->end()
32+
->end();
33+
// @codingStandardsIgnoreEnd
34+
35+
return $treeBuilder;
36+
}
37+
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Mhujer\JavaScriptErrorHandlerBundle\DependencyInjection;
6+
7+
use Symfony\Component\Config\FileLocator;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11+
12+
class JavaScriptErrorHandlerExtension extends Extension
13+
{
14+
15+
/**
16+
* Configures the passed container according to the merged configuration.
17+
*
18+
* @param mixed[] $configs
19+
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
20+
*/
21+
public function load(array $configs, ContainerBuilder $container): void
22+
{
23+
$configuration = $this->getConfiguration($configs, $container);
24+
$config = $this->processConfiguration($configuration, $configs);
25+
26+
$enabled = $config['enabled'];
27+
28+
if ($enabled) {
29+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
30+
$loader->load('kernel_response_listener.yml');
31+
}
32+
}
33+
34+
/**
35+
* @param mixed[] $config An array of configuration values
36+
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
37+
* @return \Mhujer\JavaScriptErrorHandlerBundle\DependencyInjection\Configuration
38+
*/
39+
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
40+
{
41+
return new Configuration($container->getParameter('kernel.debug'));
42+
}
43+
44+
}

0 commit comments

Comments
 (0)