ruckuus / php-activerecord-service-provider
A PHPActiveRecord Service Provider for Silex
Installs: 2 927
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: >=5.3.0
- php-activerecord/php-activerecord: ~1.1.1
- silex/silex: ~1.0
This package is not auto-updated.
Last update: 2025-03-01 17:12:50 UTC
README
A PHP ActiveRecord ServiceProvider for Silex.
History
I was about to use [Available ActiveRecord Extension] (https://github.com/RafalFilipek/ActiveRecordExtension/blob/master/ActiveRecordExtension.php), but then I realised that registerNamespace() is deprecated in later version of Silex. This work is experimental, it has a minimum functionality to "work".
Fetch
The recommended way to install ActiveRecordServiceProvider is through composer.
Just create a composer.json file for your project:
{ "require": { "ruckuus/php-activerecord-service-provider": "dev-master", "silex/silex": "1.0.*@dev" } }
Parameters
- ar.model_dir - Path to where model folder is located ( without trailing slash )
- ar.connections - Array of connections (
name => connection
). Connections examples:mysql://username:password@localhost/database_name
pgsql://username:password@localhost/development
sqlite://my_database.db
oci://username:passsword@localhost/xe
- ar.default_connection - default models connection.
Register
use Silex\Application; use Ruckuus\Silex\ActiveRecordServiceProvider; $app = new Application(); $app->register(new ActiveRecordServiceProvider(), array( 'ar.model_dir' => __DIR__ . '/App/Model', 'ar.connections' => array ('development' => 'mysql://root@localhost/database_name'), 'ar.default_connection' => 'development', ));
Usage
Create your model in __DIR__ . '/app/Model'
. Eg.
namespace App\Model; class User extends \ActiveRecord\Model { static $has_many = array ( array('problem'), array('luck') ) }
In your application:
use App\Model\User; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; class UserProvider implements UserProviderInterface { public function loadUserByUsername($username) { $user = User::find_by_username(strtolower($username)); if ($user->dirty_attributes()) { throw new UnsupportedUserException(sprintf('Bad credentials for "%s"'), $username); } } }
For more informations check the website of PHP ActiveRecord. Its wiki.