diff --git a/.gitignore b/.gitignore index acb7240a..41e96208 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,14 @@ .project +.idea .buildpath .settings *.log *.db *.swp vendor/* +output/* composer.lock phpunit.xml .php_cs.cache .php_cs +build/* diff --git a/.travis.yml b/.travis.yml index ed389f80..027deef9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/composer.json b/composer.json index 3daca1c0..220356ff 100644 --- a/composer.json +++ b/composer.json @@ -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" ] }, diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 6aaa42cf..00000000 --- a/docs/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Active Record Documentation - -Work in progress... diff --git a/docs/_config.yml b/docs/_config.yml deleted file mode 100644 index 2f7efbea..00000000 --- a/docs/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-minimal \ No newline at end of file diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 4f0b64c2..24f1546a 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -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) diff --git a/lib/Model.php b/lib/Model.php index c7e717f2..2dc71198 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -1,5 +1,7 @@ + * ```sql * CREATE TABLE people( * id int primary key auto_increment, * parent_id int, @@ -24,9 +25,9 @@ * cost decimal(10,2), * total decimal(10,2) * ); - * + * ``` * - * + * ```php * class Person extends ActiveRecord\Model { * static $belongs_to = array( * array('parent', 'foreign_key' => 'parent_id', 'class_name' => 'Person') @@ -59,7 +60,7 @@ * $this->total = $this->cost * 0.045; * } * } - * + * ``` * * 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}. @@ -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 @@ -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(); @@ -964,6 +973,13 @@ protected function update_cache() } } + /** + * Generates a unique key for caching. + * + * @protected + * + * @return string + */ protected function cache_key() { $table = static::table(); @@ -1002,8 +1018,8 @@ protected function cache_key() *
  • order: A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)
  • * * - * @params array $options - * return integer Number of rows affected + * @param array $options + * return integer Number of rows affected */ public static function delete_all($options=[]) { @@ -1059,8 +1075,8 @@ public static function delete_all($options=[]) *
  • order: A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)
  • * * - * @params array $options - * return integer Number of rows affected + * @param array $options + * return integer Number of rows affected */ public static function update_all($options=[]) { @@ -1117,6 +1133,9 @@ public function delete() return true; } + /** + * Removes this individual from cache. + */ public function remove_from_cache() { $table = static::table(); @@ -1381,6 +1400,11 @@ public function reload() return $this; } + /** + * Magic Method. Called when cloning a model. + * + * @return Model} + */ public function __clone() { $this->__relationships = []; diff --git a/lib/Relationship.php b/lib/Relationship.php index 6ac76aec..68b6ab2b 100644 --- a/lib/Relationship.php +++ b/lib/Relationship.php @@ -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 */ @@ -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 */ @@ -396,7 +398,7 @@ abstract public function load(Model $model); /** * One-to-many relationship. * - * + * ```php * # Table: people * # Primary key: id * # Foreign key: school_id @@ -409,11 +411,11 @@ abstract public function load(Model $model); * array('people') * ); * }); - * + * ``` * * Example using options: * - * + * ```php * class Payment extends ActiveRecord\Model { * static $belongs_to = array( * array('person'), @@ -429,7 +431,7 @@ abstract public function load(Model $model); * 'conditions' => 'payments.amount < 200') * ); * } - * + * ``` * * @package ActiveRecord * diff --git a/lib/SQLBuilder.php b/lib/SQLBuilder.php index 9bc47eb7..7812c3ee 100644 --- a/lib/SQLBuilder.php +++ b/lib/SQLBuilder.php @@ -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, ...) diff --git a/output/.gitkeep b/output/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/output/.gitkeep @@ -0,0 +1 @@ + diff --git a/sami-config.php b/sami-config.php new file mode 100644 index 00000000..6fb6af27 --- /dev/null +++ b/sami-config.php @@ -0,0 +1,16 @@ +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%' +]); \ No newline at end of file