Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php loading modules query 2

Status
Not open for further replies.
Yes, very likely in the App folder or config folder. the XML file may also need to have an entry added to it so it can find all the appropriate pieces.





----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Yes i sussed the xml out and I copied the selling section then renamed the tab, but soon as a added a new file name (like ie: test.phtml) file not found, i will have a look in app folder and config
 
Ok why this section on tek-tips isn't busy thought I would ask the question, what is bootstrap doing in this function?
Code:
    public function bootstrap()
    {
        if (!empty($this->_options['modules'])) {
            $this->_moduleManager = ModuleManager::getInstance()
                    ->setModules($this->_options['modules']);

            $this->setOptions(
                    $this->_moduleManager->getConfig(
                            $this->_moduleManager->getActiveModule()));

            $this->_autoloader->addPaths(
                    $this->_moduleManager->getPaths());
        }
        else {
            throw new \InvalidArgumentException('At least one module needs to be created in order for the application to function.');
        }

        $this->getBootstrap()->bootstrap();

        return $this;
    }

I'm pretty rusty coming back to programming, finished in 2005 but I never know such an enigma trying to follow this code

If I remember is the variable $this used within the object? I get this message after declaring some libraries

Fatal error: Using $this when not in object context - $stmt = $this->_adapter->query($query);

At some point the front page items should be called calling index.php but I'm trying to find where, this is the full code page of cube/application.php

Code:
namespace Cube;

use Cube\Loader\Autoloader;

class Application
{
    /**
     *
     * the name of the module bootstrap files
     */

    const BOOTSTRAP = 'Bootstrap';

    /**
     *
     * holds the configuration options array
     * 
     * @var array
     */
    protected $_options;

    /**
     * autoloader object
     *
     * @var \Cube\Loader\Autoloader
     */
    protected $_autoloader;

    /**
     *
     * requested module name
     * 
     * @var \Cube\ModuleManager
     */
    protected $_moduleManager;

    /**
     * 
     * bootstrap
     *
     * @var \Cube\Application\Bootstrap
     */
    protected $_bootstrap;

    /**
     * 
     * returns an instance of the object and creates it if it wasnt instantiated yet
     * 
     * @return \Cube\Application
     */
    private static $_instance;

    /**
     * 
     * class constructor
     * 
     * initialize autoloader
     * 
     * @param array $options     configuration array
     */
    protected function __construct($options = array())
    {
        require_once 'Debug.php';
        Debug::setTimeStart();
        Debug::setMemoryStart();
        Debug::setCpuUsageStart();

        require_once 'Loader/Autoloader.php';

        $this->_autoloader = Autoloader::getInstance()
                ->register();

        $this->setOptions($options);
    }

    /**
     * 
     * initialize application as singleton
     * 
     * @param array $options     configuration array
     * @return \Cube\Application
     */
    public static function init($options = array())
    {
        if (!self::$_instance instanceof self) {
            self::$_instance = new self($options);
        }

        return self::$_instance;
    }

    /**
     * 
     * returns an instance of the application object
     * 
     * @return \Cube\Application
     */
    public static function getInstance()
    {
        return self::$_instance;
    }

    /**
     * 
     * get options array
     * 
     * @return array
     */
    public function getOptions()
    {
        return $this->_options;
    }

    /**
     * 
     * set options array
     * 
     * @param array $options
     * @return \Cube\Application
     */
    public function setOptions(array $options)
    {
        if (!empty($this->_options)) {
            $this->_options = array_replace_recursive(
                array_merge_recursive($this->_options, $options), $options);
        }
        else {
            $this->_options = $options;
        }

        return $this;
    }

    /**
     * 
     * get a key from the options array 
     * 
     * @param string $key
     * @return mixed|null
     */
    public function getOption($key)
    {
        if (isset($this->_options[$key])) {
            return $this->_options[$key];
        }

        return null;
    }

    /**
     * 
     * set or unset a key in the options array
     * 
     * @param string $key
     * @param mixed|null $value
     * @return \Cube\Application
     */
    public function setOption($key, $value = null)
    {

        $this->_options[$key] = $value;

        return $this;
    }

    /**
     * get bootstrap object
     * we will first search for the requested module bootstrap and only if the file doesnt exist will we call the default bootstrap class from the library
     * the bootstrap class will only be created once
     *
     * @return \Cube\Application\Bootstrap
     */
    public function getBootstrap()
    {
        if (!($this->_bootstrap instanceof Application\Bootstrap)) {
            $bootstrap = $this->_moduleManager->getActiveModule() . '\\' . self::BOOTSTRAP;

            if (class_exists($bootstrap)) {
                $this->_bootstrap = new $bootstrap($this);
            }

            if ($this->_bootstrap === null) {
                $this->_bootstrap = new Application\Bootstrap($this);
            }
        }

        return $this->_bootstrap;
    }

