Rectangle 27 106

I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.

After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin (ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.

You can then simply call

composer install

instead of

php composer.phar install

This finally works, I don't understand why I can't find this info anywhere on the composer website ... .

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 106

I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.

After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin (ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.

You can then simply call

composer install

instead of

php composer.phar install

This finally works, I don't understand why I can't find this info anywhere on the composer website ... .

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 1

{% if app.user and is_granted("IS_AUTHENTICATED_REMEMBERED") %}
  {{ include('FooBarBundle:Navbar:authenticated.html.twig') }}
{% else %}
  {{ include('FooBarBundle:Navbar:anonymous.html.twig') }}
{% endif %}
IS_AUTHENTICATED_REMEMBERED
IS_AUTHENTICATED_FULLY

php - Symfony2 Project, Problems with template design using twig - Sta...

php html symfony templates twig
Rectangle 27 1

{% if app.user and is_granted("IS_AUTHENTICATED_REMEMBERED") %}
  {{ include('FooBarBundle:Navbar:authenticated.html.twig') }}
{% else %}
  {{ include('FooBarBundle:Navbar:anonymous.html.twig') }}
{% endif %}
IS_AUTHENTICATED_REMEMBERED
IS_AUTHENTICATED_FULLY

php - Symfony2 Project, Problems with template design using twig - Sta...

php html symfony templates twig
Rectangle 27 3

Probably as per @0x13a 's comments you don't have openssl installed.

I think in XAMPP these are the instructions:

C:\xampp\php\ext\php.ini

If not, try adding it. I believe XAMPP should have openssl installed, but if not, you might need to look into that.

sudo apt-get install openssl

Then find out which php.ini is being used vi php from command line:

php -i |grep 'Loaded Configuration File'

Then edit the above specified php.ini with vi (below is an example):

vi /etc/php.ini

Hi Nathan30. If this fixed the problem, can you click the checkmark to mark this as the answer. There are 2 ways to respond to an answer, one way is to click the up arrow if the answer helped, the other is the checkmark to indicate it solved the problem. Thanks!

And what about users of Linux ? ;)

Hi @Marine1, what distro of Linux do you have? My answer address the OP's question which is on Windows.

16.04 ! I'm open minded about window's user ;)

@Marine1, vi is the standard text editor that has been around since the 1970's (at least). You can instead use nano editor, or whatever is available on your distro. For example nano /etc/php.ini.

php - Symfony 3 new project error - Stack Overflow

php symfony
Rectangle 27 1

It seems the only problem was the missing bin folder. I made a new symfony project, copy/pasted its bin into my cloned project and ran $ composer install as pr. Cerads advice. Then everything went smooth.

php - How to setup a basic symfony2 project after cloning it from gith...

php git symfony github configuration
Rectangle 27 33

To install assets with symlinks edit your composer.json (at the end) in this way

"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "symlink"
}

Then run composer as uusal.

php - How to properly change what composer or Symfony2 does after runn...

php symfony composer-php
Rectangle 27 67

It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system wide executable.

Installing Composer locally simply means that you are downloading a file (composer.phar - which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.

Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:

Which basically tells the php executable to run the file composer.phar with update as argument.

However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:

composer update
php composer.phar update
Could not open input file: composer.phar
composer.phar

If you have Composer installed globally, simply run composer update instead of php composer.phar update.

If you don't, either download the composer.phar to your project directory, or install Composer globally (I'd recommend the latter).

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 67

It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system wide executable.

Installing Composer locally simply means that you are downloading a file (composer.phar - which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.

Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:

Which basically tells the php executable to run the file composer.phar with update as argument.

However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:

composer update
php composer.phar update
Could not open input file: composer.phar
composer.phar

If you have Composer installed globally, simply run composer update instead of php composer.phar update.

If you don't, either download the composer.phar to your project directory, or install Composer globally (I'd recommend the latter).

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 35

As of Symfony 2.6 this issue should be fixed. A pull request has just been accepted into the master. Your problem is described in here. https://github.com/symfony/symfony/pull/11690

security.token_storage
SecurityContext
SecurityContext::getToken()

Example usage in 2.6:

