SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36
  1. #26
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Yes, sorry, that was typo. It should indeed be:
    PHP Code:
        public function execute(){
            
    $this->_connection->sendFrame($this->_xml);
            return 
    $this->_connection->getFrame();
        } 
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  2. #27
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    Yes, sorry, that was typo.
    One day Sir Anthony, really, one day, I will do typos as well while I write some nice code in 5 minutes while on a reunion!!!

    Conexao.Class.php

    PHP Code:
    class Conexao
    {
        protected 
    $_filePointer;

        public function  
    __construct($hostname$port)
        {
            
    $this->_filePointer fsockopen($hostname$port);
        }

        public function 
    write($data$length null)
        {
            return 
    fwrite($this->_filePointer$datanull===$length strlen($data) : $length);
        }

        public function 
    read($length)
        {
            return 
    fread($this->_filePointer$length);
        }

    ConexaoEpp.Class.php
    PHP Code:
    require_once ('Conexao.class.php');

    class 
    ConexaoEpp extends Conexao
    {
       const 
    OFFSET 4;

       
    //Type Hinting on PHP own objects!! SO NICE :)
       
    public function sendFrame(SimpleXMLElement $frame)
       {
           return 
    parent::write(pack('N'strlen($frame->asXML())+ self::OFFSET) . $frame->asXML());
       }

       public function 
    getFrame()
       {
           
    $unpacked unpack('Nlength'parent::read(self::OFFSET));
           
           
    //note: instead of three lines! Nice number2!  But I must return to three lines to properly comment.
           
    return new SimpleXMLElement(parent::read((int)$unpacked['length'] - self::OFFSET));
       }

    ComandosEpp.Class.php
    PHP Code:
    class ComandosEpp
    {
        protected 
    $_conexao;
        protected 
    $_xml;

        public function  
    __construct(ConexaoEpp $conexao$ficheiro)
        {
            list(
    $this->_connection$this->_xml) = array ($conexao, new SimpleXMLElement($ficheiro));
        }

        public function 
    executa()
        {
                
    $this->_conexao->sendFrame($this->_xml);
                return 
    $this->_connection->getFrame();
        }


    ComandoHello.Class.php

    PHP Code:
    require_once ('ComandosEpp.Class.php');

    class 
    ComandoHello extends ComandosEPP
    {
        public function  
    __construct(ConexaoEpp $conexao$ficheiro 'RepositorioXml/EppHello.xml')
        {
            
    parent::__construct($conexao$ficheiro);
        }

    EppHello.php
    PHP Code:
    require_once('Classes/ConexaoEpp.Class.php');
    require_once(
    'Classes/ComandoHello.Class.php');

    $conexao = new ConexaoEpp('ssl://example.com'3121);

    $comandoHello = new ComandoHello($conexao);

    $comandoHello->executa(); 
    When I run this last one, I'm getting:
    SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found
    I have certified that the XML is uploaded. But I've used a relative path. (like on the previous examples).

    I've changed to an absolute path just to be sure. No changes.

    I've var_dump $ficheiro and I'm getting the path. And this is the issue.

    string(57) "/public_html/DevRegistrar/RepositorioXml/EppHello.xml"

    I is expecting an XML, so:
    simplexml_load_file should be here somwhere...

    PHP Code:
    $xmlObj simplexml_load_file('RepositorioXml/EppHello.xml'); 
    So, we can put in on the Hello class, but maybe not, because, it's not Hello specific, is more command specific... or even more generic...

    On our ConexaoEpp.Class.php perhaps.

    But where? Before the frame is treated by the constructor? As a property?

  3. #28
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    One step at a time.

    Does your XML file contain white-space or a new line prior to the XML?

    SimpleXMLElement will load a file just fine, don't worry.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #29
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No white spaces or new lines on the xml.




    I've changed here.

    PHP Code:
    public function  __construct(ConexaoEpp $conexao$ficheiro)
        {
            
    $xmlObj simplexml_load_file($ficheiro);

            list(
    $this->_connection$this->_xml) = array ($conexao, new SimpleXMLElement($xmlObj));
        } 
    Getting:
    Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity
    :s

    But I will calm down... sort of...

  5. #30
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nop. My last try was just stupid. Passing an object inside a function that creates an object... bah!!

    I will wait for your advice.

  6. #31
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try this.
    PHP Code:
    class ComandosEpp
    {
        protected 
    $_conexao;
        protected 
    $_xml;

        public function  
    __construct(ConexaoEpp $conexao$ficheiro)
        {
          if(
    false === file_exists($ficheiro)){
            throw new 
    Exception($ficheiro ' does not exist!');
          }
          
          if(
    false === is_readable($ficheiro)){
            throw new 
    Exception($ficheiro ' is not readable!');
          }
          
          list(
    $this->_connection$this->_xml) = array ($conexao, new SimpleXMLElement($ficheiro));
        }

        public function 
    executa()
        {
                
    $this->_conexao->sendFrame($this->_xml);
                return 
    $this->_connection->getFrame();
        }

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #32
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It returns: doesn't exist.

    If I swear that, indeed, it exists on the given location? Does this count anything?

  8. #33
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oikram View Post
    If I swear that, indeed, it exists on the given location? Does this count anything?
    I will reply to myself: No.


    Ok. I've indeed found that path issue. (forgot to upload a file that contained that path updated. :s) Now the return is no longer that the "file doesn't exist".

    Actually, nothing is caught by the function I believe.

    But, now, after the warnings that I quoted earlier, I have below:
    Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML
    And the line of this Uncaught exception was:
    PHP Code:
    list($this->_connection$this->_xml) = array ($conexao, new SimpleXMLElement($ficheiro)); 
    Despite the fact that the function didn't provide the answers... it seems that this Uncaught exception did.

    So it must be related with the fact that we are using a path and we should use a binarypack containing the xml part only... ?

  9. #34
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    PHP Code:
    $connection = new EppConnection('example.org'1231);

    $command = new HelloCommand($connection);
    $command->execute();

    $command = new GetMeASandwichCommand($connection);
    $command->execute(); 
    Re-use the connection.
    Until now, I was thinking that, the better code we have, the better we will have a nice abstraction, a nice way to maintain and etc... but, also, on the "view" part of things, put them as simple as possible.... those were my thoughts.


    So let's say I have a function called Register domain (on my "view" part that will use this class and that, that function, will need 5 commands to run).

    I will need to, inside that function:
    require a 5 commandEspecific classes;
    Instanciate 5 specific classes;
    So we can have 5 commands to do, we have to include 5 files, one connection, instantiate 5 objects, and execute 5 times each of them.

    Isn't this to much? Don't take me wrong, you obviously deserve all my respect, I'm just asking. I've not seen enough code on my life... so I'm wondering.

  10. #35
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You have to do all this regardless, barring instantiating the objects to do it for you.

    Try it in procedural, as an exercise.

    M&#225;rcio, you need to start small and work your way up. You're having trouble resolving file paths, understanding how the objects are composed and seem determined to over complicate things.

    One of the benefits of OOP is that you can quite easily work on small sections of the application at a time, often without even knowing how any of the other components work.

    Use this to your advantage, build an object, test it, then build another that uses it.

    Anthony.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  11. #36
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't exercise any longer, this needs to be done, either well done, or more or less done. The question is, how do deal with this, knowing that it could be better, that we can do better, but we are just not allowed (by time, money whatever) to do so.

    I will give my best to simplify without been scruffy. (not sure if this last term is what I wanted to).


    Thanks for your time, and patience,
    M&#225;rcio


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •