Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong ROOTPATH on console #460

Closed
eddmash opened this issue Apr 5, 2017 · 6 comments
Closed

Wrong ROOTPATH on console #460

eddmash opened this issue Apr 5, 2017 · 6 comments

Comments

@eddmash
Copy link
Contributor

eddmash commented Apr 5, 2017

The ROOTPATH on console is wrong which has the effect composer autoloader is never required.

If i create a command at application/Commands/Powerorm.php

namespace App\Commands;

use CodeIgniter\CLI\BaseCommand; 

class Powerorm extends BaseCommand
{
    protected $group = 'Powerorm';
    protected $name  = 'powerorm';
    protected $description = 'Displays powerorm commands.';


    public function run(array $params)
    {
        var_dump(realpath(ROOTPATH));
    }
}

The output i get is /opt/lampp/htdocs/ci4/public where instead of /opt/lampp/htdocs/ci4 which is what i get when i run

var_dump(realpath(ROOTPATH));

On the view.

This also has the side effect of, i am not able to use packages on the vendor folder in my command. since composer autloader is never required on the system/bootstrap.php

e.g. if i try the dump() method found on symfony/var-dumper which is already on my vendor.

Type:        Error
Message:     Call to undefined function App\Commands\dump()
Filename:    /opt/lampp/htdocs/ci4/application/Commands/Powerorm.php
Line Number: 27
@lonnieezell
Copy link
Member

There, I think that should fix it, but let me know if it's still not working for you.

@eddmash
Copy link
Contributor Author

eddmash commented Apr 11, 2017

No its no working actually the whole console is broken, this could be the problem

at https://github.com/bcit-ci/CodeIgniter4/blob/develop/ci.php#L17 the variabale $paths is being used before declaration which happens at line https://github.com/bcit-ci/CodeIgniter4/blob/develop/ci.php#L42

@eddmash
Copy link
Contributor Author

eddmash commented Apr 11, 2017

Reorganizing my code to look as below seems to have worked for me fixing both issues


#!/usr/bin/env php
<?php

/*
 * --------------------------------------------------------------------
 * CodeIgniter command-line tools
 * --------------------------------------------------------------------
 * The main entry point into the CLI system and allows you to run
 * commands and perform maintenance on your application.
 *
 * Because CodeIgniter can handle CLI requests as just another web request
 * this class mainly acts as a passthru to the framework itself.
 */

/*
 *---------------------------------------------------------------
 * BOOTSTRAP THE APPLICATION
 *---------------------------------------------------------------
 * This process sets up the path constants, loads and registers
 * our autoloader, along with Composer's, loads our constants
 * and fires up an environment-specific bootstrapping.
 */

// Refuse to run when called from php-cgi
if (substr(php_sapi_name(), 0, 3) == 'cgi') {
    die("The cli tool is not supported when running php-cgi. It needs php-cli to function!\n\n");
}

// Location to the Paths config file.
$pathsPath = 'application/Config/Paths.php';


// Load our paths config file
require $pathsPath;

$paths = new Config\Paths();

$public = trim($paths->publicDirectory, '/');

// Path to the front controller
define('FCPATH', realpath($public) . DIRECTORY_SEPARATOR);

// Ensure the current directory is pointing to the front controller's directory
chdir('public');

$app = require rtrim($paths->systemDirectory, '/ ') . '/bootstrap.php';

// Grab our Console
$console = new \CodeIgniter\CLI\Console($app);

// We want errors to be shown when using it from the CLI.
error_reporting(-1);
ini_set('display_errors', 1);

// Show basic information before we do anything else.
$console->showHeader();

// fire off the command the main framework.
$console->run();

@lonnieezell
Copy link
Member

What do you mean when you say "the Console is broken"? Using the latest version of the code I'm able to list the commands, etc. Seems to be working correctly for me. What are you seeing?

@eddmash
Copy link
Contributor Author

eddmash commented Apr 12, 2017

Yes the listing is working but if you try to run any of those commands you get the following warnings

PHP Notice:  Undefined variable: paths in /var/www/public/ci4/ci.php on line 33
PHP Stack trace:
PHP   1. {main}() /var/www/public/ci4/ci.php:0
PHP Notice:  Trying to get property of non-object in /var/www/public/ci4/ci.php on line 33
PHP Stack trace:
PHP   1. {main}() /var/www/public/ci4/ci.php:0

as a result of this warning, the original issue was not fixed. and the reorganization of ci,php above worked for me.

i'm working with the latest version.

@lonnieezell
Copy link
Member

Strange. I don't think I was seeing that error.

However, the latest version (1765d0d) has the reordering you placed here. It was just committed a day or so ago, so please pull down the latest version and see if that fixes it for you. If not, submitting a working PR would probably be the simplest fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants