ansas/propel-helper

Propel helper - helper classes (traits) for Propel2 ORM

1.4.0 2019-06-29 15:40 UTC

This package is auto-updated.

Last update: 2024-11-06 13:37:50 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Helper classes (traits) for Propel2 ORM.

Ansas\Propel\Helper\ReadOnly

This trait is a workaround for the Propel bug that you cannot use joinWith() methods anymore when setting tables to readOnly="true" in Propel's schema.xml file. So instead of making tables "readonly" in the scheme just add this trait to every child model you want to make readonly.

For details see propelorm/Propel2#629

Example usage:

<?php

use Base\User as BaseUser;
use Ansas\Propel\Helper\ReadOnly;

class User extends BaseUser
{
    use ReadOnly;
}

Ansas\Propel\Helper\SimpleVersionableBehavior

The default behavior "versionable" does not seem to work well with relations and in combination with other behaviors. Therefore I wrote a "simple trait" that does NOT consider versions of related tables. All methods can be used as before.

Three things have to be implemented to use this trait:

  1. Use the trait in the desired class
  2. Add the following constant with the name of the versionable behavior active records class (e. g. for an 'Account')
  3. Optionally add the constant for column names (in default PhpName notation) to skip when populating object

Example usage:

<?php

use Base\User as BaseUser;
use Ansas\Propel\Helper\SimpleVersionableBehavior;

class User extends BaseUser
{
    use SimpleVersionableBehavior;

    /**
     * Class name for versionable behavior active records
     */
    const VERSIONABLE_CLASS = 'UserVersion';

    /**
     * Column names (in default PhpName notation) to skip when populating this with version entry
     */
    const VERSIONABLE_POPULATE_SKIP_COLUMNS = ['UpdatedAt', 'Version'];
}

Ansas\Propel\Helper\Validation

This trait makes validation of an object quite easy.

Methods:

protected function addValidationError($key, $value, $overwrite = true)
protected function resetValidation()
public function getValidationErrors()
public function hasValidationErrors()
abstract protected function doValidate();

TODO

  • Write tests

Contribute

Everybody can contribute to this package. Just:

  1. fork it,
  2. make your changes and
  3. send a pull request.

Please make sure to follow PSR-1 and PSR-2 coding conventions.

License

MIT license (see the LICENSE file for more information).