php-general Digest 31 Oct 2011 09:44:58 -0000 Issue 7546

Topics (messages 315551 through 315561):

Dependency Injection Implementation
        315551 by: jean-baptiste verrey

Novice question
        315552 by: John Allsopp
        315553 by: Negin Nickparsa
        315554 by: Marc Guay
        315555 by: Bastien
        315558 by: Rico Secada

Re: Zend Amf and Drupal?
        315556 by: Lars Nielsen

function.session-start in Webmaster Tools
        315557 by: Rick Dwyer
        315559 by: Jeremiah Dodds
        315561 by: Stuart Dallas

Re: Array has `trailing comma`, why not the same for function parameter list?
        315560 by: Jeremiah Dodds

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi everyone,

Dependency Injection is a very trendy subject and after reading about it I
kinda thought about rewriting the framework I'm doing with dependency
injection. So I made my own implementation and was wondering what would you
think about it? I have followed the article of Martin Fowler (
http://martinfowler.com/articles/injection.html)

with this implementation I have the following :
- you have both constructor and setter injection
- the Dependency class is a service locator
- we have at the same time service locator AND dependency injection
- you can always manually inject dependency
- you can pass arguments to the injected object constructor

So: am I missing something? Do you think it's good enough?

here is the code :
<?php
class Dependency {
    protected $_singletonInstances = array();
    protected $_setInstances = array();
    protected $_configuration;

    public static function getInstance() {
        static $instance = NULL;
        if (NULL === $instance) {
            $instance = new static();
        }
        return $instance;
    }

    public function setConfiguration(array $configuration) {
        $this->_configuration = $configuration;
    }

    public function getConfiguration() {
        return $this->_configuration;
    }

    public function __isset($serviceName) {
        return isset($this->_serviceInstances[$serviceName]);
    }

    public function __call($serviceName, $args) {
        // singleton
        if (isset($this->_configuration[$serviceName]) &&
$this->_configuration[$serviceName]['singleton']) {
            if (!isset($this->_singletonInstances[$serviceName])) {
                $rc = new
\ReflectionClass($this->_configuration[$serviceName]['class']);
                $this->_singletonInstances[$serviceName] = empty($args) ?
$rc->newInstance() : $rc->newInstanceArgs($args);
            }
            $ret = $this->_singletonInstances[$serviceName];
        } else {
            // normal
            if (isset($this->_setInstances[$serviceName])) {
                $ret = $this->_setInstances[$serviceName];
                unset($this->_setInstances[$serviceName]);
            } else {
                $rc = new
\ReflectionClass($this->_configuration[$serviceName]['class']);
                $ret = $this->_singletonInstances[$serviceName] =
empty($args) ? $rc->newInstance() : $rc->newInstanceArgs($args);
            }
        }
        return $ret;
    }

    public function __get($serviceName) {
        return $this->__call($serviceName, array());
    }

    public function __set($serviceName, $instance) {
        if (!is_object($instance))
            throw new Exception('instance must be an object');
        $this->_setInstances[$serviceName] = $instance;
    }
}
class DependencyInjectorException extends \Exception {

}

$di=DependencyInjector::getInstance();
$di->setConfiguration(array(
    'database.connector'=>array(
        'singleton'=>true,
        'class'=>'DatabaseConnector'
    ),
    'database'=>array(
        'singleton'=>true,
        'class'=>'Database'
    )
));

class DatabaseConnector{}
class Database{
    protected $_connector;
    public function __construct(){

$this->setConnector(DependencyInjector::getInstance()->{'database.connector'});
    }

    public function setConnector($connector){
        $this->_connector=$connector;
    }
}
class Test{
    protected $_database;
    public function __construct(){
        $this->setDatabase(DependencyInjector::getInstance()->database);
    }

    public function setDatabase($db){
        $this->_database=$db;
    }

    public function getDatabase(){
        return $this->_database;
    }
}

$test=new Test();
var_dump($test->getDatabase());

?>

--- End Message ---
--- Begin Message ---
Hi

I'm afraid I've fallen a little out of touch with PHP dev, so a stupid
question for you.

I want to write a script that requests a URL and then reads that website
.. I'm interested to map web structures. My web host is saying I'll need
URL file access enabled but that it's a) a security risk and b)
deprecated.

So .. what's the good / proper / acceptable / secure way of reading in
URLs in PHP or .. isn't there one?

Cheers
J

-- 
01723 376477

Cost-free marketing: http://www.flowmarketing.co.uk/

Affordable marketing guidance for small businesses:
http://www.amilliontweaks.co.uk/

Effective marketing services for SMEs: coming soon at
http://www.surgemarketing.co.uk

Professional Internet marketing consultancy: http://www.johnallsopp.co.uk


--- End Message ---
--- Begin Message ---
Your question is NOT Novice and I really want to know the answer like you.

On 10/30/11, John Allsopp <j...@johnallsopp.co.uk> wrote:
> Hi
>
> I'm afraid I've fallen a little out of touch with PHP dev, so a stupid
> question for you.
>
> I want to write a script that requests a URL and then reads that website
> .. I'm interested to map web structures. My web host is saying I'll need
> URL file access enabled but that it's a) a security risk and b)
> deprecated.
>
> So .. what's the good / proper / acceptable / secure way of reading in
> URLs in PHP or .. isn't there one?
>
> Cheers
> J
>
> --
> 01723 376477
>
> Cost-free marketing: http://www.flowmarketing.co.uk/
>
> Affordable marketing guidance for small businesses:
> http://www.amilliontweaks.co.uk/
>
> Effective marketing services for SMEs: coming soon at
> http://www.surgemarketing.co.uk
>
> Professional Internet marketing consultancy: http://www.johnallsopp.co.uk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> I want to write a script that requests a URL and then reads that website
> .. I'm interested to map web structures. My web host is saying I'll need
> URL file access enabled but that it's a) a security risk and b)
> deprecated.


simplehtmldom is pretty great for this, if I understand your needs
correctly... also not sure about it's server setting requirements, but
worth a look..


http://simplehtmldom.sourceforge.net/

--- End Message ---
--- Begin Message ---
On 2011-10-30, at 2:45 PM, Marc Guay <marc.g...@gmail.com> wrote:

>> I want to write a script that requests a URL and then reads that website
>> .. I'm interested to map web structures. My web host is saying I'll need
>> URL file access enabled but that it's a) a security risk and b)
>> deprecated.
> 
> 
> simplehtmldom is pretty great for this, if I understand your needs
> correctly... also not sure about it's server setting requirements, but
> worth a look..
> 
> 
> http://simplehtmldom.sourceforge.net/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Another option is cURL www.php.net/curl

Bastien Koert
905-904-0334


--- End Message ---
--- Begin Message ---
On Sun, 30 Oct 2011 17:24:07 -0000
"John Allsopp" <j...@johnallsopp.co.uk> wrote:

> Hi
> 
> I'm afraid I've fallen a little out of touch with PHP dev, so a stupid
> question for you.
> 
> I want to write a script that requests a URL and then reads that
> website .. I'm interested to map web structures. My web host is
> saying I'll need URL file access enabled but that it's a) a security
> risk and b) deprecated.
> 
> So .. what's the good / proper / acceptable / secure way of reading in
> URLs in PHP or .. isn't there one?

