sfDoctrineActAsSerializablePlugin
1.0.0stable
for sf 1.4 and Doctrine
MIT
The sfDoctrineActAsSerializablePlugin plugin automates the handling of
serializable columns. Each time a Serializable object is read from
the database, the appropriate columns are unserialized, each time it is
saved - the column values are seralized back.
Developers
| Name |
Status |
Email |
Tomasz Ducin |
lead |
moc.liamg <<ta>> nicud.zsamot
|
License
Copyright (c) 2012 Tomasz Ducin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfDoctrineActAsSerializablePlugin
The sfDoctrineActAsSerializablePlugin plugin automates the handling of
serializable columns. Each time a Serializable object is read from
the database, the appropriate columns are unserialized, each time it is
saved - the column values are seralized back.
Instalation
Install the plugin via the subversion repository by executing the following
command from the project root directory:
$ svn co http://svn.symfony-project.com/plugins/sfDoctrineActAsSerializablePlugin/trunk plugins/sfDoctrineActAsSerializablePlugin
or by using the default symfony plugin install command:
$ ./symfony plugin:install sfDoctrineActAsSerializablePlugin
Usage
You don't have to worry about (un)serializing data when reading the data from
and saving it to the database. Everything will be done automatically from now
on. It's extremely useful when you want to keep array values in the database.
# Using global behavior will make no changes.
Xxx:
actAs:
Serializable:
fields: [ features, attributes ]
column_suffix: _srlzd
Set the fields that are going to be serializable. Doctrine will create new
columns with their names concatenated with the column_suffix. In the above
example, the Xxx model woud have features_srlzd and attributes_srlzd
columns.
no postConstruct
The problem with Doctrine is that there can be no postConstuct hook called after
a new record is created. The topic
was started in 2009 and there has been no solution for the 1.x Doctrine branch
yet. Hence, the hook had to be done in a different way, unfortunately. Each
model that uses the Serializable behavior should have the construct method
implemented with one extra line, just as below:
[php]
class Xxx extends BaseXxx
{
public function construct()
{
parent::construct();
Doctrine_Auxiliary_Tools::postConstruct($this);
}
}
The postConstruct method creates empty values for the serializable columns.
todo
Thanks to
Miko Väli, who was looking for the same Doctrine feature as I was and whose
question in the google groups made it clear that I have to overcome the problem
myself.
Comments, bug reports, suggestions
If you want to comment on the plugin or suggest your ideas, please feel free to
mail me.