    /**
     * initialize module manager and bootstrap application
     *
     * @throws \InvalidArgumentException
     * @return \Cube\Application
     */
    public function bootstrap()
    {
        if (!empty($this->_options['modules'])) {
            $this->_moduleManager = ModuleManager::getInstance()
                    ->setModules($this->_options['modules']);

            $this->setOptions(
                    $this->_moduleManager->getConfig(
                            $this->_moduleManager->getActiveModule()));

            $this->_autoloader->addPaths(
                    $this->_moduleManager->getPaths());
        }
        else {
            throw new \InvalidArgumentException('At least one module needs to be created in order for the application to function.');
        }

        $this->getBootstrap()->bootstrap();

        return $this;
    }

    /**
     * Run the application
     *
     * @return void
     */
    public function run()
    {
        
        $this->getBootstrap()->run();
    }

}
 
It's not "BootStrap" as in the javascript/CSS/HTML 'framework' usage, it is the 'bootstrapping' usage of being;

"Trying to pull yourself up by your boot straps (laces)" which is why 'booting' a computer is termed as such.

In your case "bootstrap()" is likely to be a method, the OOP term for a function, that 'kicks/boots' the application into an initial state then run() is the method that starts the main process(es)



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
I see, its very hard to follow, i have my own import code, all i need is the connection to db and execute methods but its ny on impossible to find. Even in the view folders wrapped in html with extension .phtml is the use of $this-> outside its class, there are no includes in any file so i'm baffled how this bloody project works, should i resort in pulling in my own PDo calls? that too me is reinventing the wheel if i already have it hidden somewhere, any particular searches i could use to find a connection?
 
After this call... where does this go? and if someone clicked a link that didnt run index.php how would it run bootstrap?

Code:
ini_set('display_errors', 1);
error_reporting(E_ALL);

define('APPLICATION_PATH', realpath(__DIR__));

set_include_path(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'library');

require_once 'Cube/Application.php';

$application = Cube\Application::init(include 'config/global.config.php');
$application->bootstrap()
        ->run();
 
aa__live said:
where does this go?
That depends entirely on what run() tells it to do.

aa__live said:
if someone clicked a link that didnt run index.php

index.php will ALWAYS run if the folder URI is requested, that's the reason for having a 'default document' for a folder so site.tld/folder/index.php does not have to be explicitly specified.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Looking at the above code i pasted "class Application" can you tell me off that?
 
aa__live said:
Looking at the above code i pasted "class Application" can you tell me off that?

Could you be a little less vague as to what you are asking????

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Sorry, this code, index runs the code below, where does it go from here, tiny lesson would be helpful, ive seen some php but this project is very difficult to follow
Code:
namespace Cube;

use Cube\Loader\Autoloader;

class Application
{
    /**
     *
     * the name of the module bootstrap files
     */

    const BOOTSTRAP = 'Bootstrap';

    /**
     *
     * holds the configuration options array
     * 
     * @var array
     */
    protected $_options;

    /**
     * autoloader object
     *
     * @var \Cube\Loader\Autoloader
     */
    protected $_autoloader;

    /**
     *
     * requested module name
     * 
     * @var \Cube\ModuleManager
     */
    protected $_moduleManager;

    /**
     * 
     * bootstrap
     *
     * @var \Cube\Application\Bootstrap
     */
    protected $_bootstrap;

    /**
     * 
     * returns an instance of the object and creates it if it wasnt instantiated yet
     * 
     * @return \Cube\Application
     */
    private static $_instance;

    /**
     * 
     * class constructor
     * 
     * initialize autoloader
     * 
     * @param array $options     configuration array
     */
    protected function __construct($options = array())
    {
        require_once 'Debug.php';
        Debug::setTimeStart();
        Debug::setMemoryStart();
        Debug::setCpuUsageStart();

        require_once 'Loader/Autoloader.php';

        $this->_autoloader = Autoloader::getInstance()
                ->register();

        $this->setOptions($options);
    }

    /**
     * 
     * initialize application as singleton
     * 
     * @param array $options     configuration array
     * @return \Cube\Application
     */
    public static function init($options = array())
    {
        if (!self::$_instance instanceof self) {
            self::$_instance = new self($options);
        }

        return self::$_instance;
    }

    /**
     * 
     * returns an instance of the application object
     * 
     * @return \Cube\Application
     */
    public static function getInstance()
    {
        return self::$_instance;
    }

    /**
     * 
     * get options array
     * 
     * @return array
     */
    public function getOptions()
    {
        return $this->_options;
    }

