cronus / cronus
It creates model classes by reading the database tables.
Installs: 8 624
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires (Dev)
README
Cronus
It reads the (MySQL/MariaDB) database table details for creating a simple model class.
This is it, nothing more.
That's a simple task, maybe you already use an IDE that creates the getters and setters for you, but even so, you still have to take a peek to the database table in order to know what attributes should be created.
That's what this package was created for! Everything you need to know is the database name and the table name. (user and password, of course!).
Let the Cronus work for you. Don't waste your time.
Installing
composer install cronus/cronus
Basic usage.
Sample:
$ ./vendor/bin/cronus --host localhost --user root --password 32130 --database MyDatabase --table user
It will create the following code:
<?php /** * Class description. * @copyright copy right here * @package package name * @subpackage subpackage name */ class User { private $id; private $name; private $email; private $createdAt; private $updatedAt; private $deleted; }
All the attributes are columns in the table.
As you can see, all the attributes are set as private
.
We can change the attributes visibility by using an argument called attributesVisibility
, which receives an int
value, that means... 0: private
1: protected
2: public
The attributesVisibility
value is 0
by default.
Sample:
$ ./vendor/bin/cronus --host 127.0.0.1 --user root --password admin --database MyDatabaseName --table user --attributesVisibility 2
And now we have all the attributes set as public
.
<?php /** * Class description. * @copyright copy right here * @package package name * @subpackage subpackage name */ class User { public $id; public $name; public $email; public $createdAt; public $updatedAt; public $deleted; }
Getters and setters
Nevertheless if you wish to have setters and getters for the attributes, it's possible to use the --setter
and --getter
arguments. (with no value).
Sample:
$ ./vendor/bin/cronus --host 127.0.0.1 --user root --password admin --database MyDatabaseName --table user --setter --getter
And the result is...
<?php /** * Class description. * @copyright copy right here * @package package name * @subpackage subpackage name */ class User { private $id; private $name; private $email; private $createdAt; private $updatedAt; private $deleted; public function getId() { return $this->id; } public function getName() { return $this->name; } public function getEmail() { return $this->email; } public function getCreatedAt() { return $this->createdAt; } public function getUpdatedAt() { return $this->updatedAt; } public function getDeleted() { return $this->deleted; } public function setId($id) { $this->id = $id; return $this; } public function setName($name) { $this->name = $name; return $this; } public function setEmail($email) { $this->email = $email; return $this; } public function setCreatedAt($createdAt) { $this->createdAt = $createdAt; return $this; } public function setUpdatedAt($updatedAt) { $this->updatedAt = $updatedAt; return $this; } public function setDeleted($deleted) { $this->deleted = $deleted; return $this; } }
By default, the class name is the same as the table name, but... if you wish, for some reason to create the class with another name, you can use the
--className
argument, which receives the class name (obviously).
Sample:
$ ./vendor/bin/cronus --host 127.0.0.1 --user root --password admin --database MyDatabaseName --table user --setter --getter --className AnotherName
Removing prefixes
Let's supose the table has some prefix (like a module prefix or something like that) and maybe the columns have a common prefix too.
Sample:
$ ./vendor/bin/cronus --host 127.0.0.1 --user root --password admin --database MyDatabaseName --table user --setter --getter --removePrefix adm
Here Cronus will remove all adm
from the begining of all attributes. (in case it exists.)
That's all :)
If you want to read the text help, you can run the --help
argument.
Sample:
$ ./vendor/bin/cronus --help