This repository has been archived by the owner on May 14, 2019. It is now read-only.
forked from bermi/akelos
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
21,016 additions
and
6 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
class DocInstaller extends AkInstaller | ||
{ | ||
function up_1() | ||
{ | ||
$this->createTable('components', " | ||
id, | ||
name, | ||
description, | ||
parent_id, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('categories', " | ||
id, | ||
name, | ||
description, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('related_categories', " | ||
id, | ||
category_id, | ||
related_category_id | ||
"); | ||
|
||
$this->createTable('files', " | ||
id, | ||
component_id, | ||
path, | ||
body, | ||
hash, | ||
has_been_analyzed, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('klasses', " | ||
id, | ||
name, | ||
description, | ||
file_id, | ||
component_id, | ||
parent_id, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('methods', " | ||
id, | ||
name, | ||
description, | ||
klass_id, | ||
category_id, | ||
is_private, | ||
returns_reference bool default 0, | ||
position int, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('parameters', " | ||
id, | ||
name, | ||
method_id, | ||
data_type_id, | ||
default_value, | ||
description, | ||
is_reference, | ||
position, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('data_types', ' | ||
id, | ||
name | ||
'); | ||
|
||
|
||
$this->createTable('examples', " | ||
id, | ||
name, | ||
method_id, | ||
component_id, | ||
category_id, | ||
body, | ||
created_at, | ||
updated_at | ||
"); | ||
|
||
$this->createTable('comments', " | ||
id, | ||
body, | ||
user, | ||
email, | ||
method_id, | ||
ip_address, | ||
spam_score integer default 0, | ||
is_published bool default 0, | ||
created_at, | ||
updated_at | ||
"); | ||
} | ||
|
||
function down_1() | ||
{ | ||
$this->dropTables('components,files,methods,klasses,parameters,examples,comments,categories,related_categories,data_types'); | ||
} | ||
|
||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
class Category extends AkActiveRecord | ||
{ | ||
public $has_many = array('methods'); | ||
public $habtm = array('related_categories'=>array( | ||
'association_foreign_key'=>'related_category_id', | ||
'join_table'=>'related_categories', | ||
'join_class_name'=>'RelatedCategory', | ||
'unique' => true | ||
)); | ||
|
||
public function validate() | ||
{ | ||
$this->validatesUniquenessOf('name'); | ||
} | ||
|
||
public function &updateCategoryDetails(&$Method, $method_details, &$SourceAnalyzer) | ||
{ | ||
static $updated_categories = array(); | ||
if($method_details['category'] != 'none' && !in_array($method_details['category'], $updated_categories)){ | ||
$Category = $this->findOrCreateBy('name', $method_details['category']); | ||
$Category->setAttributes(array( | ||
'description' => $method_details['category_details'] | ||
)); | ||
|
||
$Category->save(); | ||
$Method->category->assign($Category); | ||
|
||
$updated_categories[] = $method_details['category']; | ||
|
||
if(false && !empty($method_details['category_relations'])){ | ||
$RelatedCategories = array(); | ||
foreach($method_details['category_relations'] as $category_name){ | ||
$RelatedCategories[] = $this->findOrCreateBy('name', $category_name); | ||
} | ||
$Category->related_category->set($RelatedCategories); | ||
$Category->save(); | ||
} | ||
} | ||
|
||
// parameters doc_metadata category_id | ||
|
||
return $Category; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
class Comment extends AkActiveRecord | ||
{ | ||
|
||
} | ||
|
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
class Component extends AkActiveRecord | ||
{ | ||
public $acts_as = 'tree'; | ||
public $has_many = array('files', 'methods', 'categories', 'klasses'); | ||
|
||
public function validate() | ||
{ | ||
$this->set('name', trim($this->get('name'))); | ||
$this->validatesUniquenessOf('name', array('scope'=>'parent_id')); | ||
} | ||
|
||
|
||
public function &updateComponentDetails(&$File, &$SourceAnalizer) | ||
{ | ||
$details = $SourceAnalizer->getFileDetails($File->body); | ||
$package = empty($details['package']) ? false : $details['package']; | ||
$subpackage = empty($details['subpackage']) ? false : $details['subpackage']; | ||
|
||
if(!$Component = $this->findFirstBy('name', $package)){ | ||
$SourceAnalizer->log('Adding package: '.$package); | ||
$Component = $this->create(array('name'=> $package)); | ||
} | ||
|
||
if(!$SubComponent = $this->findFirstBy('name AND parent_id', $subpackage, $Component->id)){ | ||
$SubComponent = $this->create(array('name'=> $subpackage)); | ||
$SourceAnalizer->log('Adding package: '.$subpackage); | ||
} | ||
|
||
if(empty($File->component_id)){ | ||
$SourceAnalizer->log('Relating file '.$File->path.' to component '.$subpackage); | ||
$File->component->assign($SubComponent); | ||
$File->save(); | ||
} | ||
|
||
if($Component && $SubComponent && !in_array($SubComponent->id, $Component->collect($Component->tree->getChildren(),'id','id'))){ | ||
$SourceAnalizer->log('Setting package '.$subpackage.' as a child for '.$package); | ||
$Component->tree->addChild($SubComponent); | ||
$Component->save(); | ||
} | ||
|
||
return $SubComponent; | ||
} | ||
} | ||
|
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
class DataType extends AkActiveRecord | ||
{ | ||
public $belongs_to = 'parameter'; | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
class Example extends AkActiveRecord | ||
{ | ||
public $belongs_to = array('method'); | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class File extends AkActiveRecord | ||
{ | ||
public $has_many = array('methods'); | ||
public $belongs_to = array('component', 'category'); | ||
|
||
public function validate() | ||
{ | ||
$this->validatesUniquenessOf('path'); | ||
} | ||
} | ||
|
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
class Klass extends AkActiveRecord | ||
{ | ||
public $acts_as = 'tree'; | ||
public $belongs_to = array('file', 'component'); | ||
public $has_many = array('methods'=>array('order'=>'position'), 'categories'); | ||
|
||
public function validate() | ||
{ | ||
$this->validatesUniquenessOf('name'); | ||
} | ||
|
||
|
||
public function &updateClassDetails(&$File, &$Component, &$SourceAnalyzer) | ||
{ | ||
$MethodInstance = new Method(array('init'=>false)); | ||
$MethodInstance->setConnection($this->getConnection()); | ||
$MethodInstance->init(); | ||
|
||
$parsed_details = $SourceAnalyzer->getParsedArray($File->body); | ||
|
||
$available_classes = empty($parsed_details['classes']) ? array() : array_keys($parsed_details['classes']); | ||
|
||
|
||
if(empty($available_classes)){ | ||
return $available_classes; | ||
} | ||
|
||
$Classes = array(); | ||
foreach ($available_classes as $class_name){ | ||
$extends = !empty($parsed_details['classes'][$class_name]['extends']) ? $parsed_details['classes'][$class_name]['extends'] : false; | ||
|
||
if($extends){ | ||
$SourceAnalyzer->log('Looking for parent class: '.$extends); | ||
$ParentClass = $this->_addOrUpdateClassDetails($extends, $File, $Component, $SourceAnalyzer, array(), true); | ||
} | ||
|
||
$Class = $this->_addOrUpdateClassDetails($class_name, $File, $Component, $SourceAnalyzer, $parsed_details['classes'][$class_name]); | ||
|
||
if(!empty($ParentClass)){ | ||
$SourceAnalyzer->log('Setting '.$extends.' as the parent of '.$class_name); | ||
$ParentClass->tree->addChild($Class); | ||
$ParentClass->save(); | ||
} | ||
|
||
$Class->methods = array(); | ||
if(!empty($parsed_details['classes'][$class_name]['methods'])){ | ||
foreach ($parsed_details['classes'][$class_name]['methods'] as $method_name => $method_details){ | ||
$Class->methods[] = $MethodInstance->updateMethodDetails($Class, $method_name, $method_details, $SourceAnalyzer); | ||
} | ||
} | ||
|
||
$Classes[] = $Class; | ||
} | ||
|
||
return $Classes; | ||
} | ||
|
||
public function &_addOrUpdateClassDetails($class_name, &$File, &$Component, &$SourceAnalyzer, $class_details, $ExtendedClass = null) | ||
{ | ||
$class_details = array( | ||
'name'=> $class_name, | ||
'file_id' => $File->getId(), | ||
'component_id' => $Component->getId(), | ||
'description' => @$class_details['doc'] | ||
); | ||
/* | ||
'doc' => trim($this->_latest_docs, "\n\t "), | ||
'doc_metadata' => $this->_latest_attributes, | ||
'class_name' => $this->_current_class, | ||
'extends' => trim($this->_current_class_extends), | ||
*/ | ||
|
||
$class_details = array_filter($class_details, 'strlen'); | ||
|
||
if(!$Class = $this->findFirstBy('name', $class_name)){ | ||
$SourceAnalyzer->log('Adding class: '.$class_name); | ||
|
||
if(!empty($ExtendedClass)){ | ||
$class_details = array('name'=>$class_details['name']); | ||
} | ||
|
||
$Class = new Klass(array('init'=>false)); | ||
$Class->setConnection($this->getConnection()); | ||
$Class->setAttributes($class_details); | ||
$Class->save(); | ||
|
||
$SourceAnalyzer->log('Added class: '.$class_name); | ||
}elseif(empty($ExtendedClass) && $File->getId() != $Class->get('file_id') || $Component->getId() != $Class->get('component_id')){ | ||
$SourceAnalyzer->log('Modifying class details: '.$class_name); | ||
unset($class_details['name']); | ||
$Class->setAttributes($class_details); | ||
$Class->save(); | ||
} | ||
return $Class; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.