Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Global functions with Symfony2 ???
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Noel Garcia  
View profile  
 More options Jun 6 2012, 3:48 am
From: Noel Garcia <noelgarciamol...@gmail.com>
Date: Wed, 6 Jun 2012 00:48:27 -0700 (PDT)
Local: Wed, Jun 6 2012 3:48 am
Subject: Global functions with Symfony2 ???

I'm searching to the best & most elegant way to have, in symfony2 project,
functions available at global scope, ie, you can access everywhere in the
project.

Firstly, a requirement/function example:
I need to merge various "number-keyed" arrays (eg [4=>"foo", 7=>"bar"])
maintaing the keys, so php array_merge function isn't valid for me.
I found this function at stackoverflow (
http://stackoverflow.com/questions/10083158/how-to-merge-two-php-doct...)
function array_merge_maintain_keys() {
    $args = func_get_args();
    $result = array();
    foreach ( $args as &$array ) {
        foreach ( $array as $key => &$value ) {
            $result[$key] = $value;
        }
    }
    return $result;

}

Some ideas:
-A Trait (php 5.4): I don't like this, code is reusable, but isn't elegant
-A php extension: too much effort to add an stupid function
-Add an include_once at the end of app/autoload.php pointing to a plain php
file with that kind of simple function(s)
-A class static methods, something like
\Acme\Utils::array_merge_mantain_keys();
-A service is another option, but if I need to call that function from an
entity I would have to inject it previously (I hate this)

Which would be the best & the most elegant solution?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eriksen Costa  
View profile  
 More options Jun 11 2012, 1:51 pm
From: Eriksen Costa <eriksenco...@gmail.com>
Date: Mon, 11 Jun 2012 14:51:14 -0300
Local: Mon, Jun 11 2012 1:51 pm
Subject: Re: [symfony-devs] Global functions with Symfony2 ???

I think this is a question for the symfony-users mailing list.

I would use a class with a static method. Or take a look at how Symfony
includes files with functions in the autoload.php file:

https://github.com/symfony/symfony/blob/master/autoload.php.dist

For the intl stub functions, for example, it just require the file
functions.php

require_once
__DIR__.'/src/Symfony/Component/Locale/Resources/stubs/functions.php';

Eriksen

--
Blog: http://blog.eriksen.com.br
Twitter: @eriksencosta

On Wed, Jun 6, 2012 at 4:48 AM, Noel Garcia <noelgarciamol...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stéphane  
View profile  
 More options Jun 11 2012, 2:59 pm
From: Stéphane <stephane.er...@gmail.com>
Date: Mon, 11 Jun 2012 20:59:47 +0200
Local: Mon, Jun 11 2012 2:59 pm
Subject: Re: [symfony-devs] Global functions with Symfony2 ???

Latest composer let you automatically require function files. Look at its
github's latest commits.

Regards,

On Mon, Jun 11, 2012 at 7:51 PM, Eriksen Costa <eriksenco...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »