Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2p relationships #137

Merged
merged 22 commits into from
Oct 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ca63172
Add scribu/posts-to-posts to composer.json
pdclark Jun 30, 2014
b7e6f15
Register post relationships. Connect functions to functions.
pdclark Jun 30, 2014
46310ff
Move wp_parser_ending_import action to before counting is turned back…
pdclark Jun 30, 2014
ca012d1
Remove minimum-stability and include UI-less p2p
Oct 5, 2014
cef8033
Make P2P work while only including p2p core
Oct 7, 2014
d108e44
Remove current relationships if they exist
Oct 7, 2014
4fcf640
Fix a bug that prevent functions_to_hooks from working
Oct 7, 2014
138352f
Fix functions_to_hooks relationships
Oct 8, 2014
57bf9c6
Implement method calls relationships
Oct 10, 2014
f7dac24
Add methods_to_x relationships
atimmer Oct 11, 2014
96204f2
Remove debug cruft
atimmer Oct 11, 2014
37472de
Fix an error with getLocation on the ClassMethod check
atimmer Oct 11, 2014
b1497ac
Fix an error when parsing method calls on function calls
atimmer Oct 11, 2014
c4c7d75
Enable self connections the methods_to_methods relation
atimmer Oct 11, 2014
c2fb6d9
Prevent an error with Node_Scalar_Encapsed
atimmer Oct 11, 2014
8575b63
Correctly report the function name a method is called on
atimmer Oct 12, 2014
c57628b
Add function to class mapping for methods
atimmer Oct 12, 2014
ad97c9f
Merge branch 'master' into p2p-relationships
atimmer Oct 23, 2014
6047cad
Fix file indentation
atimmer Oct 23, 2014
845323a
Fix some merge leftovers
atimmer Oct 23, 2014
04d7c9a
Add some missing newlines at the end of files
atimmer Oct 23, 2014
9fdf176
Add documentation where it was previously missing
atimmer Oct 23, 2014
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
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
"source": "https://github.com/rmccue/WP-Parser"
},
"require" : {
"php" : ">=5.3.6",
"composer/installers" : "~1.0",
"phpdocumentor/reflection": "~1.0",
"erusev/parsedown" : "~0.9"
"php" : ">=5.3.6",
"composer/installers" : "~1.0",
"phpdocumentor/reflection" : "~1.0",
"erusev/parsedown" : "~0.9",
"scribu/lib-posts-to-posts": "dev-master@dev",
"scribu/scb-framework" : "dev-master@dev"
},
"autoload" : {
"classmap": ["lib"],
"files" : ["lib/runner.php", "lib/template.php"]
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/scribu/wp-lib-posts-to-posts"
}
]
}
10 changes: 7 additions & 3 deletions lib/class-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ public function import( array $data, $skip_sleep = false, $import_internal_funct
delete_option( "{$this->taxonomy_package}_children" );
delete_option( "{$this->taxonomy_since_version}_children" );

/**
* Action at the end of a complete import
*/
do_action( 'wp_parser_ending_import' );

// Start counting again
Expand Down Expand Up @@ -738,9 +741,10 @@ public function import_item( array $data, $parent_post_id = 0, $import_internal
* Action at the end of importing an item.
*
* @param int $ID Optional; post ID of the inserted or updated item.
* @param array $data Data
* @param array $data PHPDoc data for the item we just imported
* @param array $post_data WordPress data of the post we just inserted or updated
*/
do_action( 'wp_parser_import_item', $ID, $data );
do_action( 'wp_parser_import_item', $ID, $data, $post_data );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to add a parameter to the hook, you should also update the hook docs.


return $ID;
}
Expand Down Expand Up @@ -772,4 +776,4 @@ public function error( $message ) {}
* @param string $message The success message.
*/
public function success( $message ) {}
}
}
72 changes: 72 additions & 0 deletions lib/class-method-call-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public function getName() {

if ( $this->called_in_class && '$this' === $caller ) {
$caller = $this->called_in_class->getShortName();
} else {

// If the caller is a function, convert it to the function name
if ( is_a( $caller, 'PHPParser_Node_Expr_FuncCall' ) ) {

// Add parentheses to signify this is a function call
$caller = $caller->name->parts[0] . '()';
}

$class_mapping = $this->_getClassMapping();
if ( array_key_exists( $caller, $class_mapping ) ) {
$caller = $class_mapping[ $caller ];
}
}

return array( $caller, $name );
Expand All @@ -47,4 +60,63 @@ public function set_class( \phpDocumentor\Reflection\ClassReflector $class ) {

$this->called_in_class = $class;
}

/**
* Returns whether or not this method call is a static call
*
* @return bool Whether or not this method call is a static call
*/
public function isStatic() {
return false;
}

/**
* Returns a mapping from variable names to a class name, leverages globals for most used classes
*
* @return array Class mapping to map variable names to classes
*/
protected function _getClassMapping() {

// List of global use generated using following command:
// ack "global \\\$[^;]+;" --no-filename | tr -d '\t' | sort | uniq | sed "s/global //g" | sed "s/, /,/g" | tr , '\n' | sed "s/;//g" | sort | uniq | sed "s/\\\$//g" | sed "s/[^ ][^ ]*/'&' => ''/g"
// There is probably an easier way, there are currently no globals that are classes starting with an underscore
$wp_globals = array(
'authordata' => 'WP_User',
'custom_background' => 'Custom_Background',
'custom_image_header' => 'Custom_Image_Header',
'phpmailer' => 'PHPMailer',
'post' => 'WP_Post',
'userdata' => 'WP_User', // This can also be stdClass, but you can't call methods on an stdClass
'wp' => 'WP',
'wp_admin_bar' => 'WP_Admin_Bar',
'wp_customize' => 'WP_Customize_Manager',
'wp_embed' => 'WP_Embed',
'wp_filesystem' => 'WP_Filesystem',
'wp_hasher' => 'PasswordHash', // This can be overridden by plugins, for core assume this is ours
'wp_json' => 'Services_JSON',
'wp_list_table' => 'WP_List_Table', // This one differs because there are a lot of different List Tables, assume they all only overwrite existing functions on WP_List_Table
'wp_locale' => 'WP_Locale',
'wp_object_cache' => 'WP_Object_Cache',
'wp_query' => 'WP_Query',
'wp_rewrite' => 'WP_Rewrite',
'wp_roles' => 'WP_Roles',
'wp_scripts' => 'WP_Scripts',
'wp_styles' => 'WP_Styles',
'wp_the_query' => 'WP_Query',
'wp_widget_factory' => 'WP_Widget_Factory',
'wp_xmlrpc_server' => 'wp_xmlrpc_server', // This can be overridden by plugins, for core assume this is ours
'wpdb' => 'wpdb',
);

$wp_functions = array(
'get_current_screen()' => 'WP_Screen',
'_get_list_table()' => 'WP_List_Table', // This one differs because there are a lot of different List Tables, assume they all only overwrite existing functions on WP_List_Table
'wp_get_theme()' => 'WP_Theme',
);

$class_mapping = array_merge( $wp_globals, $wp_functions );

return $class_mapping;
}

}
7 changes: 7 additions & 0 deletions lib/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

class Plugin {

/**
* @var WP_Parser\Relationships
*/
var $relationships;

public function on_load() {

if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'parser', __NAMESPACE__ . '\\Command' );
}

$this->relationships = new Relationships;

add_action( 'init', array( $this, 'register_post_types' ), 11 );
add_action( 'init', array( $this, 'register_taxonomies' ), 11 );
add_filter( 'wp_parser_get_arguments', array( $this, 'make_args_safe' ) );
Expand Down
Loading