services:
    my.listener:
        class: App\SharedBundle\Listener\EntityListener
        arguments:
            - "@security.token_storage"
        tags:
            - { name: doctrine.event_listener, event: prePersist }
namespace App\SharedBundle\Listener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class EntityListener
{
    private $token_storage;

    public function __construct(TokenStorageInterface $token_storage)
    {
        $this->token_storage = $token_storage;
    }

    public function prePersist(LifeCycleEventArgs $args)
    {
        $entity = $args->getEntity();
        $entity->setCreatedBy($this->token_storage->getToken()->getUsername());
    }
}

For a nice created_by example, you can use https://github.com/hostnet/entity-blamable-component/blob/master/src/Listener/BlamableListener.php for inspiration. It uses the hostnet/entity-tracker-component which provides a special event that is fired when an entity is changed during your request. There's also a bundle to configure this in Symfony2

Nice, I'm glad there's no need to inject the entire container anymore.

What about a service that is not a security token ?

What do you mean Lighthart? The security token in symfony is not a service, there's a services that gives you access to it: security.token_storage.

@Lighthart I've asked the question here since it came up during development for me as well. How would you inject any service dependend on the entity manager into a listener. Check out my question here if you have any ideas: stackoverflow.com/q/34227467/1847340

What can I do if I'm working in 2.3?

php - Injecting SecurityContext into a Listener prePersist or preUpdat...

php doctrine2 symfony
Rectangle 27 6

If you use composer to deploy to production environments, you may want to set the environment variable SYMFONY_ASSETS_INSTALL to symlink instead. This way production still uses hard copies which is the recommended option.

SYMFONY_ASSETS_INSTALL=symlink

and

export SYMFONY_ASSETS_INSTALL
.profile

php - How to properly change what composer or Symfony2 does after runn...

php symfony composer-php
Rectangle 27 3

The problem looks to be your defining a service, but then instantiating the service using new. To allow for symfony to do its things (and actually inject the dependencies) you need symfony to instantiate the service using the service container most likely:

$mailer = $container->get('app.custom_mailer');
$this->get

Purpose of this excise was to use dependency injection which should live outside controller therefore there is no access to container but actually you may be right and instead of creating new object $mailer=new \NTPBundle\Mailer\CustomMailer; i should call CustomMailer::weekExtractMail(); i will test that this afternoon and confirm

Well you don't need the controller, you need the service container for symfony to do the dependency injection. I just said the controller has a shortcut to get the container class as its a common place where you would use services.

This answer is completely right, no need to test anything different. It even says at the very top of your linked symfony docs that it's related to the service container. Also: "actually you may be right and instead of creating new object [...] i should call CustomMailer::weekExtractMail(); i will test that this afternoon and confirm" - How would calling that method as a static suddenly make $this->mailer available (heck, you don't even have $this in a static call...)? Are you always guessing? Long story short: You need the service container to get an instance of your CustomMailer.

php - Symfony 2.8 dependecy injection issue - Stack Overflow

php symfony
Rectangle 27 54

I think that this question deserves an updated answer since 2.6.x+ since the new security component improvements.

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;

class UserDateExtension extends \Twig_Extension
{
    /**
     * @var TokenStorage
     */
    protected $tokenStorage;


    /**
     * @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage    $tokenStorage
     */
    public function __construct(TokenStorage $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    public function getUser()
    {
        return $this->tokenStorage->getToken()->getUser();
    }

    public function getFilters()
    {
        return array(
            'user_date' => new \Twig_Filter_Method($this, "formatUserDate"),
        );
    }

    public function formatUserDate($date, $format)
    {
        $user = $this->getUser();
        // do stuff
    }
}
twig.date_extension:
    class: Acme\Twig\SpecialDateExtension
    tags:
        - { name: twig.extension }
    arguments:
        - "@security.token_storage"

php - Symfony2: Inject current user in Service - Stack Overflow

php dependency-injection symfony fosuserbundle
Rectangle 27 54

I think that this question deserves an updated answer since 2.6.x+ since the new security component improvements.

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;

class UserDateExtension extends \Twig_Extension
{
    /**
     * @var TokenStorage
     */
    protected $tokenStorage;