    /**
     * 
     * set options array
     * 
     * @param array $options
     * @return \Cube\Application
     */
    public function setOptions(array $options)
    {
        if (!empty($this->_options)) {
            $this->_options = array_replace_recursive(
                array_merge_recursive($this->_options, $options), $options);
        }
        else {
            $this->_options = $options;
        }

        return $this;
    }

    /**
     * 
     * get a key from the options array 
     * 
     * @param string $key
     * @return mixed|null
     */
    public function getOption($key)
    {
        if (isset($this->_options[$key])) {
            return $this->_options[$key];
        }

        return null;
    }

    /**
     * 
     * set or unset a key in the options array
     * 
     * @param string $key
     * @param mixed|null $value
     * @return \Cube\Application
     */
    public function setOption($key, $value = null)
    {

        $this->_options[$key] = $value;

        return $this;
    }

    /**
     * get bootstrap object
     * we will first search for the requested module bootstrap and only if the file doesnt exist will we call the default bootstrap class from the library
     * the bootstrap class will only be created once
     *
     * @return \Cube\Application\Bootstrap
     */
    public function getBootstrap()
    {
        if (!($this->_bootstrap instanceof Application\Bootstrap)) {
            $bootstrap = $this->_moduleManager->getActiveModule() . '\\' . self::BOOTSTRAP;

            if (class_exists($bootstrap)) {
                $this->_bootstrap = new $bootstrap($this);
            }

            if ($this->_bootstrap === null) {
                $this->_bootstrap = new Application\Bootstrap($this);
            }
        }

        return $this->_bootstrap;
    }

    /**
     * initialize module manager and bootstrap application
     *
     * @throws \InvalidArgumentException
     * @return \Cube\Application
     */
    public function bootstrap()
    {
        if (!empty($this->_options['modules'])) {
            $this->_moduleManager = ModuleManager::getInstance()
                    ->setModules($this->_options['modules']);

            $this->setOptions(
                    $this->_moduleManager->getConfig(
                            $this->_moduleManager->getActiveModule()));

            $this->_autoloader->addPaths(
                    $this->_moduleManager->getPaths());
        }
        else {
            throw new \InvalidArgumentException('At least one module needs to be created in order for the application to function.');
        }

        $this->getBootstrap()->bootstrap();

        return $this;
    }

    /**
     * Run the application
     *
     * @return void
     */
    public function run()
    {
        
        $this->getBootstrap()->run();
    }

}
 
could i ask, "this" is used everywhere, is "this"
Code:
$this->getBootstrap()->run();

equivalent too
Code:
$Application->getBootstrap()->run();

in the above code?
 
My problem is I have theme files extension .phtml using code within the file and no include classes at the top of the page and the use of the word $this in the file so I have no reference has to what object it is?

Fatal error: Using $this when not in object context

Code:
if ($this->userDetails($this->loggedInUser['id'])->getUser()->isVerified() === false) { 
	echo $this->partial('partials/user-verification-message.phtml', null); 
}

the file has no declaration to the object above this
 
aa__live said:
so I have no reference has to what object it is?

Correct.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
In this circumstance, is "view" a class somewhere?
Code:
$view->loggedInUser = $this->_user;
 
Its an object. It may or may not be an object instantiated from a defined class however.

The line is simply setting the loggedInUser Property of the $view object to whatever the current object's _user property is set to.








----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
I thought so, trouble is, I cannot find "loggedInUser" anywhere declared other than like the above, its not a function, it looks like part of an array, how could I search for it to see how its contructed
 
Probably because its not constructed anywhere else but there where its being set to _user.

Some class somewhere is setting or constructing _user however.

You could attempt to output _user using var_dump() function to see what else may be in there.

Code:
echo var_dump($this->_user);





----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
I will add to existing see what i can find, is there anyway of finding the class associated to "$this" at that point? "$this" is used all over this project with no real clue to what object it actually is, is that bad practice?
 
$this" is used all over this project with no real clue to what object it actually is, is that bad practice?

No, because '$this' is ONLY a valid object reference inside the object it it is referring to. So $this may be used many, many times in the code of an application which accesses or instantiates several classes, but it only ever has scope within the 'present' object, 'past' references, or 'future' instantiations of objects MUST be referenced by name.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
How can i follow for example this *.phtml file? there is no instantiation of a class but uses '$this' so how can i know what object this is? you can understand my conversion, when i used c++ years ago, the include to an object was added at the top of the page so you had some idea where to look

Code:
<!DOCTYPE html>

<html dir="<?php echo $htmlDir = $this->htmlDir(); ?>" lang="<?php echo $this->htmlLang(); ?>">
<head>
    <?php echo $this->headTitle(); ?>

    <?php
    $this->headMeta()
        ->appendName('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no')
        ->appendHttpEquiv('X-UA-Compatible', 'IE=edge');
    echo $this->headMeta();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top