Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving DBAL related configuration to ORM module, fixing tests bootstr…
…apper (still using Configuration instead of Config
- Loading branch information
Showing
11 changed files
with
627 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,94 @@ | |||
# Extra goodies included with DoctrineModule | |||
The items listed below are entirely optional and are intended to enhance integration between Zend Framework 2 and | |||
Doctrine 2 . | |||
|
|||
## ObjectExists and NoObjectExists Validators | |||
The ObjectExists and NoObjectExists are validators similar to Zend\Validator\Db validators. You can | |||
pass a variety of options to determine validity. The most basic use case requires an entity manager (em), | |||
an entity, and a field. You also have the option of specifying a query_builder Closure to use if you | |||
want to fine tune the results. | |||
|
|||
```php | |||
<?php | |||
$validator = new \DoctrineModule\Validator\NoObjectExists(array( | |||
// object repository to lookup | |||
'object_repository' => $serviceLocator->get('Doctrine\ORM\EntityManager')->getRepository('My\Entity\User'), | |||
|
|||
// fields to match | |||
'fields' => array('username'), | |||
)); | |||
|
|||
// following works also with simple values if the number of fields to be matched is 1 | |||
echo $validator->isValid(array('username' => 'test')) ? 'Valid' : 'Invalid! Duplicate found!'; | |||
``` | |||
|
|||
## Authentication adapter for Zend\Authentication | |||
The authentication adapter is intended to provide an adapter for `Zend\Authentication`. It works much | |||
like the `DbTable` adapter in the core framework. You must provide the entity manager instance, | |||
entity name, identity field, and credential field. You can optionally provide a callable method | |||
to perform hashing on the password prior to checking for validation. | |||
|
|||
```php | |||
<?php | |||
$adapter = new \DoctrineModule\Authentication\Adapter\DoctrineObject( | |||
$this->getLocator()->get('Doctrine\ORM\EntityManager'), | |||
'Application\Test\Entity', | |||
'username', // optional, default shown | |||
'password', // optional, default shown, | |||
function($identity, $credential) { // optional callable | |||
return \My\Service\User::hashCredential( | |||
$credential, | |||
$identity->getSalt(), | |||
$identity->getAlgorithm() | |||
); | |||
} | |||
); | |||
|
|||
$adapter->setIdentityValue('admin'); | |||
$adapter->setCredentialValue('pa55w0rd'); | |||
$result = $adapter->authenticate(); | |||
|
|||
echo $result->isValid() ? 'Authenticated!' : 'Could not authenticate'; | |||
``` | |||
|
|||
## Custom DBAL Types | |||
To register custom Doctrine DBAL types, simply add them to the `doctrine.configuration.my_dbal_default.types` | |||
key in you configuration file: | |||
|
|||
```php | |||
<?php | |||
return array( | |||
'doctrine' => array( | |||
'configuration' => array( | |||
'my_dbal_default' => array( | |||
'types' => array( | |||
// You can override a default type | |||
'date' => 'My\DBAL\Types\DateType', | |||
|
|||
// And set new ones | |||
'tinyint' => 'My\DBAL\Types\TinyIntType', | |||
), | |||
), | |||
), | |||
), | |||
); | |||
``` | |||
|
|||
You are now able to use them, for example, in your ORM entities: | |||
|
|||
```php | |||
<?php | |||
|
|||
class User | |||
{ | |||
/** | |||
* @ORM\Column(type="date") | |||
*/ | |||
protected $birthdate; | |||
|
|||
/** | |||
* @ORM\Column(type="tinyint") | |||
*/ | |||
protected $houses; | |||
} | |||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,104 @@ | |||
<?php | |||
/* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
* This software consists of voluntary contributions made by many individuals | |||
* and is licensed under the MIT license. For more information, see | |||
* <http://www.doctrine-project.org>. | |||
*/ | |||
|
|||
namespace DoctrineORMModule\Options; | |||
|
|||
use Zend\Stdlib\AbstractOptions; | |||
|
|||
/** | |||
* Configuration options for a DBAL Connection | |||
* | |||
* @license MIT | |||
* @link http://www.doctrine-project.org/ | |||
* @author Kyle Spraggs <theman@spiffyjr.me> | |||
*/ | |||
class DBALConfiguration extends AbstractOptions | |||
{ | |||
/** | |||
* Set the cache key for the result cache. Cache key | |||
* is assembled as "doctrine.cache.{key}" and pulled from | |||
* service locator. | |||
* | |||
* @var string | |||
*/ | |||
protected $resultCache = 'array'; | |||
|
|||
/** | |||
* Set the class name of the SQL Logger, or null, to disable. | |||
* | |||
* @var string | |||
*/ | |||
protected $sqlLogger = null; | |||
|
|||
/** | |||
* Keys must be the name of the type identifier and value is | |||
* the class name of the Type | |||
* | |||
* @var array | |||
*/ | |||
protected $types = array(); | |||
|
|||
/** | |||
* @param string $resultCache | |||
*/ | |||
public function setResultCache($resultCache) | |||
{ | |||
$this->resultCache = $resultCache; | |||
} | |||
|
|||
/** | |||
* @return string | |||
*/ | |||
public function getResultCache() | |||
{ | |||
return 'doctrine.cache.' . $this->resultCache; | |||
} | |||
|
|||
/** | |||
* @param string $sqlLogger | |||
*/ | |||
public function setSqlLogger($sqlLogger) | |||
{ | |||
$this->sqlLogger = $sqlLogger; | |||
} | |||
|
|||
/** | |||
* @return string | |||
*/ | |||
public function getSqlLogger() | |||
{ | |||
return $this->sqlLogger; | |||
} | |||
|
|||
/** | |||
* @param array $types | |||
*/ | |||
public function setTypes(array $types) | |||
{ | |||
$this->types = $types; | |||
} | |||
|
|||
/** | |||
* @return string | |||
*/ | |||
public function getTypes() | |||
{ | |||
return $this->types; | |||
} | |||
} |
Oops, something went wrong.