I am curious if there is a best practice concerning the location of a website's cache folder (templates, images, etc)?
I often see it residing in the webroot with index.html/index.php like so,
Server
`-- /var/
`-- www/
-- example.com/
|-- .git/
|-- public_html/
| |-- cache/
| |-- assets/
| `-- index.html
|-- src/
|-- test/
|-- .gitignore
`-- package.json
However, would it be considered bad practice or create any security concerns if I place the cache folder up one level with the rest of the private project files (.git, node_modules, etc)? Like so...
Server
`-- /var/
`-- www/
-- example.com/
|-- .git/
|-- cache/
|-- public_html/
| |-- assets/
| `-- index.html
|-- src/
|-- test/
|-- .gitignore
`-- package.json
Apologies if this isn't a question for here, but I wasn't able to find much information on best practices regarding project folder structure for the cache. The only stuff I could find was about best practices on using the browser cache and other caching tools.
Thanks!
Related
Since I couldn’t find a proper documentation and examples for flysystem, I am asking you for help. Currently I am developing a plugin (for Shopware 6), and I am using some sources that are stored inside my plugin (such as pictures, and csv files).
The structure looks like this
|-- custom
|-- plugins
|-- ImporterPlugin
|-- src
|-- Adapter
|-- CsvImportAdapter.php
|-- ImportAdapterInterface.php
|-- Command
|-- ImportCommand.php
|-- Factory
|-- AdapterFactory.php
|-- Resources
|-- Service
|-- ImporterPlugin.php
|-- upload
|-- product.csv
|-- media
|-- Image1.jpg
Inside .env I wrote the file paths that I need
IMPORT_CSV_PATH=/var/www/html/custom/plugins/ImporterPlugin/upload/products.csv
IMPORT_MAP_PATH=/var/www/html/custom/plugins/ImporterPlugin/src/Resources/maps/product.map.json
PRODUCTIMPORTER_MEDIA_SOURCE_PATH=/var/www/html/custom/plugins/ImporterPlugin/upload/media/
My question is, how can I implement Local Adapter (Flysystem)? And where to call functions / methods? The functionality of the plugin is mainly called in command line. Please provide some examples. Thanks
In your services.xml of your plugin you can use the FileSystemFactory and a collection of arguments to define your filesystem abstraction.
<service class="League\Flysystem\FilesystemInterface" id="importer_plugin.filesystem.private" public="true">
<factory service="Shopware\Core\Framework\Adapter\Filesystem\FilesystemFactory" method="factory"/>
<argument type="collection">
<argument key="type">local</argument>
<argument key="config" type="collection">
<argument key="root">%kernel.plugin_dir%/ImporterPlugin/upload</argument>
</argument>
</argument>
</service>
You can then inject importer_plugin.filesystem.private into your other services and work with the filesystem abstraction rooted in the upload directory.
public function __construct(FilesystemInterface $filesystem)
{
$this->filesystem = $filesystem;
}
// ...
$products = $this->filesystem->read('products.csv');
I have a too basic php application that I wante to run through the built-in php server and that lives in my VM in my windows machine:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App();
$app->get('/', function (Request $req, Response $res, $arg = []) {
return 'hello world!!';
});
$app->run();
My project structure
tree -I vendor
.
|-- cache
| `-- 6a
| `-- 532bg9987gt23f4356546poo999vvb234234.php
|-- composer.json
|-- composer.lock
|-- public
| `-- js
| `-- app.js
|-- routes
| `-- web.php
`-- views
`-- templates
`-- index.html
7 directories, 7 files
When I run curl from within my VM it obviously works:
php -S localhost:9899&
curl localhost:9899/routes/web.php
Hello world!!
The problem is when I try to connect to this server from my browser (windows machine) I get
This site can’t be reached
Although this doesn't work for my php built-in server, it works perfectly for two other projects developed with nodejs that are on the same VM as the php one.
Why I'm not able to reach the php built-in server especially that nodejs built-in server are accessible?
You are binding your server to localhost. It is only listening on the localhost network interface. It won't be accessible outside of that machine.
Tell it to listen on your externally facing IP address instead.
Alternatively, tell it to listen on all network interfaces:
php -S 0.0.0.0:9889
I have this folder structure (symfony 2 application):
src
|-- Application
| |-- UserBundle
| | |-- Admin
| | |-- Api
| | |-- SomeController.php
| | |-- Controller
| | |-- DefaultController.php
| | |-- DependencyInjection
| | |-- Entity
| | |-- Resources
| | |-- Tests
I want to call some controller from Api folder. How i can do this?
UPD.
I use symfony routing to provide the controller:
application_homepage:
path: /hello/{name}
defaults: { _controller: ApplicationUserBundle:Default:index }
application_some:
path: /api/{slug}
defaults: { _controller: ApplicationUserBundle:../Api/Some:index }
I want to load controller from Api folder
If the namespace of your controller is : Application\UserBundle\Api,
that the className is SomeController and the action is indexAction
You can use this syntax in your routing file :
application_some:
path: /api/{slug}
defaults: { _controller: Application\UserBundle\Api\SomeController::indexAction }
This solution will work too:
application_some:
resource: "#ApplicationUserBundle/Api"
type: annotation
or:
application_some:
resource: "#ApplicationUserBundle/Api/SomeController.php"
type: annotation
see http://symfony.com/doc/current/book/routing.html#including-external-routing-resources
If both controller sit within the same namespace, you could simply do
$controller = new ControllerInApiFolder();
$conotroller->someFunction();
if they do not, then you need to include the controller via use-statement.
use Namespace\My\Controller\Sits\In\ControllerInApiFolder;
If you are trying to access the controller not from another controller, but from a template, an url or a testcase, you should refer to the symfony2 documentation.
Symfony2 Doc
From the edited question above I take it you want to call the controller via the url.
In your browser you can simply type in
path/to/my/web/api/something
or
path/to/my/web/app_dev.php/api/something
where "path/to/my/web" referes to the path of the web folder within your project
EDIT: I think now I am getting the problem...
Symfony2 routing always defaults to the /Controller folder to look for the controller (which is quite nice).
I am not quite sure you should add another folder to this. Instead, the documentation suggests having multiple folders inside the /Controller folder.
If you take a look at the folder structure displayed here: Symfony2 Controller, you will notice that there is an API folder within the /Controller folder.
<your-project>/
├─ ...
└─ src/
└─ AppBundle/
├─ ...
└─ Controller/
├─ DefaultController.php
├─ ...
├─ Api/
│ ├─ ...
│ └─ ...
└─ Backend/
├─ ...
└─ ...
I'm starting in Doctrine 2.4 and I'm developing a system where I separate the core files and application files, as follows:
/ root
|-- /Src
|-- / App
|-- /Model
|- ** (Application Entities) **
|-- /Core
|-- /Model
|-- ** (Core Entities) **
In the Doctrine documentation shows the following form to set 1 directory for Esntitys:
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__. "/src"), $isDevMode);
But when I have to configure more than one directory that will contain the Entitys of my application, how to proceed?
Thanks in advance!
I found a way to resolve the issue. Simple!!!
Put like this:
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/App/Model/", __DIR__."/src/Core/Model/"), $isDevMode);
I'm creating an app in Symfony which is using a library I'm writing at the same time.
While my application is being built with symfony, I want the component library to be completely framework independent as it needs to be reusable by applications not necessarily written in symfony.
Therefore I have a symfony bundle which integrates the library (the component)
The folder structure is a follows
src/MyVendor/
|-- Bundle
| `-- MyComponentBundle
| |-- Controller
| |-- DependencyInjection
| |-- Resources
| | |-- config
| | `-- views
| | `-- Default
| |-- Tests
| `-- Controller
| `-- MyObjectControllerTest.php
| `-- MyComponentBundle.php
`-- Component
`-- MyComponent
|-- doc
|-- src
`-- MyObject.php
|-- test
`-- MyObjectTest.php
|-- .gitignore
|-- composer.json
|-- LICENSE
|-- README.md
`-- phpunit.xml.dist
Questions:
Is MyComponent directory structure correct as per the PSR-x Autoloading standards? For example, how do I use MyObject from the library inside the bundle, i.e. in MyObjectControllerTest.php
Can MyObject reside in the namespace of MyVendor\MyComponent? If not, how do I have to amend the directory structure so that (1) I can use that namespace, and (2) so that it can be autoloaded inside MyObjectControllerTest.php, i.e. new MyVendor\MyComponent\MyObject(); will work; right now I'm getting PHP Fatal error: Class 'MyVendor\MyComponent\MyObject' not found in ...
Could you please direct me to an online resource to help me to publish MyComponent on github and make it available to symfony (I'm guessing most of that involves just setting up composer.json correctly)
Thank you
It's compatible with PSR-x autoloaders. But your namespaces should be properly registered (PSR-4, PSR-0).
You should create proper autoload to use your component (using composer, for example).
Just create a repo for your component on github, create your composer.json (or copy/past and edit some side one), submit your package on packagist (just insert github project link)