Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0daa5fa
Remove require_once from inside functions
andyleap May 29, 2013
16b1df3
remove all carriage returns <CR>
koenpunt Jul 17, 2014
93963b4
normalize file endings
koenpunt Jul 17, 2014
1fa8918
Added option for multiple model directories
koenpunt Jun 27, 2012
47a14ee
Added tests
koenpunt Apr 20, 2013
050e323
Adding custom support for boolean casting based on connection
leightonshank Nov 8, 2012
f43ff78
Updated ColumnTest for new BOOLEAN type cast
leightonshank Nov 8, 2012
f3ba6e5
fixed indentation formatting to match existing code
leightonshank Apr 30, 2013
ac50389
Updated tests for boolean value casting
leightonshank Apr 30, 2013
5ec71ee
Updated PgsqlAdapter boolean_to_string() for Postgres boolean values
leightonshank Apr 30, 2013
5969bd4
Shortened the false condition in PgsqlAdapter::boolean_to_string()
leightonshank May 1, 2013
9780dfc
Added some newlines for readability.
Jul 21, 2012
09abed8
Implemented 'on' option for validations.
Jul 21, 2012
39c17ee
Added tests for on create/update/save
koenpunt Sep 25, 2012
a8526e6
Only flag attributes as dirty if the value changes
leightonshank Jul 10, 2013
2d334d3
Added tracking of changed attributes
leightonshank Jul 10, 2013
4947136
Fix handling of changed DateTime attributes
leightonshank Jul 11, 2013
79ea463
Fix so that empty attributes still track a change
leightonshank Jul 19, 2013
53d0f48
Fix PgsqlAdapter native types, default values.
Jun 13, 2013
838b316
Updates to allow for easy access/serialization of virtual attributes
leightonshank Nov 15, 2012
c52836f
unit test for ActiveRecord\Serialization update
leightonshank Nov 15, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 56 additions & 49 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
<?php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
die('PHP ActiveRecord requires PHP 5.3 or higher');

define('PHP_ACTIVERECORD_VERSION_ID','1.0');

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND',true);

require __DIR__.'/lib/Singleton.php';
require __DIR__.'/lib/Config.php';
require __DIR__.'/lib/Utils.php';
require __DIR__.'/lib/DateTime.php';
require __DIR__.'/lib/Model.php';
require __DIR__.'/lib/Table.php';
require __DIR__.'/lib/ConnectionManager.php';
require __DIR__.'/lib/Connection.php';
require __DIR__.'/lib/Serialization.php';
require __DIR__.'/lib/SQLBuilder.php';
require __DIR__.'/lib/Reflections.php';
require __DIR__.'/lib/Inflector.php';
require __DIR__.'/lib/CallBack.php';
require __DIR__.'/lib/Exceptions.php';
require __DIR__.'/lib/Cache.php';

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
spl_autoload_register('activerecord_autoload',false,PHP_ACTIVERECORD_AUTOLOAD_PREPEND);

function activerecord_autoload($class_name)
{
$path = ActiveRecord\Config::instance()->get_model_directory();
$root = realpath(isset($path) ? $path : '.');

if (($namespaces = ActiveRecord\get_namespaces($class_name)))
{
$class_name = array_pop($namespaces);
$directories = array();

foreach ($namespaces as $directory)
$directories[] = $directory;

$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
}

$file = "$root/$class_name.php";

if (file_exists($file))
require_once $file;
}
<?php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
die('PHP ActiveRecord requires PHP 5.3 or higher');

define('PHP_ACTIVERECORD_VERSION_ID','1.0');

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND',true);

require __DIR__.'/lib/Singleton.php';
require __DIR__.'/lib/Config.php';
require __DIR__.'/lib/Utils.php';
require __DIR__.'/lib/DateTime.php';
require __DIR__.'/lib/Model.php';
require __DIR__.'/lib/Table.php';
require __DIR__.'/lib/ConnectionManager.php';
require __DIR__.'/lib/Connection.php';
require __DIR__.'/lib/Serialization.php';
require __DIR__.'/lib/SQLBuilder.php';
require __DIR__.'/lib/Reflections.php';
require __DIR__.'/lib/Inflector.php';
require __DIR__.'/lib/CallBack.php';
require __DIR__.'/lib/Exceptions.php';
require __DIR__.'/lib/Cache.php';

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
spl_autoload_register('activerecord_autoload',false,PHP_ACTIVERECORD_AUTOLOAD_PREPEND);

function activerecord_autoload($class_name)
{
$paths = ActiveRecord\Config::instance()->get_model_directories();
$namespace_directory = '';
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
{
$class_name = array_pop($namespaces);
$directories = array();

foreach ($namespaces as $directory)
$directories[] = $directory;

$namespace_directory = DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
}
$paths = count($paths) ? $paths : array('.');

foreach($paths as $path)
{
$root = realpath($path);
$file = "{$root}{$namespace_directory}/{$class_name}.php";

if (file_exists($file))
{
require $file;
return;
}
}
}
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Of course, there are some differences which will be obvious to the user if they

Setup is very easy and straight-forward. There are essentially only three configuration points you must concern yourself with:

1. Setting the model auto_load directory.
1. Setting the model auto_load directory/directories.
2. Configuring your database connections.
3. Setting the database connection to use for your environment.

Expand All @@ -63,14 +63,17 @@ Example:
```php
ActiveRecord\Config::initialize(function($cfg)
{
$cfg->set_model_directory('/path/to/your/model_directory');
$cfg->set_connections(
array(
'development' => 'mysql://username:password@localhost/development_database_name',
'test' => 'mysql://username:password@localhost/test_database_name',
'production' => 'mysql://username:password@localhost/production_database_name'
)
);
$cfg->set_model_directories(array(
'/path/to/your/model_directory',
'/some/other/path/to/your/model_directory'
));
$cfg->set_connections(
array(
'development' => 'mysql://username:password@localhost/development_database_name',
'test' => 'mysql://username:password@localhost/test_database_name',
'production' => 'mysql://username:password@localhost/production_database_name'
)
);
});
```

Expand Down
1 change: 0 additions & 1 deletion examples/orders/models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ public function apply_tax()
$this->tax = $this->price * $tax;
}
}
?>
1 change: 0 additions & 1 deletion examples/orders/models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ class Payment extends ActiveRecord\Model
array('person'),
array('order'));
}
?>
1 change: 0 additions & 1 deletion examples/orders/models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ class Person extends ActiveRecord\Model
static $validates_presence_of = array(
array('name'), array('state'));
}
?>
2 changes: 1 addition & 1 deletion examples/orders/orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@

foreach ($order->people as $person)
echo " payment of $$person->amount by " . $person->name . "\n";
?>

1 change: 0 additions & 1 deletion examples/simple/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class Book extends ActiveRecord\Model { }
});

print_r(Book::first()->attributes());
?>
1 change: 0 additions & 1 deletion examples/simple/simple_with_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ class Book extends ActiveRecord\Model
});

print_r(Book::first()->attributes());
?>
Loading