Get profiler toolbar in demo - symfony-3.1

I don't manage to get the Symfony 3.1 profiler toolbar in demo environment
AppKernel.php : bundles are enabled for demo
if (in_array($this->getEnvironment(), ['dev', 'demo'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}
config_demo.yml
framework:
router:
resource: "%kernel.root_dir%/config/routing_demo.yml"
strict_requirements: true
profiler: false
web_profiler:
toolbar: true
intercept_redirects: false
app_demo.php
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('demo', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
routing_demo.yml
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
and yes, I have body tag in my home page
What am I missing ?
Thanks

OK my mistake
My demo htaccess was using app.php and not app_demo.php
sorry !

Related

How to secure cache.db file in Xamarin.iOS

I'd like to secure cache.db file on iPhone. Now when I install my App and connect the iPhone to my Mac, I'm able to see cache.db file in the apps file structure and I'm able to read the file contents that basically contains requests and responses. I Applied NoCatch with HTTP client object. But not it makes no difference.
HttpClientObj.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true
};
Translate the solution here with SWIFT into c#:
To prevent request and parameters being written to the Cache.db iOS
If you are using NSUrlSession :
var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
configuration.URLCache = new NSUrlCache(0,0,"");
NSUrlSession seeion = NSUrlSession.FromConfiguration(configuration);
Or set at a global NSUrlCache level:
NSUrlCache.SharedCache = new NSUrlCache(0,0,"");
Update:
You can use native handler when creating HttpClient:
public MainPage()
{
InitializeComponent();
HttpClient httpClient;
if (Device.RuntimePlatform == Device.iOS)
{
var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
configuration.URLCache = new NSUrlCache(0, 0, "");
NSUrlSessionHandler handler = new NSUrlSessionHandler(configuration);
httpClient = new HttpClient(handler);
}else if (Device.RuntimePlatform == Device.Android)
{
AndroidClientHandler handler = new AndroidClientHandler();
httpClient = new HttpClient(handler);
}
//...your request
}
Remember to Add reference to Xamarin.iOS.dll and Mono.Android.dll.
CacheControl HeaderValue works me
System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true };
Documentation

error 500 slim get data POST

I tried all possible methods and always got the same error, can someone help me?? and give me some advice?
pdt. i am new to web development
thanks
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/products', function(Request $req, Response $res){
$query = 'SELECT * FROM products';
try{
$db = new database();
$db = $db->connection();
$stmt = $db->query($query);
$products = $stmt->fetch_object();
echo json_encode($products);
}catch(Exception $e){
echo $e;
}
});
$app->post('/api/add',function()use($app){
$request = Slim::getInstance()->request();
$name = json_decode($request->getBody());
//$content = file_get_contents($req);
//$json = json_decode($content, true);
//$post = $id->post;
echo $name;
});
Follow the tutorial. You need to require Composer's autoloader.
If you check your PHP error log, you'll see the errors.

Laravel 5.4 - Socialite Providers multiple configurations with Twitter

I have two services to connect with Socialite Provider:
use Laravel\Socialite\Facades\Socialite;
use \SocialiteProviders\Manager\Config;
public function connect_1() {
$config1 = new Config(
env('TWITTER_CONSUMER_KEY_1'),
env('TWITTER_CONSUMER_SECRET_1'),
env('TWITTER_REDIRECT_URI_1'),
[
//
]
);
return Socialite::with('twitter')->setConfig($config1)->redirect();
}
public function connect_2() {
$config2 = new Config(
env('TWITTER_CONSUMER_KEY_2'),
env('TWITTER_CONSUMER_SECRET_2'),
env('TWITTER_REDIRECT_URI_2'),
[
//
]
);
return Socialite::with('twitter')->setConfig($config2)->redirect();
}
But, I have this error when I try this code:
Configuration for TWITTER_KEY is missing. There is no services entry
for twitter
I think this will work after
https://packagist.org/packages/socialiteproviders/manager
$clientId = "secret";
$clientSecret = "secret";
$redirectUrl = "yourdomain.com/api/redirect";
$additionalProviderConfig = ['site' => 'meta.stackoverflow.com'];
$config = new \SocialiteProviders\Manager\Config($clientId, $clientSecret, $redirectUrl, $additionalProviderConfig);
return Socialite::with('provider-name')->setConfig($config)->redirect();

How to query VSTS Work Items with Wiql

