From 764ff899b39306568ec0f6409fe9a991229cc477 Mon Sep 17 00:00:00 2001 From: Filip Golonka Date: Mon, 5 Oct 2015 14:29:33 +0200 Subject: [PATCH] use the newest rollbar.js version, but allow user to select custom one --- DependencyInjection/Configuration.php | 3 + Faker/Application.php | 11 ++++ README.md | 1 + Twig/RollbarExtension.php | 4 +- composer.json | 3 +- .../Twig/RollbarExtensionSpec.php | 61 +++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 Faker/Application.php create mode 100644 spec/Ftrrtf/RollbarBundle/Twig/RollbarExtensionSpec.php diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9e880cb..bf2ebf6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -49,6 +49,9 @@ public function getConfigTreeBuilder() ->booleanNode('guess_uncaught_frames') ->defaultFalse() ->end() + ->scalarNode('rollbarjs_version') + ->defaultValue('v1') + ->end() ->arrayNode('allowed_js_hosts') ->prototype('scalar') ->end() diff --git a/Faker/Application.php b/Faker/Application.php new file mode 100644 index 0000000..03f1060 --- /dev/null +++ b/Faker/Application.php @@ -0,0 +1,11 @@ +notifierOptions['rollbarjs_version']; + $config = json_encode($config); $checkIgnoreConfig = $this->getCheckIgnoreConfig(); @@ -96,7 +98,7 @@ public function getInitRollbarCode(array $context) return << var _rollbarConfig = {$config}; -!function(r){function t(o){if(e[o])return e[o].exports;var n=e[o]={exports:{},id:o,loaded:!1};return r[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){"use strict";var o=e(1).Rollbar,n=e(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://d37gvrvc0wt4s1.cloudfront.net/js/v1.7/rollbar.min.js";var a=o.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,t){"use strict";function e(){var r=window.console;r&&"function"==typeof r.log&&r.log.apply(r,arguments)}function o(r,t){return t=t||e,function(){try{return r.apply(this,arguments)}catch(e){t("Rollbar internal error:",e)}}}function n(r,t,e){window._rollbarWrappedError&&(e[4]||(e[4]=window._rollbarWrappedError),e[5]||(e[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,e),t&&t.apply(window,e)}function a(r){this.shimId=++u,this.notifier=null,this.parentShim=r,this.logger=e,this._rollbarOldOnError=null}function i(r){var t=a;return o(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var e=this,o="scope"===r;o&&(e=new t(this));var n=Array.prototype.slice.call(arguments,0),a={shim:e,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),o?e:void 0})}function l(r,t){if(t.hasOwnProperty&&t.hasOwnProperty("addEventListener")){var e=t.addEventListener;t.addEventListener=function(t,o,n){e.call(this,t,r.wrap(o),n)};var o=t.removeEventListener;t.removeEventListener=function(r,t,e){o.call(this,r,t&&t._wrapped?t._wrapped:t,e)}}}var u=0;a.init=function(r,t){var e=t.globalAlias||"Rollbar";if("object"==typeof r[e])return r[e];r._rollbarShimQueue=[],r._rollbarWrappedError=null,t=t||{};var i=new a;return o(function(){if(i.configure(t),t.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=function(){var r=Array.prototype.slice.call(arguments,0);n(i,i._rollbarOldOnError,r)};var o,a,u="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(o=0;o END_HTML; diff --git a/composer.json b/composer.json index 5d3af23..144ed08 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "ftrrtf/rollbar-notifier": "~1.0" }, "require-dev" : { - "phpspec/phpspec" : "2.*" + "phpspec/phpspec" : "2.*", + "twig/extensions": "^1.3" }, "suggest": { "twig/extensions": "~1.1 – For twig rollbarjs extension" diff --git a/spec/Ftrrtf/RollbarBundle/Twig/RollbarExtensionSpec.php b/spec/Ftrrtf/RollbarBundle/Twig/RollbarExtensionSpec.php new file mode 100644 index 0000000..2c405c6 --- /dev/null +++ b/spec/Ftrrtf/RollbarBundle/Twig/RollbarExtensionSpec.php @@ -0,0 +1,61 @@ +beConstructedWith([], [], $helper); + } + + function it_is_initializable() + { + $this->shouldHaveType('Ftrrtf\RollbarBundle\Twig\RollbarExtension'); + } + + function it_uses_the_newest_version_of_rollbarjs(UserHelper $helper, Application $app) + { + $this->beConstructedWith( + [ + 'access_token' => 'access_token', + 'source_map_enabled' => false, + 'allowed_js_hosts' => [], + 'rollbarjs_version' => 'v1', + ], + [ + 'environment' => 'test', + ], + $helper + ); + + $this->getInitRollbarCode(['app' => $app])->shouldMatch('/v1/'); + } + + function it_allows_to_select_rollbarjs_version(UserHelper $helper, Application $app) + { + $this->beConstructedWith( + [ + 'access_token' => 'access_token', + 'source_map_enabled' => false, + 'allowed_js_hosts' => [], + 'rollbarjs_version' => 'v1.7' + ], + [ + 'environment' => 'test', + ], + $helper + ); + + $this->getInitRollbarCode(['app' => $app])->shouldMatch('/v1.7/'); + } +}