    /**
     * @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage    $tokenStorage
     */
    public function __construct(TokenStorage $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    public function getUser()
    {
        return $this->tokenStorage->getToken()->getUser();
    }

    public function getFilters()
    {
        return array(
            'user_date' => new \Twig_Filter_Method($this, "formatUserDate"),
        );
    }

    public function formatUserDate($date, $format)
    {
        $user = $this->getUser();
        // do stuff
    }
}
twig.date_extension:
    class: Acme\Twig\SpecialDateExtension
    tags:
        - { name: twig.extension }
    arguments:
        - "@security.token_storage"

php - Symfony2: Inject current user in Service - Stack Overflow

php dependency-injection symfony fosuserbundle
Rectangle 27 2

The problem is in .htaccess and more specifically in the rules Symfony2 puts there:

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]

Your request to your subdirectory project will be re-written to the front controller of the main project, game over.

There are several ways to solve this. One would be to change the .htaccess file of the main project to explicitly exclude the subproject directory. However, due to the first rule this would still allow subproject files to be served from the main project which you may not want. That can be fixed with more fiddling with the rewrite rules.

The other option would be to use Symfony2 to solve this. I have a similar project (not quite your question, but also with subprojects), and my routing.yml is like this:

collaboration:
    resource: "@CCollabBundle/Controller"
    type:     annotation
    prefix:   /{_site}
    defaults:
     _site: demo

You could simply add a routing rule without a prefix that points to your main project, and a routing rule with prefix that points to your subproject. For example (untested code, may or may not work):

mainproject:
    resource: "@MainProjectBundle/Resources/config/routing.yml"
    prefix:   /

subproject:
    resource: "@SubProjectBundle/Resources/config/routing.yml"
    prefix:   /subproject

Note that this means both your projects live in the same Symphony2 installation. If you need them absolutely seperate, fiddling with rewrite is the way to go.

Thnx. The two projects do need to be absolutely separate. I guess this problem would be easier to solve if I had access to the Apache conf (httpd.conf).

Actually, instead of a subdirectory I created a subdomain in cPanel and installed a separate Symfony project there. It works perfectly.

php - Symfony project on root and subdirectory - Stack Overflow

php apache symfony
Rectangle 27 6

as the comment sais

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

this is just checking that your IP address is allowed. And allowed IP's are contained in this array array('127.0.0.1', 'fe80::1', '::1').

PROD
php app/console cache:warmup --env=prod --no-debug
--env=prod
app.php
app_dev.php

--no-debug will exit the debug mode like it won't show the Symfony debug bar in the browser..

It's better to use web/app.php (as you just said in your note)

@Debflav yes exactly, but as i mentioned in the EDIT, this will be done from the console with the appropriate command :-)

php - Problems deploying Symfony2 project - Stack Overflow

php .htaccess symfony web-deployment
Rectangle 27 2

To solve this issue the first thing you need to do is to get the last version of composer :

curl -sS https://getcomposer.org/installer | php

I recommend you to move the composer.phar file to a global bin directoy, in my case (OS X) the path is:

mv composer.phar /usr/local/bin/composer.phar

than you need to create an alias file for an easy access

alias composer='/usr/local/bin/composer.phar'
composer --version

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 2

To solve this issue the first thing you need to do is to get the last version of composer :

curl -sS https://getcomposer.org/installer | php

I recommend you to move the composer.phar file to a global bin directoy, in my case (OS X) the path is:

mv composer.phar /usr/local/bin/composer.phar

than you need to create an alias file for an easy access

alias composer='/usr/local/bin/composer.phar'
composer --version

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 3

Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:

php composer.phar install

This will automatically find the composer.json and run your required scripts. Good luck. This stuff is a breeze for terminal wizards and totally bizarre to the rest of us

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php
Rectangle 27 3

Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:

php composer.phar install

This will automatically find the composer.json and run your required scripts. Good luck. This stuff is a breeze for terminal wizards and totally bizarre to the rest of us

php - Running Composer returns: "Could not open input file: composer.p...

php symfony wamp composer-php