I need to query VSTS work items using Wiql from vsp-node-api package, Please provide any examples if possible.
Refer to following code for details:
import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';
import * as core from 'vso-node-api/interfaces/CoreInterfaces';
var collectionUrl = "https://xxxxxx.visualstudio.com";
let token: string = "PersonalAccessToekn";
let creds = vm.getPersonalAccessTokenHandler(token);
var connection = new vm.WebApi(collectionUrl, creds);
let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();
async function WIQLquery() {
let teamC: core.TeamContext = {project: "", projectId: "", team: "", teamId: "" };
let wiqls: wi.Wiql = { query: "Select [System.Id] From WorkItems Where [System.WorkItemType] = 'Task' And [System.TeamProject] = 'Project'"};
let queryResult: wi.WorkItemQueryResult = await vstsWI.queryByWiql(wiqls, teamC);
queryResult.workItems.forEach(s=>console.log(s.url));
}
WIQLquery();
Here is how I did it, using Javascript instead of Typescript.
Shout out to Eddie Chen for leading me in the right direction.
// file - models/witModel.js
var azdev = require("azure-devops-node-api");
var Model = function(){};
Model.prototype.getWiqlQuery = function(wiqlQuery, teamName){
return new Promise(function(resolve, reject){
const orgUrl = process.env.ADOURI; // ex. https://dev.azure.com/<your org>
const token = process.env.ADOPAT; // Your personal access token
const teamProject = process.env.ADOPROJ;// Team Project
let authHandler = azdev.getPersonalAccessTokenHandler(token);
let connection = new azdev.WebApi(orgUrl, authHandler);
connection.getWorkItemTrackingApi().then(function(witAPI){
var teamContext = {project: teamProject, team: teamName };
witAPI.queryByWiql(wiqlQuery, teamContext).then(function(queryResult){
resolve(queryResult);
}).catch(function(err){reject(err)});
}).catch(function(err){
reject(err);
});
});
};
module.exports = new Model();
And this was how I used it.
// usage - the above code was saved in a module called witModel.js
// feel free to put the module where you need to.
var witModel = require("./models/witModel.js");
// form query and set the value of the teame to query
var query = {query: "your wiql query"};
var team = "team name in Azure DEvops";
// call the promise and handle resolve/reject - then/catch
witModel.getWiqlQueryResuults(query,team).then(function(data){
console.log(data);
}).catch(function(err){
console.log(err)
});

HttpFileCollectionBase: Mocking Count-Property

I try to mock the Count-Property of an instance of HttpFileCollectionBase - but somehow it doesn't work.
var fakedRequest = new Mock<HttpRequestBase>();
var fakedFile = new Mock<HttpPostedFileBase>();
fakedFile.SetupGet(x => x.InputStream).Returns(inputStream);
var fakedFileCollection = new Mock<HttpFileCollectionBase>();
fakedFileCollection.SetupGet(x => x.Count).Returns(1);
fakedRequest.SetupGet(x => x.Files).Returns(fakedFileCollection.Object);
fakedRequest.SetupGet(x => x.Files[0]).Returns(fakedFile.Object);
var sut = new TestableExploreController(null, fakedTemporaryStorageRepository.Object)
{
HttpRequest = fakedRequest.Object
};
As you see, I create a mocked HttpRequest, which I inject to the system under test. The Count-Property is defined to return 1 - but it always returns 0. I'm using Moq.
What am I doing wrong?
Scott Hanselman blogged about this. The problem is the following line:
fakedRequest.SetupGet(x => x.Files[0]).Returns(fakedFile.Object);
Try like this and it should work:
var fakedRequest = new Mock<HttpRequestBase>();
var fakedFile = new Mock<HttpPostedFileBase>();
fakedFile.SetupGet(x => x.InputStream).Returns(inputStream);
var fakedFileCollection = new Mock<HttpFileCollectionBase>();
fakedFileCollection.SetupGet(x => x.Count).Returns(1);
fakedFileCollection.SetupGet(x => x[0]).Returns(fakedFile.Object);
fakedRequest.SetupGet(x => x.Files).Returns(fakedFileCollection.Object);
Here's a deeper example using NSubstitute that allows you to foreach over the file collection
var request = Substitute.For<HttpRequestBase>();
var firstFile = Substitute.For<HttpPostedFileBase>();
firstFile.ContentLength.Returns(1);
firstFile.FileName.Returns("firstFile.txt");
firstFile.ContentType.Returns("text");
firstFile.InputStream.Returns(new MemoryStream());
var secondFile = Substitute.For<HttpPostedFileBase>();
secondFile.ContentLength.Returns(1);
secondFile.FileName.Returns("secondFile.txt");
secondFile.ContentType.Returns("text");
secondFile.InputStream.Returns(new MemoryStream());
var fileKeys = new[] { "1", "2" };
var files = Substitute.For<HttpFileCollectionBase>();
files.GetEnumerator().Returns(fileKeys.GetEnumerator());
files[fileKeys[0]].Returns(firstFile);
files[fileKeys[1]].Returns(secondFile);
request.Files.Returns(files);
Example caller usage https://stackoverflow.com/a/1760523/37055

Resources