-
Notifications
You must be signed in to change notification settings - Fork 385
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
Added autoloader to reduce complexity; fix phpcs issues #828
Merged
Merged
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
8346524
Added classmap autoloader, removed all require_once(), deprecated amp…
mikeschinkel 5c1fa20
Remove duplicated array index.
mikeschinkel 33c0ebf
Initialize array that is used by may not have been initialized.
mikeschinkel 08bac6b
Removed unused variables.
mikeschinkel e5c1a8c
Removed 2nd parameter to remove_shortcode() because remove_shortcode(…
mikeschinkel 8b267ef
Added some PHPDoc for methods.
mikeschinkel 8b34e24
Added PHPDoc so PhpStorm will not flag as an error.
mikeschinkel b54243b
Add dev-lib
westonruter 38cccab
Remove partial PHPDoc header.
mikeschinkel f13c385
Restructure autoloader to use static methods.
mikeschinkel 03c126b
Document the sanitizers
mikeschinkel fdd1c74
Documented AMP DOM Utils.
mikeschinkel 48c492e
Updating reference to dev-lib
mikeschinkel 1a0b53c
Documented PHPDoc header for amp_get_permalink()
mikeschinkel fb10624
Renamed _build_placeholder() back to build_placeholder() since no whe…
mikeschinkel 19b6f04
Remove errant tick mark.
mikeschinkel b1ee243
Revert string concatenation style change.
mikeschinkel 010dad4
Revert regex syntax style change.
mikeschinkel 8fad986
Add class AMP_Rule_Spec in its own file.
mikeschinkel 241e866
Merge branch 'develop' of https://github.com/Automattic/amp-wp into n…
westonruter 38992ed
Fix autoloader file refs and PHP 5.2 compat
westonruter 5fcbc2b
Fix phpcs
westonruter 2105af0
Stop <amg-audio> sanitizer from including a contained "\n" (and thus …
mikeschinkel f85c366
Revert the unfortunate change that broke placeholders in iframes.
mikeschinkel 564a9d9
Ensure that no errant whitespace text nodes are added to output. Thi…
mikeschinkel f90c16d
Exclude includes/lib from linting; temporarily disable phpcs
westonruter b62132a
Change self::class to hardcode the class to support earlier versions …
mikeschinkel 5417aeb
Fix improperly added filepath for the FastImage class in the autoloader.
mikeschinkel 19658c9
Merge branch 'develop' of github.com:newclarity/amp-wp into develop
mikeschinkel a66c992
Merge branch 'develop' of github.com:newclarity/amp-wp into develop
mikeschinkel 23bf64f
Fixed autoloader for PHP 5.2, e.g. __DIR__ ==> dirname( __FILE__ )
mikeschinkel bfa54bc
PHP5.2: Remove '\' from on front of ReflectionClass() because PHP 5.2…
mikeschinkel 129bda7
Added PHPDoc explaining relative filepaths not having leading slash o…
mikeschinkel b1feee0
Added logic in AMP_DOM_Utils::get_content_from_dom() to replace <br><…
mikeschinkel 00bea9b
Another attempt to fix unit test.
mikeschinkel b74ee8f
Another attempt to fix unit test, take two.
mikeschinkel 6000b50
Ensure that content if retrieved via get_content_from_dom() and not v…
mikeschinkel 6e0c13b
Added a composer.json.
mikeschinkel bd97046
Handle "no body" in AMP_DOM_Utils::get_content_from_dom()
mikeschinkel 215a27b
Split get_content_from_dom() in to by adding get_content_from_dom_nod…
mikeschinkel 85a46ba
Use the new AMP_DOM_Utils::get_content_from_dom_node() to make failin…
mikeschinkel de7f617
Remove "repositories" from composer.json because it is not merged in …
mikeschinkel 5d1157f
Had to remove require: php>=5.2 because it appears to be breaking the…
mikeschinkel 42c0600
Ugh. Have to go with minimal composer.json because it is breaking the…
mikeschinkel 47edc2f
Need a commit to trigger a rebuild given that one of them timed out...
mikeschinkel 3e15941
Merge branch 'develop' of github.com:Automattic/amp-wp into develop
ThierryA f5b2d2f
Include test/stubs in autoloader; remove unused absolute path support…
westonruter 8b416f9
Fix phpcs issues in modified files
westonruter 575ac66
Fix phpcs issues in AMP_Post_Template
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
SYNC_README_MD=0 | ||
SYNC_README_MD=0 | ||
PATH_EXCLUDES_PATTERN=includes/lib/* | ||
|
||
# Temporary to avoid having to fix all phpcs issues for touched files in <https://github.com/Automattic/amp-wp/pull/828>. | ||
DEV_LIB_SKIP=phpcs |
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,141 @@ | ||
<?php | ||
|
||
/** | ||
* Autoload the classes used by the AMP plugin. | ||
* | ||
* Class AMP_Autoloader | ||
*/ | ||
class AMP_Autoloader { | ||
|
||
/** | ||
* Map of Classname to relative filepath sans extension. | ||
* | ||
* @note We omitted the leading slash and the .php extension from each | ||
* relative filepath because they are redundant and to include | ||
* them would take up unnecessary bytes of memory at runtime. | ||
* | ||
* @example Format (note no leading / and no .php extension): | ||
* | ||
* array( | ||
* 'Class_Name1' => 'subdir-of-includes/filename1', | ||
* 'Class_Name2' => '2nd-subdir-of-includes/filename2', | ||
* 'Class_Name3' => '!/full/path/to/filename3.php', | ||
* ); | ||
* | ||
* @var string[] | ||
*/ | ||
private static $_classmap = array( | ||
'AMP_Actions' => 'actions/class-amp-actions', | ||
'AMP_Frontend_Actions' => 'actions/class-amp-frontend-actions', | ||
'AMP_Paired_Post_Actions' => 'actions/class-amp-paired-post-actions', | ||
'AMP_Template_Customizer' => 'admin/class-amp-customizer', | ||
'AMP_Post_Meta_Box' => 'admin/class-amp-post-meta-box', | ||
'AMP_Post_Type_Support' => 'class-amp-post-type-support', | ||
'AMP_Base_Embed_Handler' => 'embeds/class-amp-base-embed-handler', | ||
'AMP_DailyMotion_Embed_Handler' => 'embeds/class-amp-dailymotion-embed', | ||
'AMP_Facebook_Embed_Handler' => 'embeds/class-amp-facebook-embed', | ||
'AMP_Gallery_Embed_Handler' => 'embeds/class-amp-gallery-embed', | ||
'AMP_Instagram_Embed_Handler' => 'embeds/class-amp-instagram-embed', | ||
'AMP_Pinterest_Embed_Handler' => 'embeds/class-amp-pinterest-embed', | ||
'AMP_SoundCloud_Embed_Handler' => 'embeds/class-amp-soundcloud-embed', | ||
'AMP_Twitter_Embed_Handler' => 'embeds/class-amp-twitter-embed', | ||
'AMP_Vimeo_Embed_Handler' => 'embeds/class-amp-vimeo-embed', | ||
'AMP_Vine_Embed_Handler' => 'embeds/class-amp-vine-embed', | ||
'AMP_YouTube_Embed_Handler' => 'embeds/class-amp-youtube-embed', | ||
'FastImage' => 'lib/fastimage/class-fastimage', | ||
'WillWashburn\\Stream\\Exception\\StreamBufferTooSmallException' => 'lib/fasterimage/Stream/Exception/StreamBufferTooSmallException', | ||
'WillWashburn\\Stream\\StreamableInterface' => 'lib/fasterimage/Stream/StreamableInterface', | ||
'WillWashburn\\Stream\\Stream' => 'lib/fasterimage/Stream/Stream', | ||
'FasterImage\\Exception\\InvalidImageException' => 'lib/fasterimage/Exception/InvalidImageException', | ||
'FasterImage\\ExifParser' => 'lib/fasterimage/ExifParser', | ||
'FasterImage\\ImageParser' => 'lib/fasterimage/ImageParser', | ||
'FasterImage\\FasterImage' => 'lib/fasterimage/FasterImage', | ||
'AMP_Analytics_Options_Submenu' => 'options/class-amp-analytics-options-submenu', | ||
'AMP_Options_Menu' => 'options/class-amp-options-menu', | ||
'AMP_Options_Manager' => 'options/class-amp-options-manager', | ||
'AMP_Analytics_Options_Submenu_Page' => 'options/views/class-amp-analytics-options-submenu-page', | ||
'AMP_Options_Menu_Page' => 'options/views/class-amp-options-menu-page', | ||
'AMP_Rule_Spec' => 'sanitizers/class-amp-rule-spec', | ||
'AMP_Allowed_Tags_Generated' => 'sanitizers/class-amp-allowed-tags-generated', | ||
'AMP_Audio_Sanitizer' => 'sanitizers/class-amp-audio-sanitizer', | ||
'AMP_Base_Sanitizer' => 'sanitizers/class-amp-base-sanitizer', | ||
'AMP_Blacklist_Sanitizer' => 'sanitizers/class-amp-blacklist-sanitizer', | ||
'AMP_Iframe_Sanitizer' => 'sanitizers/class-amp-iframe-sanitizer', | ||
'AMP_Img_Sanitizer' => 'sanitizers/class-amp-img-sanitizer', | ||
'AMP_Playbuzz_Sanitizer' => 'sanitizers/class-amp-playbuzz-sanitizer', | ||
'AMP_Style_Sanitizer' => 'sanitizers/class-amp-style-sanitizer', | ||
'AMP_Tag_And_Attribute_Sanitizer' => 'sanitizers/class-amp-tag-and-attribute-sanitizer', | ||
'AMP_Video_Sanitizer' => 'sanitizers/class-amp-video-sanitizer', | ||
'AMP_Customizer_Design_Settings' => 'settings/class-amp-customizer-design-settings', | ||
'AMP_Customizer_Settings' => 'settings/class-amp-customizer-settings', | ||
'AMP_Content' => 'templates/class-amp-content', | ||
'AMP_Content_Sanitizer' => 'templates/class-amp-content-sanitizer', | ||
'AMP_Post_Template' => 'templates/class-amp-post-template', | ||
'AMP_DOM_Utils' => 'utils/class-amp-dom-utils', | ||
'AMP_HTML_Utils' => 'utils/class-amp-html-utils', | ||
'AMP_Image_Dimension_Extractor' => 'utils/class-amp-image-dimension-extractor', | ||
'AMP_String_Utils' => 'utils/class-amp-string-utils', | ||
'AMP_WP_Utils' => 'utils/class-amp-wp-utils', | ||
'WPCOM_AMP_Polldaddy_Embed' => 'wpcom/class-amp-polldaddy-embed', | ||
); | ||
|
||
/** | ||
* Is registered. | ||
* | ||
* @var bool | ||
*/ | ||
public static $is_registered = false; | ||
|
||
/** | ||
* Perform the autoload on demand when requested by PHP runtime. | ||
* | ||
* Design Goal: Execute as few lines of code as possible each call. | ||
* | ||
* @since 0.6.0 | ||
* | ||
* @note If $class_name has first char as '!' strip it and assume | ||
* a full path with extension otherwise assume a subdir of | ||
* /includes/ that does not contain an extension. | ||
* | ||
* @param string $class_name Class name. | ||
*/ | ||
protected static function autoload( $class_name ) { | ||
if ( ! isset( self::$_classmap[ $class_name ] ) ) { | ||
return; | ||
} | ||
$filepath = self::$_classmap[ $class_name ]; | ||
require '!' !== $filepath[0] ? dirname( __FILE__ ) . "/includes/{$filepath}.php" : substr( $filepath, 1 ); | ||
} | ||
|
||
/** | ||
* Registers this autoloader to PHP. | ||
* | ||
* @since 0.6.0 | ||
* | ||
* Called at the end of this file; calling a second time has no effect. | ||
*/ | ||
public static function register() { | ||
if ( ! self::$is_registered ) { | ||
spl_autoload_register( array( __CLASS__, 'autoload' ) ); | ||
self::$is_registered = true; | ||
} | ||
} | ||
|
||
/** | ||
* Allows an extensions plugin to register a class and its file for autoloading | ||
* | ||
* @since 0.6.0 | ||
* | ||
* @param string $class_name Full classname (include namespace if applicable). | ||
* @param string $filepath Absolute filepath to class file, including .php extension. | ||
*/ | ||
public static function register_autoload_class( $class_name, $filepath ) { | ||
self::$_classmap[ $class_name ] = '!' . $filepath; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Call method to register this autoloader with PHP. | ||
*/ | ||
AMP_Autoloader::register(); |
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 @@ | ||
{ | ||
"name": "automattic/amp-wp", | ||
"description": "WordPress plugin for adding AMP support.", | ||
"homepage": "https://github.com/Automattic/amp-wp", | ||
"type": "wordpress-plugin", | ||
"license": "GPL-2.0" | ||
} |
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,25 +1,9 @@ | ||
<?php | ||
|
||
function amp_load_fasterimage_classes() { | ||
// We're not using composer to pull in FasterImage so we need to load the files manually | ||
$fasterimage__DIR__ = dirname( __FILE__ ); | ||
|
||
// Stream files | ||
require_once( $fasterimage__DIR__ . '/Stream/Exception/StreamBufferTooSmallException.php' ); | ||
require_once( $fasterimage__DIR__ . '/Stream/StreamableInterface.php' ); | ||
require_once( $fasterimage__DIR__ . '/Stream/Stream.php' ); | ||
|
||
// FasterImage files | ||
require_once( $fasterimage__DIR__ . '/Exception/InvalidImageException.php' ); | ||
require_once( $fasterimage__DIR__ . '/ExifParser.php' ); | ||
require_once( $fasterimage__DIR__ . '/ImageParser.php' ); | ||
require_once( $fasterimage__DIR__ . '/FasterImage.php' ); | ||
_deprecated_function( __FUNCTION__, '0.6.0' ); | ||
} | ||
|
||
function amp_get_fasterimage_client( $user_agent ) { | ||
if ( ! class_exists( 'FasterImage\FasterImage' ) ) { | ||
amp_load_fasterimage_classes(); | ||
} | ||
|
||
return new FasterImage\FasterImage( $user_agent ); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing function description, param description, and return description. We've also been adding
@since
tags.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your requests to document this caused me to go down the rabbit hole for the past (far too many) hours. Every time I would document something it would cause PhpStorm to flag something else as being "off", so I ended up documented all of the sanitizers.
Note I found a few places that would throw errors, e.g.
DOMNode $nodes
using methods that are only onDOMElement
so I added a variable of logic to ensure errors are not thrown during the normal course of usage whenWP_DEBUG
is set totrue
. One such example is I added the following in several places:I hope that was okay...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node type checks are probably a good idea, as I can see that clearly some of the situations would result in text nodes being used as elements. It looks like some of the instances you added would never result in a non-element being iterated (e.g.
$this->dom->getElementsByTagName( self::$tag );
) but it doesn't hurt.