cURL is the best one in my experience, but you have to manage security
yourself. Meaning: Remember to escape/encode data.

http://php.net/manual/en/book.curl.php

> Cheers
> J
> 
> -- 
> 01723 376477
> 
> Cost-free marketing: http://www.flowmarketing.co.uk/
> 
> Affordable marketing guidance for small businesses:
> http://www.amilliontweaks.co.uk/
> 
> Effective marketing services for SMEs: coming soon at
> http://www.surgemarketing.co.uk
> 
> Professional Internet marketing consultancy:
> http://www.johnallsopp.co.uk
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
Silence.... ?
I havn't got any responses from drupal.org, and i think its very quiet
here too?
Should I start to analyze the code to understand the inner workings? Can
anyone give some advise on where to get more information?

Or... is there another proven way to communicate between Flash and
PHP/Drupal?

Regards
Lars Nielsen
lør, 29 10 2011 kl. 12:53 +0200, skrev Lars Nielsen:
> Hey List,
> 
> I am making a webservice in Drupal with AMF Zend to provide some methods
> to a Flash app. I have now managed to use standard Drupal services
> (node,user and files) and I have made my own method to create users.
> But! ... When I try to pass on arguments from Flash to Drupal it fails.
> It says that it expects zero arguments but I have provided 4 arguments.
> 
> I have posted some info here : http://drupal.org/node/1323678
> 
> Can you give me some guidelines? or pointers on what to do?
> 
> Kind Regards
> Lars Nielsen
> www.lfweb.dk / www.gearworks.dk
> 
> 
> 




