Commit 67807d29 authored by Patrick Barroca's avatar Patrick Barroca 🐧

more php highlighting

parent 1a97b3cd
Pipeline #4093 passed with stage
in 7 seconds
......@@ -23,7 +23,7 @@ The main classes are:
A simple persistent model can be declared like:
```
```php
class Newsletter extends Storm_Model_Abstract {
protected $_table_name = 'newsletters';
}
......@@ -34,7 +34,7 @@ class Newsletter extends Storm_Model_Abstract {
By default, table primary is supposed to be an autoincrement field named 'id'.
If your primary is not named 'id' you must define $_table_primary like:
```
```php
class Datas extends Storm_Model_Abstract {
protected $_table_name = 'datas';
protected $_table_primary = 'id_data';
......@@ -43,7 +43,7 @@ class Datas extends Storm_Model_Abstract {
If your primary is not autoincremented, you must set $_fixed_id as true.
Suppose you want to handle a value list with a textual primary key, like in :
```
```php
class Datas extends Storm_Model_Abstract {
protected $_table_name = 'datas';
protected $_table_primary = 'data_code';
......@@ -53,7 +53,7 @@ class Datas extends Storm_Model_Abstract {
Storm will not ask last insert id from persistence strategy upon insert but use the provided value.
```
```php
$data = Datas::newInstance()
->setDataCode('MY_CODE')
->setDataValue('any value');
......@@ -68,12 +68,12 @@ A Storm_Model_Loader is automatically generated for the model via Storm_Model_Ab
Storm_Model_Loader can load the instance from the database:
* return a list of all Newsletter objects in db:
```
```php
$all_newsletters = Newsletter::getLoader()->findAll();
```
* return the Newsletter object with id 5 in db
```
```php
$my_newsletter = Newsletter::getLoader()->find(5);
```
......@@ -81,7 +81,7 @@ Note that if you call find with the same id twice, only one db request will be s
As Storm_Model_Abstract implements *__callStatic*, you can write above lines:
```
```php
$all_newsletters = Newsletter::findAll();
$my_newsletter = Newsletter::find(5);
```
......@@ -98,7 +98,7 @@ and on Storm_Model_Loader save, load, delete instances.
For example, the db table newsletters has 3 fields id, title, content. With previous declaration, you get for free:
```
```php
$animation = Newsletter::find(5);
echo $animation->getId();
echo $animation->getTitle();
......@@ -165,7 +165,7 @@ So we have this DSL:
* Newsletter **has_many** NewsletterSubscription.
* NewsletterSubscription **belongs_to** Newsletter.
```
```php
class NewsletterSubscription extends Storm_Model_Abstract {
protected $_table_name = 'newsletters_users';
protected $_belongs_to = ['user' => ['model' => 'Users'],
......@@ -177,7 +177,7 @@ There can be several *belongs_to* associations, so it's an array.
The key *newsletter* is used by Storm_Model_Abstract to understand the following messages:
```
```php
$subscription = NewsletterSubscription::find(2);
$newsletter = $subscription->getNewsletter();
$user = $subscription->getUser();
......@@ -191,7 +191,7 @@ $subscription
Note that the newsletter_user table must contain the fields: id, user_id, newsletter_id.
```
```php
class Newsletter extends Storm_Model_Abstract {
protected $_table_name = 'newsletters';
protected $_has_many = ['subscriptions' => ['model' => 'NewsletterSubscription',
......@@ -231,7 +231,7 @@ Other options include:
You need to use the option 'through' :
```
```php
class Newsletter extends Storm_Model_Abstract {
protected $_table_name = 'newsletters';
protected $_has_many = ['subscriptions' => ['model' => 'NewsletterSubscription',
......@@ -257,7 +257,7 @@ NewsletterSubscription object will be automatically created.
For users:
```
```php
class User extends Storm_Model_Abstract {
protected $_table_name = 'bib_admin_users';
protected $_table_primary = 'ID_USER';
......@@ -402,7 +402,7 @@ class Profil extends Storm_Model_Abstract {
Use field *$_default_attribute_values* to specify default attribute values:
```
```php
class User extends Storm_Model_Abstract {
protected $_table_name = 'users';
protected $_default_attribute_values = ['login' => 'foo',
......@@ -427,7 +427,7 @@ echo $foo->getName();
A Storm_Model_Abstract subclass can override `validate` to check its data before validation. If an error is reported, no data will be sent to database
```
```php
class User extends Storm_Model_Abstract {
protected $_table_name = 'users';
protected $_default_attribute_values = ['login' => '',
......@@ -459,7 +459,7 @@ echo implode("\n", $foo->getErrors());
Hooks can be executed before and after saving, before and after delete
```
```php
class User extends Storm_Model_Abstract {
public function beforeSave() {
echo "before save\n";
......@@ -500,7 +500,7 @@ The easiest way to write unit tests on data is to use *Storm_Model_Abstract::fix
A real example worth a thousand words:
```
```php
class Storm_Test_VolatileUser extends Storm_Model_Abstract {
protected $_table_primary = 'id_user';
}
......@@ -678,7 +678,7 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase {
Storm's ObjectWrapper is used for *partial mocking* (by default). Imagine you have this class:
```
```php
class Foo {
public function doRealStuff() {
return 'some real stuff';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment