I have a project where I use only PHP Templates (instead of twig). Where can I set the default engine for #Template so I do not have to do the below all the time?
#Template(engine="php")
In config.yml I think the following should work:
framework:
templating: { engines: ['php'] }
Related
I'm writing a test in Laravel and I want to unittest this piece of code:
if (file_exists(\Config::get('maintenance.dir.api'))) {
throw new ServiceUnavailableException('We are down for maintenance');
}
I'm using Illuminate\Foundation\Testing\TestCase and I can't access to the config variables from the main app in the test. In my package, I don't have any config. Can I mock the config folder or something like that?
Thank you!
You can 'mock' config variables by simply setting them:
config(['maintenance.dir.api' => 'mock value'])
The question is - how to force Laravel Elixir not to generate map files?
At the moment if I run gulp I will have generated app.css and app.css.map file. I don't know what for is this app.css.map file but I think it's not necessary for me at the moment. Question is - how to force gulp not to generate this file?
At the moment my gulpfile.js looks like this:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.sass('app.scss', 'public/css/app.css');
});
This is no longer achievable via elixir.extend() syntax, instead the official documentation now suggests to use this:
elixir.config.sourcemaps = false;
Starting from Elixir 3.0 you can put a JSON object that will override the default configuration in elixir.json:
{
"sourcemaps": false
}
.map files are called source maps. Their purpose is to map the contents of a concatenated, minified file to it's original files to make debugging easier.
You can disable them by changing elixirs config using extend() in your gulpfile
elixir.extend('sourcemaps', false);
Note that source maps are disabled by default when running in production.
I try to build a simple application using Zend Framework 2 and Doctrine 2. I decided to use YAML config files so my doctrine.yml file is as follow:
driver:
application_entities:
class: 'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
cache: 'array'
paths:
- '__DIR__/../src/__NAMESPACE__/Entity'
orm_default:
drivers:
'Application\Entity': application_entities
authentication:
orm_default:
object_manager: 'Doctrine\ORM\EntityManager'
identity_class: 'Application\Entity\User'
identity_property: 'login'
credential_property: 'password'
configuration:
orm_default:
metadata_cache: 'array'
query_cache: 'array'
Now, the question is: is my cache config proper? And how can I verify it's actually working?
Of course I know I should use some better driver than simple array but for the moment it's enough for me.
Doctrine provides a set of command-line tools to simplify common administration tasks such this. Here is an example list of available commands:
In your case, you should use orm:ensure-production-settings command to make sure that Proxy Generation, Metadata and Query cache configurations are correct.
Assuming that you are using DoctrineORMModule to integrate doctrine with zend framework 2, open the console and simply type:
$ cd /path/to/your/projectroot
$ php public/index.php orm:ensure-production-settings
The output will warn you if the caching configuration is incorrect.
Here is the detailed official documentation for doctrine console.
I'm running a Rails 3.1.1 application on Heroku Cedar. By default this stack doesn't Gzip and set Expires Headers on assets.
There is some doc about that, but it's not very clear : http://devcenter.heroku.com/articles/http-routing
Can somebody give me the piece of code to activate that ?
Thank you very much
Cedar doesn't use Nginx, so you have to gzip assets yourself with Rack::Deflater, like so :
# config.ru
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run YourApp::Application
Also you can set headers for static files directly in your app :
# config/environments/production.rb
config.static_cache_control = "public, max-age=3600"
Finally you're probably better off setting up Rack::Cache to replace Varnish caching. See this blog post for more infos.
Shameless plug - I created a gem which enables compression, but avoids compressing images.
https://github.com/romanbsd/heroku-deflater
It is important that the middleware be included early, before ActionDispatch::Static
#production.rb
config.middleware.insert_before ActionDispatch::Static, Rack::Deflater
> rake middleware
use Rack::Deflater
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f8e18455e90>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Remotipart::Middleware
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use Warden::Manager
use Rack::Mongoid::Middleware::IdentityMap
use Rack::Pjax
run MyApp::Application.routes
Because of deployment constraints, I would like to have the log and cache directories used by my Symfony2 application somewhere under /var/... in my file system. For this reason, I am looking for a way to configure Symfony and to override the default location for these two directories.
I have seen the kernel.cache_dir and kernel.log_dir and read the class Kernel.php. From what I have seen, I don't think that it is possible to change the dir locations by configuration and I would have to patch the Kernel.php class.
Is that true, or is there a way to achieve what I want without modifying the framework code?
Add the following methods to app/AppKernel.php (AppKernel extends Kernel) making them return your preferred paths:
public function getCacheDir()
{
return $this->rootDir . '/my_cache/' . $this->environment;
}
public function getLogDir()
{
return $this->rootDir . '/my_logs';
}
I was happy to find your post, but I was a little bit confused of the unhelping answers.
I got the same problem and found out that the logs are depending on the config parameter
kernel.logs_dir.
So I just added it to my config.yml parameters:
kernel.logs_dir: /var/log/symfonyLogs
I hope it will helpfull for you even, if its a late answer.
i think the easiest way is to link the folder to another place. We have made this on the prod server but when you develop local perhaps on windows its a bit complicated to set the symlinks.
ln -s /var/cache/ /var/www/project/app/cache
something like this.
I would like to offer an alternative and that is to set environment variables to change these directories. This way it's easier to set depending on the stage. (testing, production or development)
export SYMFONY__KERNEL__CACHE_DIR "/your/directory/cache"
export SYMFONY__KERNEL__LOGS_DIR "/your/directory/logs"
Environment variables can also be set in the virtual host with SetEnv.
When reading kernel parameters symfony will look for all the $_SERVER variables that start with SYMFONY__, strip the first part and convert all the double underscores into a .
Source code
See line 568 to 608
In symfony you can override the cache (and logs) directory by extending the method in AppKernel.
// app/appKernel.php
class AppKernel extends Kernel
{
// ...
public function getCacheDir()
{
return $this->rootDir.'/'.$this->environment.'/cache';
}
}
Check out http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html#override-cache-dir
I used the configuration solution from Dragnic but I put the paths in the parameters.yml file because this file is ignored by git. in other words, it's not synchronized from my PC to the git repository so there is no impact in the prod environment.
# app/config/parameters.yml
parameters:
database_driver: pdo_mysql
[...]
kernel.cache_dir: "T:/project/cache"
kernel.logs_dir: "T:/project/logs"
Configuration: Windows7, WAMP 2.4 and Symfony 2.3.20.
But you have to know that:
Overwriting the kernel.cache_dir parameter from your config file is a very bad idea, and not a supported way to change the cache folder in Symfony.
It breaks things because you would now have different cache folders for the kernel Kernel::getCacheDir() and for the parameter.
Source: https://github.com/symfony/AsseticBundle/issues/370
So you should use it only in dev environment and if you don't want to change the content of the app/AppKernel.php file, otherwise see the other answers.
No accepted answer, and a really old question, but IĀ found it with google, so I post here a more recent way to change the cache directory, and the logs directory, (source here)
remember, short syntax for arrays require php 5.4
you can select the env to modify, and manage different cache and logs directories if you want
public function getCacheDir()
{
if (in_array($this->environment, ['prod', 'test'])) {
return '/tmp/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, ['prod', 'test'])) {
return '/var/log/symfony/logs';
}
return parent::getLogDir();
}