简体   繁体   中英

Generate PHP class from bash script

I am new to Shell script. I am writing a shell script to generate a php class. I have successfully generated a class from that script but the problem is that I am unable to declare php variables in that class. For example:

#!/bin/bash

# Make root class
echo "Adding Root class..."
cat > Example.php << EOF
<?php 
require_once (dirname(__FILE__)) . '/../CmlmAPICore.php';

class $1 extends PHPUnit_Framework_TestCase {

    public $coreAPI;
    public $globalPath;
    public $path;
    protected function setUp() {
        $this->coreAPI = new CmlmAPICore();
        $this->globalPath = $GLOBALS['DATA_FOLDER'];
}
}

These variables are not being shown in the class generated. Everything else is showing fine. Generated class is:

<?php 
require_once (dirname(__FILE__)) . '/../CmlmAPICore.php';
class Audios extends PHPUnit_Framework_TestCase {

   public ;
    public ;
    public ;

    protected function setUp() {
        ->coreAPI = new CmlmAPICore();
        ->globalPath = ['DATA_FOLDER'];
}
}

=> $1 is the parameter I pass as class name when i run shell script.

I guess it is not identifying "$" sign in this. Is there any way to do so?

add '\\' before '$'

public \$coreAPI;
public \$globalPath;
public \$path;
protected function setUp() {
    \$this->coreAPI = new CmlmAPICore();
    \$this->globalPath = \$GLOBALS['DATA_FOLDER'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM