Jump to content

Mad_Griffith

Members
  • Posts

    146
  • Joined

  • Last visited

Posts posted by Mad_Griffith

  1. Hi I would like to mask `domain2.com/my-path/` with `domain2.com` (base URL).

    I have done the following and it works:

        location = / {
            proxy_pass http://domain2.com/my-path/;
        }

    But now I don't know how to bar the user from accessing `domain2.com/my-path/` directly or, from that address, redirect him to `domain2.com`, without influencing the solution above.

    Also, I am not fully convinced of using the `proxy_pass` directive, as I am using uWSGI and could maybe use `uwsgi_pass`, but something like the following throws an `invalid host in upstream` error:

        location = / {
            uwsgi_param QUERY_STRING $query_string;
            uwsgi_param REQUEST_METHOD $request_method;
            uwsgi_param CONTENT_TYPE $content_type;
            uwsgi_param CONTENT_LENGTH $content_length;
            uwsgi_param REQUEST_URI $request_uri;
            uwsgi_param PATH_INFO $document_uri;
            uwsgi_param DOCUMENT_ROOT $document_root;
            uwsgi_param SERVER_PROTOCOL $server_protocol;
            uwsgi_param REMOTE_ADDR $remote_addr;
            uwsgi_param REMOTE_PORT $remote_port;
            uwsgi_param SERVER_ADDR $server_addr;
            uwsgi_param SERVER_PORT $server_port;
            uwsgi_param SERVER_NAME $server_name;
            uwsgi_pass http://domain2.com/my-path/;
        }

     

  2. Thank you so much. I found this resource and I may need a mix of a Factory / FrontController kind of thing, although I am not too keen on abstracting the dispatcher. But the philosophy behind what I am trying to do quite matches the FrontController pattern.

  3. 10 hours ago, justsomeguy said:

    And why are you doing that from the superclass and not the child class?

    Because I want the Child class to be as clean as possible and somehow abstract that method's firing.

  4. I am doing it because I would like to have an entry point Class to control all the routing. I would still need to have modules such as Site inherit methods and properties from a superclass, though.

  5. This is a more faithful code. I need to instantiate Module only once because it can be extended for an indefinite number of times. I hope you can shed some light as I am currently stuck.

    <?php
    
    class Site extends Module {
    
        public function indexAction() {
            echo 'init\'ed!';
        }
    }
    
    class Module {
        public $name;
    
        public function getName() {
            return $this->name;
        }
    
        public function setName($name) {
            $this->name = $name;
        }
    
        public function getMethod() {
            return $this->method;
        }
    
        public function setMethod($method) {
            $this->method = $method;
        }
    
        public function init() {
            $this->setName('Site');
            $this->setMethod('indexAction');
    
            $moduleName = $this->getName();
            $methodName = $this->getMethod();
    
            $moduleInstance = new $moduleName();
            $moduleInstance->$methodName;
        }
    
        public function __construct() {
            $this->init();
        }
    }
    
    $Module = new Module();
  6. Hi, I am stuck in a conundrum.

    I have the following code:

    class Dad {
    
    	public function setup() {
    		// sets object and local vars
    	}
    
    	public function init() {
    		$sonInstance = new $sonName();
    		$sonInstance->$methodName();
    	}
    
    	public function __construct($sonName = null, $methodName = null) {
    		$this->setup($moduleName, $methodName);
    	}
    
    }
    
    class Son extends Dad {
    
    	public function doSomething() {
    
    	}
    
    }

    All this complication is needed because I need to have Dad() flexible enough to call Son() dynamically and be also able to inject the Son's class and method directly (please note that I omitted all the getters and setters on purpose from the code above).

    $Dad = new Dad();
    $Dad->init();
    $Son = new Dad('Son', 'doSomething');
    $Son->init();

    And I need Son extending Dad so that I can access Dad's methods within Son.

    But doing all this also makes Dad->setup() be called twice. How can I avoid this? What pattern suggestions do you have?

    Thank you.

  7. I just noticed I am in a conundrum. in firstMethod() I am also setting the value of a few SecondClass' variables that I want to be accessible in ThirdClass, but which of course is not set in ThirdClass if I either add the check in the SecondClass' constructor or override the constructor in ThirdClas. How do I overcome that?

    Thank you.

  8. uhm, I get your points. What do you think of this solution? firstMethod() is actually just a init function containing stuff that SecondClass won't share with any other class.

     

        public function __construct()
        {
            if (get_class($this) !== 'SecondClass') return;
    
            $this->firstMethod();
        }

     

  9. ThirdClass is something I would like to keep clean, if possible. I will put a check on the class in SecondClass' constructor.

    Anyway, thank you, I didn't know constructors are inherited.

  10. You're right, that's the issue. How can I avoid this in such a way that I am not forced to put an empty constructor in ThirdClass? Should I just use a check on the class in the SecondClass' constructor or is there a better solution? 

  11. Hi, I can't understand what I am doing wrong. It keeps on loading endlessly. Can you help out?

    I have one file with this:

    require_once 'path/to/firstclass';
    
    $Core = new FirstClass();

    Then in second file I have this:

    require_once 'SecondClass.php';
    
    class FirstClass {
    
    public function __construct() {
    	$SecondClass = new SecondClass();
    }
    
    }

    In a third file I have this:

    class SecondClass {
    
    public function __construct() {
    	require_once 'path/to/thirdclass';
    
    	$ThirdClass = new ThirdClass();
    	$ThirdClass->secondMethod();
    }
    
    public function firstMethod() {
    	echo 'my first method!';
    }
    
    }

    And in a fourth file I have this:

    class ThirdClass extends SecondClass {
    
    public function secondMethod() {
    	$this->firstMethod();
    }
    
    }

    Thank you.

  12. Like this?

    var complete = 0
    for (var i = 0; i < arr.length; i++) {
      $.post().then(handleResponse);
    }
    
    function handleResponse() {
      complete++;
    
      var images = { 'title1' : 'http://url-to-img-1', 'title2' : 'http://url-to-img-2', 'title3' : 'http://url-to-img-3' };
    
      var imagesAmount = Object.keys(images).length,
      imagesLoaded = 0;
      
      for (var img in images) {
        var imgObj = new Image();
        imgObj.src = images[img];
        imgObj.onload = function() { 
            imagesLoaded++
        };
      }
    
      if(complete === arr.length && imagesLoaded === imagesAmount - 1) {
        // Do something
      }
    }

     

  13. Thanks! Picking up on your solution: what if I have 3 post requests and I have to load 3 images per request and I want to be sure that the "Do something" part is reached only when the last request's last image is loaded?

    Would the following be correct?

     

    var complete = 0;
    for (var i = 0; i < arr.length; i++) {
      $.post().then(handleResponse);
    }
    
    function handleResponse() {
      complete++;
    
      var images = { 'title1' : 'http://url-to-img-1', 'title2' : 'http://url-to-img-2', 'title3' : 'http://url-to-img-3' };
    
      var imagesAmount = Object.keys(images).length;
      
      for (var img in images) {
        var imgObj = new Image();
        imgObj.src = images[img];
        img.onload = imagesLoaded++;
      }
    
      if(complete === arr.length && imagesLoaded === imagesAmount - 1) {
        // Do something
      }
    }

     

    Thanks

  14. Hi! I am starting to write my own MVC CMS just to learn about classes.

     

    One thing I do not understand is what is how in the MVC pattern a new class instance is generated in the controller and used in the view. Could you make an example with a Page class that would generate each page's body inside a static index.php?

     

    I'd just need a general example so that I can understand how to use instantiation properly in the context of page layouts and MVC.

     

    Thank you.

×
×
  • Create New...