Judging teacher PHP Devil Special Training Note (7)--what's my name?

Source: Internet
Author: User
Tags stdin

first, generate the Folder.

mkdir ();--new Directory
$context]])
Try creating a new directory that is specified by Pathname.

  Parameters: pathname: The path to the Directory.

  mode:The default mode is 0777, which means the maximum possible access Rights. For more information on mode, please read the chmod () page.

See the above function? Remember Last lesson Shen Teacher left a homework, read the God.json file, generate a simplest "skeleton". 1, accept the parameter Start. 2. Generate a folder based on the value of Prj_name. 3. A index.php is generated by default in the newly created Folder.

OK, Let's start with the first step and write a method in the Godinit File.

Static function start () {        $get _config = loadconfig ();         mkdir (getcwd(). " /". $get _config-prj_name);    }

Then./god start, in my file path, a project folder is Generated. Of course, This is a course demonstration, we also need to determine whether the folder is already present, not exist to create, if there is not created.

Improve the start () method:

Static function start () {        $get _config = loadconfig ();        ! file_exists (getcwd(). " /". $get _config mkdir (getcwd(). " /". $get _config-prj_name);    }

 a function appears above: file_exists ();--check whether a file or directory Exists. Let's strengthen it again:

file_exists string $filename )// Check whether the file or directory Exists. 

Parameters: filename The path to the file or Directory.

return value: if the the specified file or directory exists and is returned Otherwise. filename TRUE FALSE

Let's go back to the course and generate a PHP file:

Static functionstart () {$get _config=Loadconfig (); //determine and generate a new folder, without creating!file_exists(GETCWD()." /".$get _config->prj_name) &&mkdir(GETCWD()." /".$get _config-prj_name); //under this folder to determine and generate a index.php file, do not create!file_exists(GETCWD()." /".$get _config->prj_name. " /index.php ") &&file_put_contents(GETCWD()." /".$get _config->prj_name. " /index.php "," "); }

  OK, the homework for the last lesson is Completed.

the main content of this lesson, create a new god_frame.php, write a class that specializes in dealing with Skeletons.

Since God is used to make "skeletons". Then we need to set up a constructor, pre-1, the skeleton of the folder name, 2, The skeleton of the entry file Reservation. Then we'll create a folder core that represents the god kernel, create a subfolder underneath it called frame, and then create a folder under the frame called template, and finally, plug the god_frame.php into the Frame.

Before we write the code, we also need to strengthen a magic function:

__autoload ();-- try to load an undefined class

string $class )// You can enable automatic loading of classes by defining this Function. 

  Parameters: class-- class name to load

// example//attempt to load an undefined class, if an undefined class is loaded, it will automatically enter this function (if you write It) function __autoload ($classname// receive a parameter {     echo$ ClassName, which can be found, takes the class name of the class you are trying to load to}

  And then we're going to look at the namespace namespace Today. Then import the namespace with Use.

okay, Let's take a look at the code I finished with this lesson: god_frame.php

<?phpnamespace core\frame;classgod_frame{ public  $project _folder= ";//project Folder     public  $project _main= ";//Entry File    function__construct ($prjName){//constructor Function       $this->project_folder =GETCWD()." /".$prjName; $this->project_main =$thisProject_folder. " /index.php "; }    functionRun () {//determine and generate a new folder, without creating!file_exists($this->project_folder) &&mkdir($this-project_folder); //under this folder to determine and generate a index.php file, do not create!file_exists($this->project_main) &&file_put_contents($this->project_main, ""); }}?>
//Godinit<?PHPDefine(' CString ', ' json ');require(' godconfig.php ');//introduce gonconfig this file usecore\frame;function__autoload ($className){    $className=Str_replace(‘\\‘,‘/‘,$className).‘. Php; require($className);}classGodinit//Create a class, godinit{    Static  $v= "god version is 1.2";//declares a static property $version    Static functionInit ()//static method Init    {        Echo"input your project name?".Php_eol; $prj _name=fgets(STDIN);//Re-fetch user input and assign value to $prj_name                Echo"input your author name?".Php_eol; $prj _author=fgets(STDIN);//Re-fetch user input and assign value to $prj_authorGenconfig (TC (Array(' Prj_name ' =$prj _name, ' prj_author ' =$prj _author))); }    functionINI () {$get _config=Loadconfig (); foreach($get _config  as $k=$v)            Echo $k.":".$v; }    Static functionstart () {$get _config=Loadconfig (); $GF=NewGod_frame ($get _config-prj_name); $GF-Run (); }/*static function Make () {$pchar =new Phar ("god.phar");        $pchar->buildfromdirectory (dirname (__file__));        $pchar->setstub ($pchar->createdefaultstub (' God '));    $pchar->compressfiles (phar::gz); }*/    Static function__callstatic ($p 1,$p 2){        Echo"error function"; }}?>

copyright notice: Note-taker Fugitive Pawns Love freedom, advocating sharing. But this note stems from www.jtthink.com (programmer in the awkward way) judging teacher's "php Devil training First stage." This study note pawn in the blog Park debut, if need to reprint please respect the teacher labor, retain judging teacher attribution and course source Address.

previous Lesson: Judging teacher PHP Devil Special Training Note (6)--witchcraft and skeleton

Judging teacher PHP Devil Special Training Note (7)--what's my name?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.