I use the Silex/Pimple container to store parameters for my application. Some of those parameters are set using middleware.
Now I have come across the problem where I want to access a parameter value that should have been set through middleware. But when I output it, it still contains the old value.
This is a simplified version of my code:
$app['test'] = 'old value';
$app->before(function (Symfony\Component\HttpFoundation\Request $request, Silex\Application $app){
// logic
$app['test'] = 'new value';
}, Silex\Application::EARLY_EVENT);
echo $app['test'];
outputs:
old value
Does someone know how I can force the middleware to run first and then do the output? Or is there an other way to interact with the request before everything else?
Related
I would like to see if they can help me with the creation of a variable, where I can change the labels of the MQTT message that is sent from my IoT devices, in order to make it easier and to select the correct parameters when creating a dashboard. .
Example:
This is the message received to my server.
[{"n": "model", "d": "iot-zigbee1783"}, {"n": "Relay", "ap": true}, {"t": "gateway", "ma": "0035DDf45VAIoT215"}]
What I want is to change the label "d" for "deviceIoT" and "ap" for "door sensor" also if it is possible to change the true or false of the door sensor for open and closed.
You can do this with the help of Thingsboards rule-chain.
There is also an official tutorial for this:
https://thingsboard.io/docs/user-guide/rule-engine-2-0/tutorials/transform-incoming-telemetry/
They use the transformation-rule-node called script to convert temperatures from [°F] to [°C].
While this is not your use case, it shows you how to handle incoming telemetry before it is saved to the database.
You could do a mapping of value-keys like this:
var theCustomizedMessage = {};
theCustomizedMessage['customizedKey'] = msg['originalIncomingKey'];
return {msg: theCustomizedMessage, metadata: metadata, msgType: msgType};
Keep in mind that this might be contra-productive since you have to update the rule-node scripts, when something changes.
As an alternative option you can rename the key labels in the widget configuration. This will not help your dashboard developers. But a documentation document will do :)
I strongly recommend against the replacement of boolean values with strings ('closed', 'opened'). This is a job for the widgets (e.g. their value format functions).
I'm using NgBlockUI and BlockUIHttpModule with blockAllRequestsInProgress set to true in an app I'm working on. In general it's working fine, but on one page I'm using a concat map to perform some action and then update the data. The first request, the update, triggers BlockUI fine, but the second one doesn't. Otherwise, it executes properly. It's just a little jarring for the user since the results seem to update without warning. Here's the code for the function:
onUpdate(event: items[]) {
this.updateService.update(event).concatMap(
_ => this.seachService.search(this.cachedSearch)
).subscribe(
resp => this.handleResponse(resp),
err => this.handleError(err)
);
}
I tried calling BlockUI directly, but still no luck. As a last resort, I'm going to make the whole thing one request, but I'd like to at least understand why this isn't working.
This happened to me as well. This issue occurs for sequential HTTP calls (usually with await) wherein the second request is not blocked by ng-block-ui.
As fix what I did was set blockAllRequestsInProgress to false. The behavior is just the same but setting it to false yields more predictable results:
BlockUIHttpModule.forRoot({
blockAllRequestsInProgress: false,
requestFilters: [urlFilter]
}),
I've also updated to ng-block-ui to latest version as of this writing:
"ng-block-ui": "^2.1.8",
I want to examine http requests in an extension for firefox. To begin figuring out how to do what I want to do I figured I'd just log everything and see what comes up:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);},
{urls: [/^.*$/]}
);
The domain is insignificant, and I know the regex works, verified in the console. When running this code I get no logging. When I take out the filter parameter I get every request:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);}
);
Cool, I'm probably doing something wrong, but I can't see what.
Another approach is to manually filter on my own:
var webRequest = Components.utils.import("resource://gre/modules/WebRequest.jsm", {});
var makeRequest = function(type) {
webRequest[type].addListener(
(stuff) => {
console.log(!stuff.url.match(/google.com.*/));
if(!stuff.url.match(/google.com.*/))
return;
console.log(type);
console.log(stuff);
}
);
}
makeRequest("onBeforeRequest");
makeRequest("onBeforeSentHeaders");
makeRequest("onSendHeaders");
makeRequest("onHeadersReceived");
makeRequest("onResponseStarted");
makeRequest("onCompleted");
With the console.log above the if, I can see the regex returning true when I want it to and the code making it past the if. When I remove the console.log above the if the if no longer gets executed.
My question is then, how do I get the filtering parameter to work or if that is indeed broken, how can I get the code past the if to be executed? Obviously, this is a fire hose, and to begin searching for a solution I will need to reduce the data.
Thanks
urls must be a string or an array of match patterns. Regular expressions are not supported.
WebRequest.jsm uses resource://gre/modules/MatchPattern.jsm. Someone might get confused with the util/match-pattern add-on sdk api, which does support regular expressions.
I have project with win auth and i use "securityTrimmingEnabled" option for detect to which parts of menu user have access.
I set site map node properties:
siteMapNode.ParentNode.Title = entity.Parent.Title;
siteMapNode.ParentNode.RouteValues["id"] = entity.Parent.Id;
And if "securityTrimmingEnabled" is false, everything is ok and i have correct url in map path(/portfolios/facility/57), if "securityTrimmingEnabled" is true, title of node is ok, but "id" param is not correct(/portfolios/facility/0)
How i can resolve this issue?
This is basically the same issue described here.
The AuthorizeAttributeAclModule is accessing the Url property and causing it to be request cached, so setting properties that affect the URL afterward (such as in a controller action) has no effect.
Option 1
Move the code that sets the RouteValues["id"] into a IDynamicNodeProvider implemenation. This will load the values into the shared cache at application startup (and when the cache expires), but it also loads them before the AuthorizeAttributeAclModule fires.
Option 2
Move the code that sets the values into the Application_BeginRequest event as described here.
Option 3
Create a custom implementation of RequestCacheableSiteMapNode that doesn't override the Url property and a custom SiteMapNodeFactory to provide instances of your new class, then inject them both with DI.
Option 4
Remove the request cache value for the Url property manually, so it can be regenerated the next time the Url property is accessed.
var parentNode = siteMapNode.ParentNode;
parentNode.Title = entity.Parent.Title;
parentNode.RouteValues["id"] = entity.Parent.Id;
var urlRequestCacheKey = "__MVCSITEMAPNODE_" + parentNode.SiteMap.CacheKey + "_" + parentNode.Key + "_Url_True_";
this.HttpContext.Items.Remove(urlRequestCacheKey);
My Problem is the following i wanted to test some functionality that depended on a certain setting in the sfConfig.
Proposed the setting is app_foo and its default is false.
The "standard" way to test is like:
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/path_to/index')->
...
end();
BUT it does not work to change the setting like
sfConfig::set('app_foo', true);
$browser = new sfTestFunctional(new sfBrowser());
The sfConfig cannot be overwritten in the test because the sfConfig is reset on the next request.
BUT a field named 'rawConfiguration' in the browser instance is added to the sfConfig for the request. So the solution is to set this array:
$browserEngine = new sfBrowser();
$browser = new sfTestFunctional($browserEngine);
// overwrite an sfConfig parameter in the browser context
$browserEngine->rawConfiguration = array_merge($browserEngine->rawConfiguration, array('app_foo' => true));
Then the action knows the sfConfig::get('app_foo') with the value true.
The samura answer is nice, you also have to know that config files are environement aware so you can do that in your app.yml:
all:
my_setting: "super"
test:
my_setting: "awesome"
This is also working on the database.yml file, allowing you to run functionnal tests in another database