accessing resource file in vendors bundle - symfony

I have a Symfony2 bundle which contains some wsdl files in Resources directory. It forces me to define some additional entries in config file like:
parameters.fx_wsdl = '../vendor/project-name/bundleName-bundle/vendorName/xxxBundle/Resources/confid/ws/fx.wsdl'
yeach, as you see it looks ugly. Is there a way to define it as:
parameters.fx_wsdl = 'VendorNameBundleNameBundle/Resources/confid/ws/fx.wsdl'
any object which can translate VendorNameBundleNameBundle into ../vendor/project-name/bundleName-bundle/vendorName/xxxBundle automatically

Related

Relative path configuration in appsettings.json in .NET Core

For sake of simplicity lets say we have the following structure of configuration files where I load all of them:
c:\apps\myapp\appsettings.json
c:\apps\appsettings.json
c:\appsettings.json
The configuration "schema" looks like this:
{
"logPath": "c:\\apps\\logs"
}
Instead of giving absolute path of log folder, I would like to give relative one like .\\logs where . would be current configuration file. While debugging I discovered that IConfigurationRoot contains all those configuration sources (in this case JsonConfigurationSource) which contains path to configuration file, but I didn't find any way how to get ConfigurationSource for specific key. So Something like IConfigurationRoot.GetConfigurationSource(string key).
Is there any way how to get configuration source for specific key? Or maybe some other way to use relative paths?

How to Make My Data File (JSon) Available in ASP.NET Project

How can I add a static data file to my web project? It doesn't work in debug mode with IIS Express, and I don't have a web site to deploy to yet.
Details
I have a data file that I want to expose on my web site. I have added that file to my ASP.NET project. When I run the project and attempt to view the file, I get a 404. In other words, I debug the project and type the file url into the browser. That url looks like 'https://localhost:44378/Data/widgetConfigMap.json'.
Rationale:
I need the data file to feed a javascript method. That method has an input parameter for a url with data, i.e. my file. The API in question is Bing Maps. The method name is 'createFromConfig'.
Unsatisfactory Alternative
I can generate the file 'on-the-fly' (via a method in my controller), but that method is slow. Slow enough that it timed-out once.
What I have tried
I tried updating the file properties. Initially, the file Build Action was 'Content', I changed that to 'Page', then to 'Resource' → neither worked. The other property choices look wrong.
Summary
I feel like there should be some way to configure my project, or IIS Express to serve-up the data file, but I can't find it.
It sounds like you just add the json file to your project folder instead of importing the json item into your project.
You can access json file directly when you have imported either new json item or existing json file to your /Data folder under your application.
Besides, please ensure you have let your route ignore the URL so static file handler will handle this.
Of course, you can try to publish it to local IIS not IIS express. Then import the data file and it shouldn't be limited.

Symfony access assets folder

I have some folders in www/web/ which is the root.
It's the following folder: assets/exports/
And it contains a file export.xsl
When I do in javascript:
window.open('/assets/exports/export.xsl');
I'm going to the following link:
http://mywebsite/assets/exports/export.xsl
But I get a: 404 not found
Is symfony somehow protecting this link?
So, my question is, how can I access this file, so it starts downloading for the visitor?
From Symfony Documentation:
Keep in mind that web/ is a public directory and that anything stored here will be publicly accessible, including all the original asset files (e.g. Sass, LESS and CoffeeScript files).
Make sure you put the files in a proper directory: <symfony_root_dir>/web. See below.
Then accessing the http://mywebsite/assets/exports/export.xsl returns the file's content.
Check also your server configuration, virtual host config and read web server configuration guide from Symfony to see if you configured it properly.

How to tell Symfony to ignore certain files in /translations

How can I tell Symfony to ignore a file with a certain suffix in the Bundle's /translations directory?
for example, I would like it to ignore the .pot file but if I put one there, it then tries to load it and cannot find a loader.

How to hide physical path for images and files in symfony2

I've got to read and serve a lot of resources (images and files) and I want to hide real path where resources are stored. What is the best way to do it with symfony 2.x?
If you want to abstract from the filesystem you could use KnpGaufretteBundle. Gaufrette is a PHP library that abstracts the filesystem. That is, you can access resources no matter where they are stored (e.g., the local filesystem, a FTP server, Amazon S3, Dropbox, etc).
However, Gaufrette does not abstract the path (you set up a kind of base directory for the filesystem) and you would use a path relative to this base directory. Consider the following code that abstracts the local filesystem:
<?php
use Gaufrette\Filesystem;
use Gaufrette\Adapter\Local as LocalAdapter;
$adapter = new LocalAdapter('/var/media');
$filesystem = new Filesystem($adapter):
$content = $filesystem->read('myFile.txt');
$content = 'Hello I am the new content';
$filesystem->write('myFile.txt', $content);
In this example you would read and write the file /var/media/myFile.txt.
If you want to further abstract the filesystem, you could create a service that has a map of files and its aliases. For example, you could read a list of these file/alias pairs from a YAML configuration file. You can then get the real filename by using some kind of getter with the alias as parameter.

Resources