Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.project
.idea
.buildpath
.settings
*.log
*.db
*.swp
vendor/*
output/*
composer.lock
phpunit.xml
.php_cs.cache
.php_cs
build/*
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: php
cache:
directories:
- $HOME/.composer/cache
- $HOME/.phpcsfixer
- $HOME/.composer/cache/files
- $HOME/.phpcsfixer

before_install:
- if [[ "$TRAVIS_PHP_VERSION" = "hhvm" || "$TRAVIS_PHP_VERSION" = "nightly" ]]; then sed -i '/^.*friendsofphp\/php-cs-fixer.*$/d' composer.json; fi
- if [[ "$TRAVIS_PHP_VERSION" != 7.0 ]]; then sed -i '/^.*sami\/sami.*$/d' composer.json; fi

install:
- travis_retry composer install --prefer-dist --no-interaction
Expand Down Expand Up @@ -37,6 +38,15 @@ matrix:

script:
- IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS
- if [[ "$WITH_PHPCSFIXER" == "true" ]]; then mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose "${COMMIT_SCA_FILES[@]}"; fi
- if [[ "$WITH_PHPCSFIXER" == "true" ]]; then vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"; fi
- ./vendor/bin/phpunit

- if [[ "$WITH_SAMI" == "true" ]]; then ./vendor/bin/sami.php update sami-config.php; fi

deploy:
provider: pages
skip_cleanup: true
local_dir: ./build
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
on:
branch: generate-docs
condition: $TRAVIS_PHP_VERSION = 7.0
Empty file added build/.gitkeep
Empty file.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"phpunit/phpunit": "4.*",
"pear/pear_exception": "1.0",
"friendsofphp/php-cs-fixer": "^2.1",
"pear/log": "~1.13"
},
"sami/sami": "^4.0",
"pear/log": "~1.13"
},
"autoload": {
"files": [ "ActiveRecord.php" ]
},
Expand Down
3 changes: 0 additions & 3 deletions docs/README.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/_config.yml

This file was deleted.

1 change: 1 addition & 0 deletions lib/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class UndefinedPropertyException extends ModelException
/**
* Sets the exception message to show the undefined property's name.
*
* @param string $class_name name of the class with the missing property
* @param string $property_name name of undefined property
*/
public function __construct($class_name, $property_name)
Expand Down
42 changes: 33 additions & 9 deletions lib/Model.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
/**
* The base class for your models.
*
* @package ActiveRecord
*/

namespace ActiveRecord;

/**
* The base class for your models.
*
* Defining an ActiveRecord model for a table called people and orders:
*
* <code>
* ```sql
* CREATE TABLE people(
* id int primary key auto_increment,
* parent_id int,
Expand All @@ -24,9 +25,9 @@
* cost decimal(10,2),
* total decimal(10,2)
* );
* </code>
* ```
*
* <code>
* ```php
* class Person extends ActiveRecord\Model {
* static $belongs_to = array(
* array('parent', 'foreign_key' => 'parent_id', 'class_name' => 'Person')
Expand Down Expand Up @@ -59,7 +60,7 @@
* $this->total = $this->cost * 0.045;
* }
* }
* </code>
* ```
*
* For a more in-depth look at defining models, relationships, callbacks and many other things
* please consult our {@link http://www.phpactiverecord.org/guides Guides}.
Expand Down Expand Up @@ -462,6 +463,9 @@ public function __set($name, $value)
throw new UndefinedPropertyException(get_called_class(), $name);
}

/**
* Magic method; this gets called by PHP itself when your model is unserialized.
*/
public function __wakeup()
{
// make sure the models Table instance gets initialized when waking up
Expand Down Expand Up @@ -956,6 +960,11 @@ private function update($validate=true)
return true;
}

/**
* If individual caching is enabled, this method will re-cache the current state of this model instance.
*
* @protected
*/
protected function update_cache()
{
$table = static::table();
Expand All @@ -964,6 +973,13 @@ protected function update_cache()
}
}

