Skip to content

A PHP Library to build classes from Database table using PDO

License

Notifications You must be signed in to change notification settings

jaimediaz817/Chrysalis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chrysalis

Chrysalis is a PHP Library create by @Pabhoz to generate classes from your project Data Model using PDO.

Getting Started

Chrysalis v1.0.0 just needs to be instanciated with a few parameters and then just be run. 🙌

Step 1. Clone Chrysalis into your project using:

~$ git clone https://github.com/pabhoz/Chrysalis/

Step 2. Require it!:

require "[path/to/libraries]/Chrysalis.php";

Step 3. Instanciate it!:

$chrysalis = new Chrysalis("localhost", "db_name", "db_user", "db_password");

Step 4. Abstract your database, so your tables will be loaded:

Now, you can do it sliently:

$chrysalis->abstractDb();

Or you can do it with a log:

$chrysalis->abstractDb(true);

Step 5. Abstract your database, so your tables will be loaded:

Now, you can do it sliently:

$chrysalis->abstractDb();

Or you can do it with a log:

$chrysalis->abstractDb(true);

Step 6. Generate them!:

You can generate de Model of an specific table by using generateClass method:

chrysalis->generateClass($chrysalis->tables[0],"../output/");

Or you can generate them all using generateAllClasses method and passing the output folder location:

$chrysalis->generateAllClasses("../output/");

Note: The output folder must have 777 permissions.

~$ sudo chmod 777 output

And thats all!

**Optional Customize them **. extend, constructors, methods, just add them all by passing additionalParams!:

//Custom Method to add to my generated classes
$additionalMethod = "    public function getMyVars(){\n        return "
        . "get_object_vars(".'$this'.");\n    }\n";
        
$chrysalis->generateAllClasses("../output/",["extends"=>"BModel", "parent_construct" => true,
    "additionalMethods"=>[$additionalMethod]]);

Current avialable Additional Params to Generate Classes:

extends = String; defines the class to extend by the generated class

parent_construct = boolean; true to use parent construct

additionalMethods = [String]; Array of functions as strings oyu want to add to generated class

Documentation is under development but for now you can check out the explanations videos: Chrysalis v1.0.0 Explanation Video (Spanish)! Chrysalis v1.0.0 Explanation video (English)! -> Comming soon.

About

A PHP Library to build classes from Database table using PDO

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%