--- End Message ---
--- Begin Message ---
Hello all.

Not sure just how much of this is PHP related, but hoping someone has come across this before.

I Google's webmaster tools for a site I work on, they list more than 100 crawl errors for pages with URL's as follows:

http://mydomain.com/My-Directory/function.session-start

Can anyone explain why webmaster tools is seeing pages with links ending in "function.session-start"? I read up on the error itself... sometimes caused by whitespace before the session_start tag... have fixed that. Any info is appreciated.



 --Rick


--- End Message ---
--- Begin Message ---
On Sun, Oct 30, 2011 at 4:30 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
> Hello all.
>
> Not sure just how much of this is PHP related, but hoping someone has come
> across this before.
>
> I Google's webmaster tools for a site I work on, they list more than 100
> crawl errors for pages with URL's as follows:
>
> http://mydomain.com/My-Directory/function.session-start
>
> Can anyone explain why webmaster tools is seeing pages with links ending in
> "function.session-start"?  I read up on the error itself... sometimes caused
> by whitespace before the session_start tag... have fixed that.  Any info is
> appreciated.
>

Off the top of my head, check to make sure your robots.txt is in
order, see http://www.robotstxt.org/robotstxt.html

--- End Message ---
--- Begin Message ---
On 30 Oct 2011, at 20:30, Rick Dwyer wrote:

> Hello all.
> 
> Not sure just how much of this is PHP related, but hoping someone has come 
> across this before.
> 
> I Google's webmaster tools for a site I work on, they list more than 100 
> crawl errors for pages with URL's as follows:
> 
> http://mydomain.com/My-Directory/function.session-start
> 
> Can anyone explain why webmaster tools is seeing pages with links ending in 
> "function.session-start"?  I read up on the error itself... sometimes caused 
> by whitespace before the session_start tag... have fixed that.  Any info is 
> appreciated.


You have PHP errors somewhere on your site. The error messages contain links 
that could result in those URLs. Find out what pages are linking to those URLs 
and check them for errors.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On Sun, Oct 30, 2011 at 8:47 AM, Nam Gi VU <nam.gi...@gmail.com> wrote:
> It is convenient to have a trailing comma when defining an array - so as
> easy to add/remove code to add/remove an entry to the array
>
> array(
>    'key00' => 'value00',
>    'key01' => 'value01',
>    'key02' => 'value02',
>    ...
> )
>
> I suggest to PHP Development team to make it available in the syntax to
> have a leading comma
> array(
>    ...
>    , 'key00' => 'value00'
>    , 'key01' => 'value01'
>    , 'key02' => 'value02'
> )
> in such way, we can thought of the leading commas as the list bulletings.
>
> And the same things would be lovely to be applied also to function
> parameter list. I don't see why not :)
>
> What do you thing about my suggestion? Hope to hear from you!
>

WRT functions: while I could see how this would seem like a good idea
because of the symmetry in what's going on at a very high level of
abstraction, I would be against including it in a language. I don't
particularly like it for arrays, but it does make it easy to add items
into an array, which happens pretty often in development, especially
when writing exploratory code. Function signatures, on the other hand,
probably aren't changing nearly as often.

 At the very least, I wouldn't want to encourage people to make
functions with many parameters, as it's normally a sign of poor
design. This wouldn't explicitly do so, but would do so implicitly as
it's only real purpose is to make it easier to add things.

As far as the supporting-a-leading-comma thing goes, I'm pretty
ambivalent on it. I don't really like the style outside of Haskell
code, but that's just a preference.

--- End Message ---

Reply via email to