/**
* Generates a unique key for caching.
*
* @protected
*
* @return string
*/
protected function cache_key()
{
$table = static::table();
Expand Down Expand Up @@ -1002,8 +1018,8 @@ protected function cache_key()
* <li><b>order:</b> A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)</li>
* </ul>
*
* @params array $options
* return integer Number of rows affected
* @param array $options
* return integer Number of rows affected
*/
public static function delete_all($options=[])
{
Expand Down Expand Up @@ -1059,8 +1075,8 @@ public static function delete_all($options=[])
* <li><b>order:</b> A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)</li>
* </ul>
*
* @params array $options
* return integer Number of rows affected
* @param array $options
* return integer Number of rows affected
*/
public static function update_all($options=[])
{
Expand Down Expand Up @@ -1117,6 +1133,9 @@ public function delete()
return true;
}

/**
* Removes this individual from cache.
*/
public function remove_from_cache()
{
$table = static::table();
Expand Down Expand Up @@ -1381,6 +1400,11 @@ public function reload()
return $this;
}

/**
* Magic Method. Called when cloning a model.
*
* @return Model}
*/
public function __clone()
{
$this->__relationships = [];
Expand Down
18 changes: 10 additions & 8 deletions lib/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ protected function query_and_attach_related_models_eagerly(Table $table, $models
/**
* Creates a new instance of specified {@link Model} with the attributes pre-loaded.
*
* @param Model $model The model which holds this association
* @param array $attributes Hash containing attributes to initialize the model with
* @param Model $model The model which holds this association
* @param array $attributes Hash containing attributes to initialize the model with
* @param bool $guard_attributes Set to true to guard protected/non-accessible attributes on the new instance
*
* @return Model
*/
Expand All @@ -240,8 +241,9 @@ public function build_association(Model $model, $attributes=[], $guard_attribute
/**
* Creates a new instance of {@link Model} and invokes save.
*
* @param Model $model The model which holds this association
* @param array $attributes Hash containing attributes to initialize the model with
* @param Model $model The model which holds this association
* @param array $attributes Hash containing attributes to initialize the model with
* @param bool $guard_attributes Set to true to guard protected/non-accessible attributes on the new instance
*
* @return Model
*/
Expand Down Expand Up @@ -396,7 +398,7 @@ abstract public function load(Model $model);
/**
* One-to-many relationship.
*
* <code>
* ```php
* # Table: people
* # Primary key: id
* # Foreign key: school_id
Expand All @@ -409,11 +411,11 @@ abstract public function load(Model $model);
* array('people')
* );
* });
* </code>
* ```
*
* Example using options:
*
* <code>
* ```php
* class Payment extends ActiveRecord\Model {
* static $belongs_to = array(
* array('person'),
Expand All @@ -429,7 +431,7 @@ abstract public function load(Model $model);
* 'conditions' => 'payments.amount < 200')
* );
* }
* </code>
* ```
*
* @package ActiveRecord
*
Expand Down
4 changes: 2 additions & 2 deletions lib/SQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ public static function create_conditions_from_underscored_string(Connection $con
/**
* Like create_conditions_from_underscored_string but returns a hash of name => value array instead.
*
* @param string $name A string containing attribute names connected with _and_ or _or_
* @param $args Array of values for each attribute in $name
* @param string $name A string containing attribute names connected with _and_ or _or_
* @param array $values Array of values for each attribute in $name
* @param $map A hash of "mapped_column_name" => "real_column_name"
*
* @return array A hash of array(name => value, ...)
Expand Down
1 change: 1 addition & 0 deletions output/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 16 additions & 0 deletions sami-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use Sami\Sami;
use Sami\RemoteRepository\GitHubRemoteRepository;
use Sami\Version\GitVersionCollection;
use Symfony\Component\Finder\Finder;

$versions = GitVersionCollection::create('lib')
->add('1.0', '1,0 release')
->add('master', 'master branch')
;
return new Sami('lib', [
'theme' => 'default',
'versions' => $versions,
'build_dir' => 'build/api/%version%',
'cache_dir' => 'build/api/cache/%version%'
]);