@@ -12,10 +12,10 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @return Remote_Entity_Importer |
| 14 | 14 | */ |
| 15 | - public static function from_entity( $entity ) { |
|
| 15 | + public static function from_entity($entity) { |
|
| 16 | 16 | |
| 17 | - if ( $entity instanceof Valid_Remote_Entity ) { |
|
| 18 | - return new Valid_Remote_Entity_Importer( $entity ); |
|
| 17 | + if ($entity instanceof Valid_Remote_Entity) { |
|
| 18 | + return new Valid_Remote_Entity_Importer($entity); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | return new Invalid_Remote_Entity_Importer(); |
@@ -7,17 +7,17 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Remote_Entity_Importer_Factory { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @param $entity Remote_Entity |
|
| 12 | - * |
|
| 13 | - * @return Remote_Entity_Importer |
|
| 14 | - */ |
|
| 15 | - public static function from_entity( $entity ) { |
|
| 10 | + /** |
|
| 11 | + * @param $entity Remote_Entity |
|
| 12 | + * |
|
| 13 | + * @return Remote_Entity_Importer |
|
| 14 | + */ |
|
| 15 | + public static function from_entity( $entity ) { |
|
| 16 | 16 | |
| 17 | - if ( $entity instanceof Valid_Remote_Entity ) { |
|
| 18 | - return new Valid_Remote_Entity_Importer( $entity ); |
|
| 19 | - } |
|
| 17 | + if ( $entity instanceof Valid_Remote_Entity ) { |
|
| 18 | + return new Valid_Remote_Entity_Importer( $entity ); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - return new Invalid_Remote_Entity_Importer(); |
|
| 22 | - } |
|
| 21 | + return new Invalid_Remote_Entity_Importer(); |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -14,88 +14,88 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Analytics_Connect { |
| 16 | 16 | |
| 17 | - const HANDLE = 'wordlift'; |
|
| 17 | + const HANDLE = 'wordlift'; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Gets an array of related entities with their post IDs and titles. |
|
| 21 | - * |
|
| 22 | - * @method get_analytics_event_data |
|
| 23 | - * @since 3.21.0 |
|
| 24 | - * |
|
| 25 | - * @param int $post_id post id we want related data for. |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public static function get_analytics_event_data( $post_id ) { |
|
| 30 | - // If no ID was passed get current ID. |
|
| 31 | - if ( ! $post_id ) { |
|
| 32 | - $post_id = get_queried_object_id(); |
|
| 33 | - } |
|
| 34 | - /** |
|
| 35 | - * TODO: set/get this from cache. |
|
| 36 | - */ |
|
| 37 | - $related_items = array(); |
|
| 38 | - $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 19 | + /** |
|
| 20 | + * Gets an array of related entities with their post IDs and titles. |
|
| 21 | + * |
|
| 22 | + * @method get_analytics_event_data |
|
| 23 | + * @since 3.21.0 |
|
| 24 | + * |
|
| 25 | + * @param int $post_id post id we want related data for. |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public static function get_analytics_event_data( $post_id ) { |
|
| 30 | + // If no ID was passed get current ID. |
|
| 31 | + if ( ! $post_id ) { |
|
| 32 | + $post_id = get_queried_object_id(); |
|
| 33 | + } |
|
| 34 | + /** |
|
| 35 | + * TODO: set/get this from cache. |
|
| 36 | + */ |
|
| 37 | + $related_items = array(); |
|
| 38 | + $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 39 | 39 | |
| 40 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 41 | - // If the current item is also an entity then add it to the list of IDs. |
|
| 42 | - if ( $entity_service->is_entity( $post_id ) ) { |
|
| 43 | - $related_ids[] = $post_id; |
|
| 44 | - } |
|
| 45 | - $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
| 46 | - // Get the post titles of related items and connect them in an array. |
|
| 47 | - foreach ( $related_ids as $related_id ) { |
|
| 48 | - $type = $entity_type_service->get( $related_id ); |
|
| 49 | - $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | - $label = $entity_service->get_labels( $related_id ); |
|
| 51 | - $label = $label[0]; |
|
| 40 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 41 | + // If the current item is also an entity then add it to the list of IDs. |
|
| 42 | + if ( $entity_service->is_entity( $post_id ) ) { |
|
| 43 | + $related_ids[] = $post_id; |
|
| 44 | + } |
|
| 45 | + $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
| 46 | + // Get the post titles of related items and connect them in an array. |
|
| 47 | + foreach ( $related_ids as $related_id ) { |
|
| 48 | + $type = $entity_type_service->get( $related_id ); |
|
| 49 | + $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | + $label = $entity_service->get_labels( $related_id ); |
|
| 51 | + $label = $label[0]; |
|
| 52 | 52 | |
| 53 | - $related_items[ $related_id ] = array( |
|
| 54 | - 'uri' => $entity_service->get_uri( $related_id ), |
|
| 55 | - 'type' => $type, |
|
| 56 | - 'label' => $label, |
|
| 57 | - ); |
|
| 58 | - } |
|
| 53 | + $related_items[ $related_id ] = array( |
|
| 54 | + 'uri' => $entity_service->get_uri( $related_id ), |
|
| 55 | + 'type' => $type, |
|
| 56 | + 'label' => $label, |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $related_items; |
|
| 61 | - } |
|
| 60 | + return $related_items; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Gets the configuration data assosiated with the analytics settings. For |
|
| 65 | - * frontend script use primarily. |
|
| 66 | - * |
|
| 67 | - * @method get_analytics_config_data |
|
| 68 | - * @since 3.21.0 |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - public static function get_analytics_config_data() { |
|
| 72 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 73 | - // get some values from the config service. |
|
| 74 | - $config = array( |
|
| 75 | - 'entity_uri_dimension' => $configuration_service->get_analytics_entity_uri_dimension(), |
|
| 76 | - 'entity_type_dimension' => $configuration_service->get_analytics_entity_type_dimension(), |
|
| 77 | - ); |
|
| 63 | + /** |
|
| 64 | + * Gets the configuration data assosiated with the analytics settings. For |
|
| 65 | + * frontend script use primarily. |
|
| 66 | + * |
|
| 67 | + * @method get_analytics_config_data |
|
| 68 | + * @since 3.21.0 |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + public static function get_analytics_config_data() { |
|
| 72 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 73 | + // get some values from the config service. |
|
| 74 | + $config = array( |
|
| 75 | + 'entity_uri_dimension' => $configuration_service->get_analytics_entity_uri_dimension(), |
|
| 76 | + 'entity_type_dimension' => $configuration_service->get_analytics_entity_type_dimension(), |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - return $config; |
|
| 80 | - } |
|
| 79 | + return $config; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Enqueues our scripts for the frontend analytics handling and attaches |
|
| 84 | - * any data we will want to use there. |
|
| 85 | - * |
|
| 86 | - * @method enqueue_scripts |
|
| 87 | - * @since 3.21.0 |
|
| 88 | - */ |
|
| 89 | - public function enqueue_scripts() { |
|
| 90 | - $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 91 | - // Bail early if there is no event data that we would send. |
|
| 92 | - if ( ! $entity_data ) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $data = self::get_analytics_config_data(); |
|
| 82 | + /** |
|
| 83 | + * Enqueues our scripts for the frontend analytics handling and attaches |
|
| 84 | + * any data we will want to use there. |
|
| 85 | + * |
|
| 86 | + * @method enqueue_scripts |
|
| 87 | + * @since 3.21.0 |
|
| 88 | + */ |
|
| 89 | + public function enqueue_scripts() { |
|
| 90 | + $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 91 | + // Bail early if there is no event data that we would send. |
|
| 92 | + if ( ! $entity_data ) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $data = self::get_analytics_config_data(); |
|
| 96 | 96 | |
| 97 | - // Uses the analytics code in the main WordLift plugin. |
|
| 98 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 100 | - } |
|
| 97 | + // Uses the analytics code in the main WordLift plugin. |
|
| 98 | + wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | + wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -26,32 +26,32 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return array |
| 28 | 28 | */ |
| 29 | - public static function get_analytics_event_data( $post_id ) { |
|
| 29 | + public static function get_analytics_event_data($post_id) { |
|
| 30 | 30 | // If no ID was passed get current ID. |
| 31 | - if ( ! $post_id ) { |
|
| 31 | + if ( ! $post_id) { |
|
| 32 | 32 | $post_id = get_queried_object_id(); |
| 33 | 33 | } |
| 34 | 34 | /** |
| 35 | 35 | * TODO: set/get this from cache. |
| 36 | 36 | */ |
| 37 | 37 | $related_items = array(); |
| 38 | - $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 38 | + $related_ids = wl_core_get_related_entity_ids($post_id); |
|
| 39 | 39 | |
| 40 | 40 | $entity_service = Wordlift_Entity_Service::get_instance(); |
| 41 | 41 | // If the current item is also an entity then add it to the list of IDs. |
| 42 | - if ( $entity_service->is_entity( $post_id ) ) { |
|
| 42 | + if ($entity_service->is_entity($post_id)) { |
|
| 43 | 43 | $related_ids[] = $post_id; |
| 44 | 44 | } |
| 45 | 45 | $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
| 46 | 46 | // Get the post titles of related items and connect them in an array. |
| 47 | - foreach ( $related_ids as $related_id ) { |
|
| 48 | - $type = $entity_type_service->get( $related_id ); |
|
| 49 | - $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | - $label = $entity_service->get_labels( $related_id ); |
|
| 47 | + foreach ($related_ids as $related_id) { |
|
| 48 | + $type = $entity_type_service->get($related_id); |
|
| 49 | + $type = isset($type['uri']) ? $type['uri'] : 'unknown'; |
|
| 50 | + $label = $entity_service->get_labels($related_id); |
|
| 51 | 51 | $label = $label[0]; |
| 52 | 52 | |
| 53 | - $related_items[ $related_id ] = array( |
|
| 54 | - 'uri' => $entity_service->get_uri( $related_id ), |
|
| 53 | + $related_items[$related_id] = array( |
|
| 54 | + 'uri' => $entity_service->get_uri($related_id), |
|
| 55 | 55 | 'type' => $type, |
| 56 | 56 | 'label' => $label, |
| 57 | 57 | ); |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | * @since 3.21.0 |
| 88 | 88 | */ |
| 89 | 89 | public function enqueue_scripts() { |
| 90 | - $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 90 | + $entity_data = self::get_analytics_event_data(get_the_ID()); |
|
| 91 | 91 | // Bail early if there is no event data that we would send. |
| 92 | - if ( ! $entity_data ) { |
|
| 92 | + if ( ! $entity_data) { |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | $data = self::get_analytics_config_data(); |
| 96 | 96 | |
| 97 | 97 | // Uses the analytics code in the main WordLift plugin. |
| 98 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 98 | + wp_localize_script(self::HANDLE, 'wordliftAnalyticsConfigData', $data); |
|
| 99 | + wp_localize_script(self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data); |
|
| 100 | 100 | } |
| 101 | 101 | } |
@@ -2,6 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | // autoload.php @generated by Composer |
| 4 | 4 | |
| 5 | -require_once __DIR__ . '/composer/autoload_real.php'; |
|
| 5 | +require_once __DIR__.'/composer/autoload_real.php'; |
|
| 6 | 6 | |
| 7 | 7 | return ComposerAutoloaderInit9b4e3e175e03285e60ba6309cc2e3477::getLoader(); |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | // value. |
| 14 | 14 | const UNKNOWN = 4; |
| 15 | 15 | |
| 16 | - public static function to_string( $object_type_enum ) { |
|
| 17 | - switch ( $object_type_enum ) { |
|
| 16 | + public static function to_string($object_type_enum) { |
|
| 17 | + switch ($object_type_enum) { |
|
| 18 | 18 | case 0: |
| 19 | 19 | return 'post'; |
| 20 | 20 | case 1: |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | return null; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public static function from_string( $object_type_name ) { |
|
| 34 | - switch ( $object_type_name ) { |
|
| 33 | + public static function from_string($object_type_name) { |
|
| 34 | + switch ($object_type_name) { |
|
| 35 | 35 | case 'post': |
| 36 | 36 | return 0; |
| 37 | 37 | case 'term': |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | return 4; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function from_wordpress_instance( $instance ) { |
|
| 49 | - if ( ! is_object( $instance ) ) { |
|
| 48 | + public static function from_wordpress_instance($instance) { |
|
| 49 | + if ( ! is_object($instance)) { |
|
| 50 | 50 | return null; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - switch ( get_class( $instance ) ) { |
|
| 53 | + switch (get_class($instance)) { |
|
| 54 | 54 | case 'WP_Post': |
| 55 | 55 | return self::POST; |
| 56 | 56 | case 'WP_Term': |
@@ -4,62 +4,62 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Object_Type_Enum { |
| 6 | 6 | |
| 7 | - const POST = 0; |
|
| 8 | - const TERM = 1; |
|
| 9 | - const HOMEPAGE = 2; |
|
| 10 | - const USER = 3; |
|
| 7 | + const POST = 0; |
|
| 8 | + const TERM = 1; |
|
| 9 | + const HOMEPAGE = 2; |
|
| 10 | + const USER = 3; |
|
| 11 | 11 | |
| 12 | - // Enum constant to represent currently unknown |
|
| 13 | - // value. |
|
| 14 | - const UNKNOWN = 4; |
|
| 12 | + // Enum constant to represent currently unknown |
|
| 13 | + // value. |
|
| 14 | + const UNKNOWN = 4; |
|
| 15 | 15 | |
| 16 | - public static function to_string( $object_type_enum ) { |
|
| 17 | - switch ( $object_type_enum ) { |
|
| 18 | - case 0: |
|
| 19 | - return 'post'; |
|
| 20 | - case 1: |
|
| 21 | - return 'term'; |
|
| 22 | - case 2: |
|
| 23 | - return 'home'; |
|
| 24 | - case 3: |
|
| 25 | - return 'user'; |
|
| 26 | - case 4: |
|
| 27 | - return 'unkn'; |
|
| 28 | - } |
|
| 16 | + public static function to_string( $object_type_enum ) { |
|
| 17 | + switch ( $object_type_enum ) { |
|
| 18 | + case 0: |
|
| 19 | + return 'post'; |
|
| 20 | + case 1: |
|
| 21 | + return 'term'; |
|
| 22 | + case 2: |
|
| 23 | + return 'home'; |
|
| 24 | + case 3: |
|
| 25 | + return 'user'; |
|
| 26 | + case 4: |
|
| 27 | + return 'unkn'; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return null; |
|
| 31 | - } |
|
| 30 | + return null; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public static function from_string( $object_type_name ) { |
|
| 34 | - switch ( $object_type_name ) { |
|
| 35 | - case 'post': |
|
| 36 | - return 0; |
|
| 37 | - case 'term': |
|
| 38 | - return 1; |
|
| 39 | - case 'home': |
|
| 40 | - return 2; |
|
| 41 | - case 'user': |
|
| 42 | - return 3; |
|
| 43 | - } |
|
| 33 | + public static function from_string( $object_type_name ) { |
|
| 34 | + switch ( $object_type_name ) { |
|
| 35 | + case 'post': |
|
| 36 | + return 0; |
|
| 37 | + case 'term': |
|
| 38 | + return 1; |
|
| 39 | + case 'home': |
|
| 40 | + return 2; |
|
| 41 | + case 'user': |
|
| 42 | + return 3; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return 4; |
|
| 46 | - } |
|
| 45 | + return 4; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public static function from_wordpress_instance( $instance ) { |
|
| 49 | - if ( ! is_object( $instance ) ) { |
|
| 50 | - return null; |
|
| 51 | - } |
|
| 48 | + public static function from_wordpress_instance( $instance ) { |
|
| 49 | + if ( ! is_object( $instance ) ) { |
|
| 50 | + return null; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - switch ( get_class( $instance ) ) { |
|
| 54 | - case 'WP_Post': |
|
| 55 | - return self::POST; |
|
| 56 | - case 'WP_Term': |
|
| 57 | - return self::TERM; |
|
| 58 | - case 'WP_User': |
|
| 59 | - return self::USER; |
|
| 60 | - } |
|
| 53 | + switch ( get_class( $instance ) ) { |
|
| 54 | + case 'WP_Post': |
|
| 55 | + return self::POST; |
|
| 56 | + case 'WP_Term': |
|
| 57 | + return self::TERM; |
|
| 58 | + case 'WP_User': |
|
| 59 | + return self::USER; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return null; |
|
| 63 | - } |
|
| 62 | + return null; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -3,10 +3,10 @@ |
||
| 3 | 3 | namespace Wordlift\Api; |
| 4 | 4 | |
| 5 | 5 | interface Api_Service_Ext { |
| 6 | - /** |
|
| 7 | - * @return Me_Response |
|
| 8 | - */ |
|
| 9 | - public function me(); |
|
| 6 | + /** |
|
| 7 | + * @return Me_Response |
|
| 8 | + */ |
|
| 9 | + public function me(); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -13,492 +13,492 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class WP_Background_Process extends WP_Async_Request { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Action |
|
| 18 | - * |
|
| 19 | - * (default value: 'background_process') |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - * @access protected |
|
| 23 | - */ |
|
| 24 | - protected $action = 'background_process'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Start time of current process. |
|
| 28 | - * |
|
| 29 | - * (default value: 0) |
|
| 30 | - * |
|
| 31 | - * @var int |
|
| 32 | - * @access protected |
|
| 33 | - */ |
|
| 34 | - protected $start_time = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Cron_hook_identifier |
|
| 38 | - * |
|
| 39 | - * @var mixed |
|
| 40 | - * @access protected |
|
| 41 | - */ |
|
| 42 | - protected $cron_hook_identifier; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Cron_interval_identifier |
|
| 46 | - * |
|
| 47 | - * @var mixed |
|
| 48 | - * @access protected |
|
| 49 | - */ |
|
| 50 | - protected $cron_interval_identifier; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Initiate new background process |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - parent::__construct(); |
|
| 57 | - |
|
| 58 | - $this->cron_hook_identifier = $this->identifier . '_cron'; |
|
| 59 | - $this->cron_interval_identifier = $this->identifier . '_cron_interval'; |
|
| 60 | - |
|
| 61 | - add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); |
|
| 62 | - add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Dispatch |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function dispatch() { |
|
| 72 | - // Schedule the cron healthcheck. |
|
| 73 | - $this->schedule_event(); |
|
| 74 | - |
|
| 75 | - // Perform remote post. |
|
| 76 | - return parent::dispatch(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Push to queue |
|
| 81 | - * |
|
| 82 | - * @param mixed $data Data. |
|
| 83 | - * |
|
| 84 | - * @return $this |
|
| 85 | - */ |
|
| 86 | - public function push_to_queue( $data ) { |
|
| 87 | - $this->data[] = $data; |
|
| 88 | - |
|
| 89 | - return $this; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Save queue |
|
| 94 | - * |
|
| 95 | - * @return $this |
|
| 96 | - */ |
|
| 97 | - public function save() { |
|
| 98 | - $key = $this->generate_key(); |
|
| 99 | - |
|
| 100 | - if ( ! empty( $this->data ) ) { |
|
| 101 | - update_site_option( $key, $this->data ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $this; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Update queue |
|
| 109 | - * |
|
| 110 | - * @param string $key Key. |
|
| 111 | - * @param array $data Data. |
|
| 112 | - * |
|
| 113 | - * @return $this |
|
| 114 | - */ |
|
| 115 | - public function update( $key, $data ) { |
|
| 116 | - if ( ! empty( $data ) ) { |
|
| 117 | - update_site_option( $key, $data ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $this; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Delete queue |
|
| 125 | - * |
|
| 126 | - * @param string $key Key. |
|
| 127 | - * |
|
| 128 | - * @return $this |
|
| 129 | - */ |
|
| 130 | - public function delete( $key ) { |
|
| 131 | - delete_site_option( $key ); |
|
| 132 | - |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Generate key |
|
| 138 | - * |
|
| 139 | - * Generates a unique key based on microtime. Queue items are |
|
| 140 | - * given a unique key so that they can be merged upon save. |
|
| 141 | - * |
|
| 142 | - * @param int $length Length. |
|
| 143 | - * |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - protected function generate_key( $length = 64 ) { |
|
| 147 | - $unique = md5( microtime() . rand() ); |
|
| 148 | - $prepend = $this->identifier . '_batch_'; |
|
| 149 | - |
|
| 150 | - return substr( $prepend . $unique, 0, $length ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Maybe process queue |
|
| 155 | - * |
|
| 156 | - * Checks whether data exists within the queue and that |
|
| 157 | - * the process is not already running. |
|
| 158 | - */ |
|
| 159 | - public function maybe_handle() { |
|
| 160 | - // Don't lock up other requests while processing |
|
| 161 | - session_write_close(); |
|
| 162 | - |
|
| 163 | - if ( $this->is_process_running() ) { |
|
| 164 | - // Background process already running. |
|
| 165 | - wp_die(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ( $this->is_queue_empty() ) { |
|
| 169 | - // No data to process. |
|
| 170 | - wp_die(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
| 174 | - |
|
| 175 | - $this->handle(); |
|
| 176 | - |
|
| 177 | - wp_die(); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Is queue empty |
|
| 182 | - * |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - protected function is_queue_empty() { |
|
| 186 | - global $wpdb; |
|
| 187 | - |
|
| 188 | - $table = $wpdb->options; |
|
| 189 | - $column = ''; |
|
| 190 | - |
|
| 191 | - if ( is_multisite() ) { |
|
| 192 | - $table = $wpdb->sitemeta; |
|
| 193 | - $column = 'meta_key'; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 197 | - |
|
| 198 | - $count = $wpdb->get_var( |
|
| 199 | - $wpdb->prepare( |
|
| 200 | - "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 201 | - $key |
|
| 202 | - ) |
|
| 203 | - ); |
|
| 204 | - |
|
| 205 | - return ( $count > 0 ) ? false : true; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Is process running |
|
| 210 | - * |
|
| 211 | - * Check whether the current process is already running |
|
| 212 | - * in a background process. |
|
| 213 | - */ |
|
| 214 | - protected function is_process_running() { |
|
| 215 | - if ( get_site_transient( $this->identifier . '_process_lock' ) ) { |
|
| 216 | - // Process already running. |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Lock process |
|
| 225 | - * |
|
| 226 | - * Lock the process so that multiple instances can't run simultaneously. |
|
| 227 | - * Override if applicable, but the duration should be greater than that |
|
| 228 | - * defined in the time_exceeded() method. |
|
| 229 | - */ |
|
| 230 | - protected function lock_process() { |
|
| 231 | - $this->start_time = time(); // Set start time of current process. |
|
| 232 | - |
|
| 233 | - $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute |
|
| 234 | - $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); |
|
| 235 | - |
|
| 236 | - set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Unlock process |
|
| 241 | - * |
|
| 242 | - * Unlock the process so that other instances can spawn. |
|
| 243 | - * |
|
| 244 | - * @return $this |
|
| 245 | - */ |
|
| 246 | - protected function unlock_process() { |
|
| 247 | - delete_site_transient( $this->identifier . '_process_lock' ); |
|
| 248 | - |
|
| 249 | - return $this; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Get batch |
|
| 254 | - * |
|
| 255 | - * @return stdClass Return the first batch from the queue |
|
| 256 | - */ |
|
| 257 | - protected function get_batch() { |
|
| 258 | - global $wpdb; |
|
| 259 | - |
|
| 260 | - $table = $wpdb->options; |
|
| 261 | - $column = 'option_name'; |
|
| 262 | - $key_column = 'option_id'; |
|
| 263 | - $value_column = 'option_value'; |
|
| 264 | - |
|
| 265 | - if ( is_multisite() ) { |
|
| 266 | - $table = $wpdb->sitemeta; |
|
| 267 | - $column = 'meta_key'; |
|
| 268 | - $key_column = 'meta_id'; |
|
| 269 | - $value_column = 'meta_value'; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 273 | - |
|
| 274 | - $query = $wpdb->get_row( |
|
| 275 | - $wpdb->prepare( |
|
| 276 | - "SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 277 | - $key |
|
| 278 | - ) |
|
| 279 | - ); |
|
| 280 | - |
|
| 281 | - $batch = new stdClass(); |
|
| 282 | - $batch->key = $query->$column; |
|
| 283 | - $batch->data = maybe_unserialize( $query->$value_column ); |
|
| 284 | - |
|
| 285 | - return $batch; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Handle |
|
| 290 | - * |
|
| 291 | - * Pass each queue item to the task handler, while remaining |
|
| 292 | - * within server memory and time limit constraints. |
|
| 293 | - */ |
|
| 294 | - protected function handle() { |
|
| 295 | - $this->lock_process(); |
|
| 296 | - |
|
| 297 | - do { |
|
| 298 | - $batch = $this->get_batch(); |
|
| 299 | - |
|
| 300 | - foreach ( $batch->data as $key => $value ) { |
|
| 301 | - $task = $this->task( $value ); |
|
| 302 | - |
|
| 303 | - if ( false !== $task ) { |
|
| 304 | - $batch->data[ $key ] = $task; |
|
| 305 | - } else { |
|
| 306 | - unset( $batch->data[ $key ] ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - if ( $this->time_exceeded() || $this->memory_exceeded() ) { |
|
| 310 | - // Batch limits reached. |
|
| 311 | - break; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // Update or delete current batch. |
|
| 316 | - if ( ! empty( $batch->data ) ) { |
|
| 317 | - $this->update( $batch->key, $batch->data ); |
|
| 318 | - } else { |
|
| 319 | - $this->delete( $batch->key ); |
|
| 320 | - } |
|
| 321 | - } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); |
|
| 322 | - |
|
| 323 | - $this->unlock_process(); |
|
| 324 | - |
|
| 325 | - // Start next batch or complete process. |
|
| 326 | - if ( ! $this->is_queue_empty() ) { |
|
| 327 | - $this->dispatch(); |
|
| 328 | - } else { |
|
| 329 | - $this->complete(); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - wp_die(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Memory exceeded |
|
| 337 | - * |
|
| 338 | - * Ensures the batch process never exceeds 90% |
|
| 339 | - * of the maximum WordPress memory. |
|
| 340 | - * |
|
| 341 | - * @return bool |
|
| 342 | - */ |
|
| 343 | - protected function memory_exceeded() { |
|
| 344 | - $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory |
|
| 345 | - $current_memory = memory_get_usage( true ); |
|
| 346 | - $return = false; |
|
| 347 | - |
|
| 348 | - if ( $current_memory >= $memory_limit ) { |
|
| 349 | - $return = true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return apply_filters( $this->identifier . '_memory_exceeded', $return ); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Get memory limit |
|
| 357 | - * |
|
| 358 | - * @return int |
|
| 359 | - */ |
|
| 360 | - protected function get_memory_limit() { |
|
| 361 | - if ( function_exists( 'ini_get' ) ) { |
|
| 362 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 363 | - } else { |
|
| 364 | - // Sensible default. |
|
| 365 | - $memory_limit = '128M'; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) { |
|
| 369 | - // Unlimited, set to 32GB. |
|
| 370 | - $memory_limit = '32000M'; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - return wp_convert_hr_to_bytes( $memory_limit ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Time exceeded. |
|
| 378 | - * |
|
| 379 | - * Ensures the batch never exceeds a sensible time limit. |
|
| 380 | - * A timeout limit of 30s is common on shared hosting. |
|
| 381 | - * |
|
| 382 | - * @return bool |
|
| 383 | - */ |
|
| 384 | - protected function time_exceeded() { |
|
| 385 | - $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds |
|
| 386 | - $return = false; |
|
| 387 | - |
|
| 388 | - if ( time() >= $finish ) { |
|
| 389 | - $return = true; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return apply_filters( $this->identifier . '_time_exceeded', $return ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Complete. |
|
| 397 | - * |
|
| 398 | - * Override if applicable, but ensure that the below actions are |
|
| 399 | - * performed, or, call parent::complete(). |
|
| 400 | - */ |
|
| 401 | - protected function complete() { |
|
| 402 | - // Unschedule the cron healthcheck. |
|
| 403 | - $this->clear_scheduled_event(); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Schedule cron healthcheck |
|
| 408 | - * |
|
| 409 | - * @access public |
|
| 410 | - * |
|
| 411 | - * @param mixed $schedules Schedules. |
|
| 412 | - * |
|
| 413 | - * @return mixed |
|
| 414 | - */ |
|
| 415 | - public function schedule_cron_healthcheck( $schedules ) { |
|
| 416 | - $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); |
|
| 417 | - |
|
| 418 | - if ( property_exists( $this, 'cron_interval' ) ) { |
|
| 419 | - $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // Adds every 5 minutes to the existing schedules. |
|
| 423 | - $schedules[ $this->identifier . '_cron_interval' ] = array( |
|
| 424 | - 'interval' => MINUTE_IN_SECONDS * $interval, |
|
| 425 | - 'display' => sprintf( __( 'Every %d Minutes' ), $interval ), |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - return $schedules; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Handle cron healthcheck |
|
| 433 | - * |
|
| 434 | - * Restart the background process if not already running |
|
| 435 | - * and data exists in the queue. |
|
| 436 | - */ |
|
| 437 | - public function handle_cron_healthcheck() { |
|
| 438 | - if ( $this->is_process_running() ) { |
|
| 439 | - // Background process already running. |
|
| 440 | - exit; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if ( $this->is_queue_empty() ) { |
|
| 444 | - // No data to process. |
|
| 445 | - $this->clear_scheduled_event(); |
|
| 446 | - exit; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $this->handle(); |
|
| 450 | - |
|
| 451 | - exit; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Schedule event |
|
| 456 | - */ |
|
| 457 | - protected function schedule_event() { |
|
| 458 | - if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { |
|
| 459 | - wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Clear scheduled event |
|
| 465 | - */ |
|
| 466 | - protected function clear_scheduled_event() { |
|
| 467 | - $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); |
|
| 468 | - |
|
| 469 | - if ( $timestamp ) { |
|
| 470 | - wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Cancel Process |
|
| 476 | - * |
|
| 477 | - * Stop processing queue items, clear cronjob and delete batch. |
|
| 478 | - */ |
|
| 479 | - public function cancel_process() { |
|
| 480 | - if ( ! $this->is_queue_empty() ) { |
|
| 481 | - $batch = $this->get_batch(); |
|
| 482 | - |
|
| 483 | - $this->delete( $batch->key ); |
|
| 484 | - |
|
| 485 | - wp_clear_scheduled_hook( $this->cron_hook_identifier ); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Task |
|
| 492 | - * |
|
| 493 | - * Override this method to perform any actions required on each |
|
| 494 | - * queue item. Return the modified item for further processing |
|
| 495 | - * in the next pass through. Or, return false to remove the |
|
| 496 | - * item from the queue. |
|
| 497 | - * |
|
| 498 | - * @param mixed $item Queue item to iterate over. |
|
| 499 | - * |
|
| 500 | - * @return mixed |
|
| 501 | - */ |
|
| 502 | - abstract protected function task( $item ); |
|
| 16 | + /** |
|
| 17 | + * Action |
|
| 18 | + * |
|
| 19 | + * (default value: 'background_process') |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + * @access protected |
|
| 23 | + */ |
|
| 24 | + protected $action = 'background_process'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Start time of current process. |
|
| 28 | + * |
|
| 29 | + * (default value: 0) |
|
| 30 | + * |
|
| 31 | + * @var int |
|
| 32 | + * @access protected |
|
| 33 | + */ |
|
| 34 | + protected $start_time = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Cron_hook_identifier |
|
| 38 | + * |
|
| 39 | + * @var mixed |
|
| 40 | + * @access protected |
|
| 41 | + */ |
|
| 42 | + protected $cron_hook_identifier; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Cron_interval_identifier |
|
| 46 | + * |
|
| 47 | + * @var mixed |
|
| 48 | + * @access protected |
|
| 49 | + */ |
|
| 50 | + protected $cron_interval_identifier; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Initiate new background process |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + parent::__construct(); |
|
| 57 | + |
|
| 58 | + $this->cron_hook_identifier = $this->identifier . '_cron'; |
|
| 59 | + $this->cron_interval_identifier = $this->identifier . '_cron_interval'; |
|
| 60 | + |
|
| 61 | + add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); |
|
| 62 | + add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Dispatch |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function dispatch() { |
|
| 72 | + // Schedule the cron healthcheck. |
|
| 73 | + $this->schedule_event(); |
|
| 74 | + |
|
| 75 | + // Perform remote post. |
|
| 76 | + return parent::dispatch(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Push to queue |
|
| 81 | + * |
|
| 82 | + * @param mixed $data Data. |
|
| 83 | + * |
|
| 84 | + * @return $this |
|
| 85 | + */ |
|
| 86 | + public function push_to_queue( $data ) { |
|
| 87 | + $this->data[] = $data; |
|
| 88 | + |
|
| 89 | + return $this; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Save queue |
|
| 94 | + * |
|
| 95 | + * @return $this |
|
| 96 | + */ |
|
| 97 | + public function save() { |
|
| 98 | + $key = $this->generate_key(); |
|
| 99 | + |
|
| 100 | + if ( ! empty( $this->data ) ) { |
|
| 101 | + update_site_option( $key, $this->data ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $this; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Update queue |
|
| 109 | + * |
|
| 110 | + * @param string $key Key. |
|
| 111 | + * @param array $data Data. |
|
| 112 | + * |
|
| 113 | + * @return $this |
|
| 114 | + */ |
|
| 115 | + public function update( $key, $data ) { |
|
| 116 | + if ( ! empty( $data ) ) { |
|
| 117 | + update_site_option( $key, $data ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Delete queue |
|
| 125 | + * |
|
| 126 | + * @param string $key Key. |
|
| 127 | + * |
|
| 128 | + * @return $this |
|
| 129 | + */ |
|
| 130 | + public function delete( $key ) { |
|
| 131 | + delete_site_option( $key ); |
|
| 132 | + |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Generate key |
|
| 138 | + * |
|
| 139 | + * Generates a unique key based on microtime. Queue items are |
|
| 140 | + * given a unique key so that they can be merged upon save. |
|
| 141 | + * |
|
| 142 | + * @param int $length Length. |
|
| 143 | + * |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + protected function generate_key( $length = 64 ) { |
|
| 147 | + $unique = md5( microtime() . rand() ); |
|
| 148 | + $prepend = $this->identifier . '_batch_'; |
|
| 149 | + |
|
| 150 | + return substr( $prepend . $unique, 0, $length ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Maybe process queue |
|
| 155 | + * |
|
| 156 | + * Checks whether data exists within the queue and that |
|
| 157 | + * the process is not already running. |
|
| 158 | + */ |
|
| 159 | + public function maybe_handle() { |
|
| 160 | + // Don't lock up other requests while processing |
|
| 161 | + session_write_close(); |
|
| 162 | + |
|
| 163 | + if ( $this->is_process_running() ) { |
|
| 164 | + // Background process already running. |
|
| 165 | + wp_die(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ( $this->is_queue_empty() ) { |
|
| 169 | + // No data to process. |
|
| 170 | + wp_die(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + check_ajax_referer( $this->identifier, 'nonce' ); |
|
| 174 | + |
|
| 175 | + $this->handle(); |
|
| 176 | + |
|
| 177 | + wp_die(); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Is queue empty |
|
| 182 | + * |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + protected function is_queue_empty() { |
|
| 186 | + global $wpdb; |
|
| 187 | + |
|
| 188 | + $table = $wpdb->options; |
|
| 189 | + $column = ''; |
|
| 190 | + |
|
| 191 | + if ( is_multisite() ) { |
|
| 192 | + $table = $wpdb->sitemeta; |
|
| 193 | + $column = 'meta_key'; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 197 | + |
|
| 198 | + $count = $wpdb->get_var( |
|
| 199 | + $wpdb->prepare( |
|
| 200 | + "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 201 | + $key |
|
| 202 | + ) |
|
| 203 | + ); |
|
| 204 | + |
|
| 205 | + return ( $count > 0 ) ? false : true; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Is process running |
|
| 210 | + * |
|
| 211 | + * Check whether the current process is already running |
|
| 212 | + * in a background process. |
|
| 213 | + */ |
|
| 214 | + protected function is_process_running() { |
|
| 215 | + if ( get_site_transient( $this->identifier . '_process_lock' ) ) { |
|
| 216 | + // Process already running. |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Lock process |
|
| 225 | + * |
|
| 226 | + * Lock the process so that multiple instances can't run simultaneously. |
|
| 227 | + * Override if applicable, but the duration should be greater than that |
|
| 228 | + * defined in the time_exceeded() method. |
|
| 229 | + */ |
|
| 230 | + protected function lock_process() { |
|
| 231 | + $this->start_time = time(); // Set start time of current process. |
|
| 232 | + |
|
| 233 | + $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute |
|
| 234 | + $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); |
|
| 235 | + |
|
| 236 | + set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Unlock process |
|
| 241 | + * |
|
| 242 | + * Unlock the process so that other instances can spawn. |
|
| 243 | + * |
|
| 244 | + * @return $this |
|
| 245 | + */ |
|
| 246 | + protected function unlock_process() { |
|
| 247 | + delete_site_transient( $this->identifier . '_process_lock' ); |
|
| 248 | + |
|
| 249 | + return $this; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Get batch |
|
| 254 | + * |
|
| 255 | + * @return stdClass Return the first batch from the queue |
|
| 256 | + */ |
|
| 257 | + protected function get_batch() { |
|
| 258 | + global $wpdb; |
|
| 259 | + |
|
| 260 | + $table = $wpdb->options; |
|
| 261 | + $column = 'option_name'; |
|
| 262 | + $key_column = 'option_id'; |
|
| 263 | + $value_column = 'option_value'; |
|
| 264 | + |
|
| 265 | + if ( is_multisite() ) { |
|
| 266 | + $table = $wpdb->sitemeta; |
|
| 267 | + $column = 'meta_key'; |
|
| 268 | + $key_column = 'meta_id'; |
|
| 269 | + $value_column = 'meta_value'; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 273 | + |
|
| 274 | + $query = $wpdb->get_row( |
|
| 275 | + $wpdb->prepare( |
|
| 276 | + "SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 277 | + $key |
|
| 278 | + ) |
|
| 279 | + ); |
|
| 280 | + |
|
| 281 | + $batch = new stdClass(); |
|
| 282 | + $batch->key = $query->$column; |
|
| 283 | + $batch->data = maybe_unserialize( $query->$value_column ); |
|
| 284 | + |
|
| 285 | + return $batch; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Handle |
|
| 290 | + * |
|
| 291 | + * Pass each queue item to the task handler, while remaining |
|
| 292 | + * within server memory and time limit constraints. |
|
| 293 | + */ |
|
| 294 | + protected function handle() { |
|
| 295 | + $this->lock_process(); |
|
| 296 | + |
|
| 297 | + do { |
|
| 298 | + $batch = $this->get_batch(); |
|
| 299 | + |
|
| 300 | + foreach ( $batch->data as $key => $value ) { |
|
| 301 | + $task = $this->task( $value ); |
|
| 302 | + |
|
| 303 | + if ( false !== $task ) { |
|
| 304 | + $batch->data[ $key ] = $task; |
|
| 305 | + } else { |
|
| 306 | + unset( $batch->data[ $key ] ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + if ( $this->time_exceeded() || $this->memory_exceeded() ) { |
|
| 310 | + // Batch limits reached. |
|
| 311 | + break; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // Update or delete current batch. |
|
| 316 | + if ( ! empty( $batch->data ) ) { |
|
| 317 | + $this->update( $batch->key, $batch->data ); |
|
| 318 | + } else { |
|
| 319 | + $this->delete( $batch->key ); |
|
| 320 | + } |
|
| 321 | + } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); |
|
| 322 | + |
|
| 323 | + $this->unlock_process(); |
|
| 324 | + |
|
| 325 | + // Start next batch or complete process. |
|
| 326 | + if ( ! $this->is_queue_empty() ) { |
|
| 327 | + $this->dispatch(); |
|
| 328 | + } else { |
|
| 329 | + $this->complete(); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + wp_die(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Memory exceeded |
|
| 337 | + * |
|
| 338 | + * Ensures the batch process never exceeds 90% |
|
| 339 | + * of the maximum WordPress memory. |
|
| 340 | + * |
|
| 341 | + * @return bool |
|
| 342 | + */ |
|
| 343 | + protected function memory_exceeded() { |
|
| 344 | + $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory |
|
| 345 | + $current_memory = memory_get_usage( true ); |
|
| 346 | + $return = false; |
|
| 347 | + |
|
| 348 | + if ( $current_memory >= $memory_limit ) { |
|
| 349 | + $return = true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return apply_filters( $this->identifier . '_memory_exceeded', $return ); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Get memory limit |
|
| 357 | + * |
|
| 358 | + * @return int |
|
| 359 | + */ |
|
| 360 | + protected function get_memory_limit() { |
|
| 361 | + if ( function_exists( 'ini_get' ) ) { |
|
| 362 | + $memory_limit = ini_get( 'memory_limit' ); |
|
| 363 | + } else { |
|
| 364 | + // Sensible default. |
|
| 365 | + $memory_limit = '128M'; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) { |
|
| 369 | + // Unlimited, set to 32GB. |
|
| 370 | + $memory_limit = '32000M'; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + return wp_convert_hr_to_bytes( $memory_limit ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Time exceeded. |
|
| 378 | + * |
|
| 379 | + * Ensures the batch never exceeds a sensible time limit. |
|
| 380 | + * A timeout limit of 30s is common on shared hosting. |
|
| 381 | + * |
|
| 382 | + * @return bool |
|
| 383 | + */ |
|
| 384 | + protected function time_exceeded() { |
|
| 385 | + $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds |
|
| 386 | + $return = false; |
|
| 387 | + |
|
| 388 | + if ( time() >= $finish ) { |
|
| 389 | + $return = true; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return apply_filters( $this->identifier . '_time_exceeded', $return ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Complete. |
|
| 397 | + * |
|
| 398 | + * Override if applicable, but ensure that the below actions are |
|
| 399 | + * performed, or, call parent::complete(). |
|
| 400 | + */ |
|
| 401 | + protected function complete() { |
|
| 402 | + // Unschedule the cron healthcheck. |
|
| 403 | + $this->clear_scheduled_event(); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Schedule cron healthcheck |
|
| 408 | + * |
|
| 409 | + * @access public |
|
| 410 | + * |
|
| 411 | + * @param mixed $schedules Schedules. |
|
| 412 | + * |
|
| 413 | + * @return mixed |
|
| 414 | + */ |
|
| 415 | + public function schedule_cron_healthcheck( $schedules ) { |
|
| 416 | + $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); |
|
| 417 | + |
|
| 418 | + if ( property_exists( $this, 'cron_interval' ) ) { |
|
| 419 | + $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // Adds every 5 minutes to the existing schedules. |
|
| 423 | + $schedules[ $this->identifier . '_cron_interval' ] = array( |
|
| 424 | + 'interval' => MINUTE_IN_SECONDS * $interval, |
|
| 425 | + 'display' => sprintf( __( 'Every %d Minutes' ), $interval ), |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + return $schedules; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Handle cron healthcheck |
|
| 433 | + * |
|
| 434 | + * Restart the background process if not already running |
|
| 435 | + * and data exists in the queue. |
|
| 436 | + */ |
|
| 437 | + public function handle_cron_healthcheck() { |
|
| 438 | + if ( $this->is_process_running() ) { |
|
| 439 | + // Background process already running. |
|
| 440 | + exit; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if ( $this->is_queue_empty() ) { |
|
| 444 | + // No data to process. |
|
| 445 | + $this->clear_scheduled_event(); |
|
| 446 | + exit; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $this->handle(); |
|
| 450 | + |
|
| 451 | + exit; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Schedule event |
|
| 456 | + */ |
|
| 457 | + protected function schedule_event() { |
|
| 458 | + if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { |
|
| 459 | + wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Clear scheduled event |
|
| 465 | + */ |
|
| 466 | + protected function clear_scheduled_event() { |
|
| 467 | + $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); |
|
| 468 | + |
|
| 469 | + if ( $timestamp ) { |
|
| 470 | + wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Cancel Process |
|
| 476 | + * |
|
| 477 | + * Stop processing queue items, clear cronjob and delete batch. |
|
| 478 | + */ |
|
| 479 | + public function cancel_process() { |
|
| 480 | + if ( ! $this->is_queue_empty() ) { |
|
| 481 | + $batch = $this->get_batch(); |
|
| 482 | + |
|
| 483 | + $this->delete( $batch->key ); |
|
| 484 | + |
|
| 485 | + wp_clear_scheduled_hook( $this->cron_hook_identifier ); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Task |
|
| 492 | + * |
|
| 493 | + * Override this method to perform any actions required on each |
|
| 494 | + * queue item. Return the modified item for further processing |
|
| 495 | + * in the next pass through. Or, return false to remove the |
|
| 496 | + * item from the queue. |
|
| 497 | + * |
|
| 498 | + * @param mixed $item Queue item to iterate over. |
|
| 499 | + * |
|
| 500 | + * @return mixed |
|
| 501 | + */ |
|
| 502 | + abstract protected function task( $item ); |
|
| 503 | 503 | |
| 504 | 504 | } |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | public function __construct() { |
| 56 | 56 | parent::__construct(); |
| 57 | 57 | |
| 58 | - $this->cron_hook_identifier = $this->identifier . '_cron'; |
|
| 59 | - $this->cron_interval_identifier = $this->identifier . '_cron_interval'; |
|
| 58 | + $this->cron_hook_identifier = $this->identifier.'_cron'; |
|
| 59 | + $this->cron_interval_identifier = $this->identifier.'_cron_interval'; |
|
| 60 | 60 | |
| 61 | - add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); |
|
| 62 | - add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); |
|
| 61 | + add_action($this->cron_hook_identifier, array($this, 'handle_cron_healthcheck')); |
|
| 62 | + add_filter('cron_schedules', array($this, 'schedule_cron_healthcheck')); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return $this |
| 85 | 85 | */ |
| 86 | - public function push_to_queue( $data ) { |
|
| 86 | + public function push_to_queue($data) { |
|
| 87 | 87 | $this->data[] = $data; |
| 88 | 88 | |
| 89 | 89 | return $this; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | public function save() { |
| 98 | 98 | $key = $this->generate_key(); |
| 99 | 99 | |
| 100 | - if ( ! empty( $this->data ) ) { |
|
| 101 | - update_site_option( $key, $this->data ); |
|
| 100 | + if ( ! empty($this->data)) { |
|
| 101 | + update_site_option($key, $this->data); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $this; |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return $this |
| 114 | 114 | */ |
| 115 | - public function update( $key, $data ) { |
|
| 116 | - if ( ! empty( $data ) ) { |
|
| 117 | - update_site_option( $key, $data ); |
|
| 115 | + public function update($key, $data) { |
|
| 116 | + if ( ! empty($data)) { |
|
| 117 | + update_site_option($key, $data); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return $this; |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return $this |
| 129 | 129 | */ |
| 130 | - public function delete( $key ) { |
|
| 131 | - delete_site_option( $key ); |
|
| 130 | + public function delete($key) { |
|
| 131 | + delete_site_option($key); |
|
| 132 | 132 | |
| 133 | 133 | return $this; |
| 134 | 134 | } |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - protected function generate_key( $length = 64 ) { |
|
| 147 | - $unique = md5( microtime() . rand() ); |
|
| 148 | - $prepend = $this->identifier . '_batch_'; |
|
| 146 | + protected function generate_key($length = 64) { |
|
| 147 | + $unique = md5(microtime().rand()); |
|
| 148 | + $prepend = $this->identifier.'_batch_'; |
|
| 149 | 149 | |
| 150 | - return substr( $prepend . $unique, 0, $length ); |
|
| 150 | + return substr($prepend.$unique, 0, $length); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | // Don't lock up other requests while processing |
| 161 | 161 | session_write_close(); |
| 162 | 162 | |
| 163 | - if ( $this->is_process_running() ) { |
|
| 163 | + if ($this->is_process_running()) { |
|
| 164 | 164 | // Background process already running. |
| 165 | 165 | wp_die(); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( $this->is_queue_empty() ) { |
|
| 168 | + if ($this->is_queue_empty()) { |
|
| 169 | 169 | // No data to process. |
| 170 | 170 | wp_die(); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
| 173 | + check_ajax_referer($this->identifier, 'nonce'); |
|
| 174 | 174 | |
| 175 | 175 | $this->handle(); |
| 176 | 176 | |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | $table = $wpdb->options; |
| 189 | 189 | $column = ''; |
| 190 | 190 | |
| 191 | - if ( is_multisite() ) { |
|
| 191 | + if (is_multisite()) { |
|
| 192 | 192 | $table = $wpdb->sitemeta; |
| 193 | 193 | $column = 'meta_key'; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 196 | + $key = $wpdb->esc_like($this->identifier.'_batch_').'%'; |
|
| 197 | 197 | |
| 198 | 198 | $count = $wpdb->get_var( |
| 199 | 199 | $wpdb->prepare( |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | ) |
| 203 | 203 | ); |
| 204 | 204 | |
| 205 | - return ( $count > 0 ) ? false : true; |
|
| 205 | + return ($count > 0) ? false : true; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * in a background process. |
| 213 | 213 | */ |
| 214 | 214 | protected function is_process_running() { |
| 215 | - if ( get_site_transient( $this->identifier . '_process_lock' ) ) { |
|
| 215 | + if (get_site_transient($this->identifier.'_process_lock')) { |
|
| 216 | 216 | // Process already running. |
| 217 | 217 | return true; |
| 218 | 218 | } |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | protected function lock_process() { |
| 231 | 231 | $this->start_time = time(); // Set start time of current process. |
| 232 | 232 | |
| 233 | - $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute |
|
| 234 | - $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); |
|
| 233 | + $lock_duration = (property_exists($this, 'queue_lock_time')) ? $this->queue_lock_time : 60; // 1 minute |
|
| 234 | + $lock_duration = apply_filters($this->identifier.'_queue_lock_time', $lock_duration); |
|
| 235 | 235 | |
| 236 | - set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); |
|
| 236 | + set_site_transient($this->identifier.'_process_lock', microtime(), $lock_duration); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @return $this |
| 245 | 245 | */ |
| 246 | 246 | protected function unlock_process() { |
| 247 | - delete_site_transient( $this->identifier . '_process_lock' ); |
|
| 247 | + delete_site_transient($this->identifier.'_process_lock'); |
|
| 248 | 248 | |
| 249 | 249 | return $this; |
| 250 | 250 | } |
@@ -262,14 +262,14 @@ discard block |
||
| 262 | 262 | $key_column = 'option_id'; |
| 263 | 263 | $value_column = 'option_value'; |
| 264 | 264 | |
| 265 | - if ( is_multisite() ) { |
|
| 265 | + if (is_multisite()) { |
|
| 266 | 266 | $table = $wpdb->sitemeta; |
| 267 | 267 | $column = 'meta_key'; |
| 268 | 268 | $key_column = 'meta_id'; |
| 269 | 269 | $value_column = 'meta_value'; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; |
|
| 272 | + $key = $wpdb->esc_like($this->identifier.'_batch_').'%'; |
|
| 273 | 273 | |
| 274 | 274 | $query = $wpdb->get_row( |
| 275 | 275 | $wpdb->prepare( |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | |
| 281 | 281 | $batch = new stdClass(); |
| 282 | 282 | $batch->key = $query->$column; |
| 283 | - $batch->data = maybe_unserialize( $query->$value_column ); |
|
| 283 | + $batch->data = maybe_unserialize($query->$value_column); |
|
| 284 | 284 | |
| 285 | 285 | return $batch; |
| 286 | 286 | } |
@@ -297,33 +297,33 @@ discard block |
||
| 297 | 297 | do { |
| 298 | 298 | $batch = $this->get_batch(); |
| 299 | 299 | |
| 300 | - foreach ( $batch->data as $key => $value ) { |
|
| 301 | - $task = $this->task( $value ); |
|
| 300 | + foreach ($batch->data as $key => $value) { |
|
| 301 | + $task = $this->task($value); |
|
| 302 | 302 | |
| 303 | - if ( false !== $task ) { |
|
| 304 | - $batch->data[ $key ] = $task; |
|
| 303 | + if (false !== $task) { |
|
| 304 | + $batch->data[$key] = $task; |
|
| 305 | 305 | } else { |
| 306 | - unset( $batch->data[ $key ] ); |
|
| 306 | + unset($batch->data[$key]); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( $this->time_exceeded() || $this->memory_exceeded() ) { |
|
| 309 | + if ($this->time_exceeded() || $this->memory_exceeded()) { |
|
| 310 | 310 | // Batch limits reached. |
| 311 | 311 | break; |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // Update or delete current batch. |
| 316 | - if ( ! empty( $batch->data ) ) { |
|
| 317 | - $this->update( $batch->key, $batch->data ); |
|
| 316 | + if ( ! empty($batch->data)) { |
|
| 317 | + $this->update($batch->key, $batch->data); |
|
| 318 | 318 | } else { |
| 319 | - $this->delete( $batch->key ); |
|
| 319 | + $this->delete($batch->key); |
|
| 320 | 320 | } |
| 321 | - } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); |
|
| 321 | + } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty()); |
|
| 322 | 322 | |
| 323 | 323 | $this->unlock_process(); |
| 324 | 324 | |
| 325 | 325 | // Start next batch or complete process. |
| 326 | - if ( ! $this->is_queue_empty() ) { |
|
| 326 | + if ( ! $this->is_queue_empty()) { |
|
| 327 | 327 | $this->dispatch(); |
| 328 | 328 | } else { |
| 329 | 329 | $this->complete(); |
@@ -342,14 +342,14 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | protected function memory_exceeded() { |
| 344 | 344 | $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory |
| 345 | - $current_memory = memory_get_usage( true ); |
|
| 345 | + $current_memory = memory_get_usage(true); |
|
| 346 | 346 | $return = false; |
| 347 | 347 | |
| 348 | - if ( $current_memory >= $memory_limit ) { |
|
| 348 | + if ($current_memory >= $memory_limit) { |
|
| 349 | 349 | $return = true; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - return apply_filters( $this->identifier . '_memory_exceeded', $return ); |
|
| 352 | + return apply_filters($this->identifier.'_memory_exceeded', $return); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @return int |
| 359 | 359 | */ |
| 360 | 360 | protected function get_memory_limit() { |
| 361 | - if ( function_exists( 'ini_get' ) ) { |
|
| 362 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 361 | + if (function_exists('ini_get')) { |
|
| 362 | + $memory_limit = ini_get('memory_limit'); |
|
| 363 | 363 | } else { |
| 364 | 364 | // Sensible default. |
| 365 | 365 | $memory_limit = '128M'; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) { |
|
| 368 | + if ( ! $memory_limit || - 1 === intval($memory_limit)) { |
|
| 369 | 369 | // Unlimited, set to 32GB. |
| 370 | 370 | $memory_limit = '32000M'; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - return wp_convert_hr_to_bytes( $memory_limit ); |
|
| 373 | + return wp_convert_hr_to_bytes($memory_limit); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | * @return bool |
| 383 | 383 | */ |
| 384 | 384 | protected function time_exceeded() { |
| 385 | - $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds |
|
| 385 | + $finish = $this->start_time + apply_filters($this->identifier.'_default_time_limit', 20); // 20 seconds |
|
| 386 | 386 | $return = false; |
| 387 | 387 | |
| 388 | - if ( time() >= $finish ) { |
|
| 388 | + if (time() >= $finish) { |
|
| 389 | 389 | $return = true; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - return apply_filters( $this->identifier . '_time_exceeded', $return ); |
|
| 392 | + return apply_filters($this->identifier.'_time_exceeded', $return); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -412,17 +412,17 @@ discard block |
||
| 412 | 412 | * |
| 413 | 413 | * @return mixed |
| 414 | 414 | */ |
| 415 | - public function schedule_cron_healthcheck( $schedules ) { |
|
| 416 | - $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); |
|
| 415 | + public function schedule_cron_healthcheck($schedules) { |
|
| 416 | + $interval = apply_filters($this->identifier.'_cron_interval', 5); |
|
| 417 | 417 | |
| 418 | - if ( property_exists( $this, 'cron_interval' ) ) { |
|
| 419 | - $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); |
|
| 418 | + if (property_exists($this, 'cron_interval')) { |
|
| 419 | + $interval = apply_filters($this->identifier.'_cron_interval', $this->cron_interval); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // Adds every 5 minutes to the existing schedules. |
| 423 | - $schedules[ $this->identifier . '_cron_interval' ] = array( |
|
| 423 | + $schedules[$this->identifier.'_cron_interval'] = array( |
|
| 424 | 424 | 'interval' => MINUTE_IN_SECONDS * $interval, |
| 425 | - 'display' => sprintf( __( 'Every %d Minutes' ), $interval ), |
|
| 425 | + 'display' => sprintf(__('Every %d Minutes'), $interval), |
|
| 426 | 426 | ); |
| 427 | 427 | |
| 428 | 428 | return $schedules; |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | * and data exists in the queue. |
| 436 | 436 | */ |
| 437 | 437 | public function handle_cron_healthcheck() { |
| 438 | - if ( $this->is_process_running() ) { |
|
| 438 | + if ($this->is_process_running()) { |
|
| 439 | 439 | // Background process already running. |
| 440 | 440 | exit; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - if ( $this->is_queue_empty() ) { |
|
| 443 | + if ($this->is_queue_empty()) { |
|
| 444 | 444 | // No data to process. |
| 445 | 445 | $this->clear_scheduled_event(); |
| 446 | 446 | exit; |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | * Schedule event |
| 456 | 456 | */ |
| 457 | 457 | protected function schedule_event() { |
| 458 | - if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { |
|
| 459 | - wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); |
|
| 458 | + if ( ! wp_next_scheduled($this->cron_hook_identifier)) { |
|
| 459 | + wp_schedule_event(time(), $this->cron_interval_identifier, $this->cron_hook_identifier); |
|
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
@@ -464,10 +464,10 @@ discard block |
||
| 464 | 464 | * Clear scheduled event |
| 465 | 465 | */ |
| 466 | 466 | protected function clear_scheduled_event() { |
| 467 | - $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); |
|
| 467 | + $timestamp = wp_next_scheduled($this->cron_hook_identifier); |
|
| 468 | 468 | |
| 469 | - if ( $timestamp ) { |
|
| 470 | - wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); |
|
| 469 | + if ($timestamp) { |
|
| 470 | + wp_unschedule_event($timestamp, $this->cron_hook_identifier); |
|
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | |
@@ -477,12 +477,12 @@ discard block |
||
| 477 | 477 | * Stop processing queue items, clear cronjob and delete batch. |
| 478 | 478 | */ |
| 479 | 479 | public function cancel_process() { |
| 480 | - if ( ! $this->is_queue_empty() ) { |
|
| 480 | + if ( ! $this->is_queue_empty()) { |
|
| 481 | 481 | $batch = $this->get_batch(); |
| 482 | 482 | |
| 483 | - $this->delete( $batch->key ); |
|
| 483 | + $this->delete($batch->key); |
|
| 484 | 484 | |
| 485 | - wp_clear_scheduled_hook( $this->cron_hook_identifier ); |
|
| 485 | + wp_clear_scheduled_hook($this->cron_hook_identifier); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | } |
@@ -499,6 +499,6 @@ discard block |
||
| 499 | 499 | * |
| 500 | 500 | * @return mixed |
| 501 | 501 | */ |
| 502 | - abstract protected function task( $item ); |
|
| 502 | + abstract protected function task($item); |
|
| 503 | 503 | |
| 504 | 504 | } |
@@ -5,22 +5,22 @@ |
||
| 5 | 5 | $issues = array(); |
| 6 | 6 | |
| 7 | 7 | if ( ! ( PHP_VERSION_ID >= 50200 ) ) { |
| 8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( $issues ) { |
| 12 | - if ( ! headers_sent() ) { |
|
| 13 | - header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 14 | - } |
|
| 15 | - if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | - fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | - } elseif ( ! headers_sent() ) { |
|
| 19 | - echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - trigger_error( |
|
| 23 | - 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 24 | - E_USER_ERROR |
|
| 25 | - ); |
|
| 12 | + if ( ! headers_sent() ) { |
|
| 13 | + header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 14 | + } |
|
| 15 | + if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | + if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | + fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | + } elseif ( ! headers_sent() ) { |
|
| 19 | + echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + trigger_error( |
|
| 23 | + 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 24 | + E_USER_ERROR |
|
| 25 | + ); |
|
| 26 | 26 | } |
@@ -4,23 +4,23 @@ |
||
| 4 | 4 | |
| 5 | 5 | $issues = array(); |
| 6 | 6 | |
| 7 | -if ( ! ( PHP_VERSION_ID >= 50200 ) ) { |
|
| 8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 7 | +if ( ! (PHP_VERSION_ID >= 50200)) { |
|
| 8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running '.PHP_VERSION.'.'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | -if ( $issues ) { |
|
| 12 | - if ( ! headers_sent() ) { |
|
| 13 | - header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 11 | +if ($issues) { |
|
| 12 | + if ( ! headers_sent()) { |
|
| 13 | + header('HTTP/1.1 500 Internal Server Error'); |
|
| 14 | 14 | } |
| 15 | - if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | - fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | - } elseif ( ! headers_sent() ) { |
|
| 19 | - echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 15 | + if ( ! ini_get('display_errors')) { |
|
| 16 | + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
| 17 | + fwrite(STDERR, 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.implode(PHP_EOL, $issues).PHP_EOL.PHP_EOL); |
|
| 18 | + } elseif ( ! headers_sent()) { |
|
| 19 | + echo 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)).PHP_EOL.PHP_EOL; |
|
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | trigger_error( |
| 23 | - 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 23 | + 'Composer detected issues in your platform: '.implode(' ', $issues), |
|
| 24 | 24 | E_USER_ERROR |
| 25 | 25 | ); |
| 26 | 26 | } |
@@ -42,375 +42,375 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | class ClassLoader { |
| 44 | 44 | |
| 45 | - // PSR-4 |
|
| 46 | - private $prefixLengthsPsr4 = array(); |
|
| 47 | - private $prefixDirsPsr4 = array(); |
|
| 48 | - private $fallbackDirsPsr4 = array(); |
|
| 49 | - |
|
| 50 | - // PSR-0 |
|
| 51 | - private $prefixesPsr0 = array(); |
|
| 52 | - private $fallbackDirsPsr0 = array(); |
|
| 53 | - |
|
| 54 | - private $useIncludePath = false; |
|
| 55 | - private $classMap = array(); |
|
| 56 | - private $classMapAuthoritative = false; |
|
| 57 | - private $missingClasses = array(); |
|
| 58 | - private $apcuPrefix; |
|
| 59 | - |
|
| 60 | - public function getPrefixes() { |
|
| 61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return array(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function getPrefixesPsr4() { |
|
| 69 | - return $this->prefixDirsPsr4; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function getFallbackDirs() { |
|
| 73 | - return $this->fallbackDirsPsr0; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getFallbackDirsPsr4() { |
|
| 77 | - return $this->fallbackDirsPsr4; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function getClassMap() { |
|
| 81 | - return $this->classMap; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param array $classMap Class to filename map |
|
| 86 | - */ |
|
| 87 | - public function addClassMap( array $classMap ) { |
|
| 88 | - if ( $this->classMap ) { |
|
| 89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 90 | - } else { |
|
| 91 | - $this->classMap = $classMap; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Registers a set of PSR-0 directories for a given prefix, either |
|
| 97 | - * appending or prepending to the ones previously set for this prefix. |
|
| 98 | - * |
|
| 99 | - * @param string $prefix The prefix |
|
| 100 | - * @param array|string $paths The PSR-0 root directories |
|
| 101 | - * @param bool $prepend Whether to prepend the directories |
|
| 102 | - */ |
|
| 103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | - if ( ! $prefix ) { |
|
| 105 | - if ( $prepend ) { |
|
| 106 | - $this->fallbackDirsPsr0 = array_merge( |
|
| 107 | - (array) $paths, |
|
| 108 | - $this->fallbackDirsPsr0 |
|
| 109 | - ); |
|
| 110 | - } else { |
|
| 111 | - $this->fallbackDirsPsr0 = array_merge( |
|
| 112 | - $this->fallbackDirsPsr0, |
|
| 113 | - (array) $paths |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $first = $prefix[0]; |
|
| 121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 123 | - |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - if ( $prepend ) { |
|
| 127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 128 | - (array) $paths, |
|
| 129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 130 | - ); |
|
| 131 | - } else { |
|
| 132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 134 | - (array) $paths |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Registers a set of PSR-4 directories for a given namespace, either |
|
| 141 | - * appending or prepending to the ones previously set for this namespace. |
|
| 142 | - * |
|
| 143 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 144 | - * @param array|string $paths The PSR-4 base directories |
|
| 145 | - * @param bool $prepend Whether to prepend the directories |
|
| 146 | - * |
|
| 147 | - * @throws \InvalidArgumentException |
|
| 148 | - */ |
|
| 149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | - if ( ! $prefix ) { |
|
| 151 | - // Register directories for the root namespace. |
|
| 152 | - if ( $prepend ) { |
|
| 153 | - $this->fallbackDirsPsr4 = array_merge( |
|
| 154 | - (array) $paths, |
|
| 155 | - $this->fallbackDirsPsr4 |
|
| 156 | - ); |
|
| 157 | - } else { |
|
| 158 | - $this->fallbackDirsPsr4 = array_merge( |
|
| 159 | - $this->fallbackDirsPsr4, |
|
| 160 | - (array) $paths |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 164 | - // Register directories for a new namespace. |
|
| 165 | - $length = strlen( $prefix ); |
|
| 166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 168 | - } |
|
| 169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | - } elseif ( $prepend ) { |
|
| 172 | - // Prepend directories for an already registered namespace. |
|
| 173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 174 | - (array) $paths, |
|
| 175 | - $this->prefixDirsPsr4[ $prefix ] |
|
| 176 | - ); |
|
| 177 | - } else { |
|
| 178 | - // Append directories for an already registered namespace. |
|
| 179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | - $this->prefixDirsPsr4[ $prefix ], |
|
| 181 | - (array) $paths |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Registers a set of PSR-0 directories for a given prefix, |
|
| 188 | - * replacing any others previously set for this prefix. |
|
| 189 | - * |
|
| 190 | - * @param string $prefix The prefix |
|
| 191 | - * @param array|string $paths The PSR-0 base directories |
|
| 192 | - */ |
|
| 193 | - public function set( $prefix, $paths ) { |
|
| 194 | - if ( ! $prefix ) { |
|
| 195 | - $this->fallbackDirsPsr0 = (array) $paths; |
|
| 196 | - } else { |
|
| 197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Registers a set of PSR-4 directories for a given namespace, |
|
| 203 | - * replacing any others previously set for this namespace. |
|
| 204 | - * |
|
| 205 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 206 | - * @param array|string $paths The PSR-4 base directories |
|
| 207 | - * |
|
| 208 | - * @throws \InvalidArgumentException |
|
| 209 | - */ |
|
| 210 | - public function setPsr4( $prefix, $paths ) { |
|
| 211 | - if ( ! $prefix ) { |
|
| 212 | - $this->fallbackDirsPsr4 = (array) $paths; |
|
| 213 | - } else { |
|
| 214 | - $length = strlen( $prefix ); |
|
| 215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 217 | - } |
|
| 218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Turns on searching the include path for class files. |
|
| 225 | - * |
|
| 226 | - * @param bool $useIncludePath |
|
| 227 | - */ |
|
| 228 | - public function setUseIncludePath( $useIncludePath ) { |
|
| 229 | - $this->useIncludePath = $useIncludePath; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Can be used to check if the autoloader uses the include path to check |
|
| 234 | - * for classes. |
|
| 235 | - * |
|
| 236 | - * @return bool |
|
| 237 | - */ |
|
| 238 | - public function getUseIncludePath() { |
|
| 239 | - return $this->useIncludePath; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Turns off searching the prefix and fallback directories for classes |
|
| 244 | - * that have not been registered with the class map. |
|
| 245 | - * |
|
| 246 | - * @param bool $classMapAuthoritative |
|
| 247 | - */ |
|
| 248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 249 | - $this->classMapAuthoritative = $classMapAuthoritative; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Should class lookup fail if not found in the current class map? |
|
| 254 | - * |
|
| 255 | - * @return bool |
|
| 256 | - */ |
|
| 257 | - public function isClassMapAuthoritative() { |
|
| 258 | - return $this->classMapAuthoritative; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
| 263 | - * |
|
| 264 | - * @param string|null $apcuPrefix |
|
| 265 | - */ |
|
| 266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * The APCu prefix in use, or null if APCu caching is not enabled. |
|
| 272 | - * |
|
| 273 | - * @return string|null |
|
| 274 | - */ |
|
| 275 | - public function getApcuPrefix() { |
|
| 276 | - return $this->apcuPrefix; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Registers this instance as an autoloader. |
|
| 281 | - * |
|
| 282 | - * @param bool $prepend Whether to prepend the autoloader or not |
|
| 283 | - */ |
|
| 284 | - public function register( $prepend = false ) { |
|
| 285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Unregisters this instance as an autoloader. |
|
| 290 | - */ |
|
| 291 | - public function unregister() { |
|
| 292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Loads the given class or interface. |
|
| 297 | - * |
|
| 298 | - * @param string $class The name of the class |
|
| 299 | - * @return bool|null True if loaded, null otherwise |
|
| 300 | - */ |
|
| 301 | - public function loadClass( $class ) { |
|
| 302 | - if ( $file = $this->findFile( $class ) ) { |
|
| 303 | - includeFile( $file ); |
|
| 304 | - |
|
| 305 | - return true; |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Finds the path to the file where the class is defined. |
|
| 311 | - * |
|
| 312 | - * @param string $class The name of the class |
|
| 313 | - * |
|
| 314 | - * @return string|false The path if found, false otherwise |
|
| 315 | - */ |
|
| 316 | - public function findFile( $class ) { |
|
| 317 | - // class map lookup |
|
| 318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | - return $this->classMap[ $class ]; |
|
| 320 | - } |
|
| 321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - if ( null !== $this->apcuPrefix ) { |
|
| 325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | - if ( $hit ) { |
|
| 327 | - return $file; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 332 | - |
|
| 333 | - // Search for Hack files if we are running on HHVM |
|
| 334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( null !== $this->apcuPrefix ) { |
|
| 339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if ( false === $file ) { |
|
| 343 | - // Remember that this class does not exist. |
|
| 344 | - $this->missingClasses[ $class ] = true; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $file; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - private function findFileWithExtension( $class, $ext ) { |
|
| 351 | - // PSR-4 lookup |
|
| 352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 353 | - |
|
| 354 | - $first = $class[0]; |
|
| 355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 356 | - $subPath = $class; |
|
| 357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | - $search = $subPath . '\\'; |
|
| 360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 364 | - return $file; |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // PSR-4 fallback dirs |
|
| 372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 374 | - return $file; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // PSR-0 lookup |
|
| 379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 380 | - // namespaced class name |
|
| 381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 383 | - } else { |
|
| 384 | - // PEAR-like class name |
|
| 385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | - foreach ( $dirs as $dir ) { |
|
| 392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 393 | - return $file; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // PSR-0 fallback dirs |
|
| 401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 403 | - return $file; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - // PSR-0 include paths. |
|
| 408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 409 | - return $file; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 45 | + // PSR-4 |
|
| 46 | + private $prefixLengthsPsr4 = array(); |
|
| 47 | + private $prefixDirsPsr4 = array(); |
|
| 48 | + private $fallbackDirsPsr4 = array(); |
|
| 49 | + |
|
| 50 | + // PSR-0 |
|
| 51 | + private $prefixesPsr0 = array(); |
|
| 52 | + private $fallbackDirsPsr0 = array(); |
|
| 53 | + |
|
| 54 | + private $useIncludePath = false; |
|
| 55 | + private $classMap = array(); |
|
| 56 | + private $classMapAuthoritative = false; |
|
| 57 | + private $missingClasses = array(); |
|
| 58 | + private $apcuPrefix; |
|
| 59 | + |
|
| 60 | + public function getPrefixes() { |
|
| 61 | + if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | + return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return array(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function getPrefixesPsr4() { |
|
| 69 | + return $this->prefixDirsPsr4; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function getFallbackDirs() { |
|
| 73 | + return $this->fallbackDirsPsr0; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getFallbackDirsPsr4() { |
|
| 77 | + return $this->fallbackDirsPsr4; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function getClassMap() { |
|
| 81 | + return $this->classMap; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param array $classMap Class to filename map |
|
| 86 | + */ |
|
| 87 | + public function addClassMap( array $classMap ) { |
|
| 88 | + if ( $this->classMap ) { |
|
| 89 | + $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 90 | + } else { |
|
| 91 | + $this->classMap = $classMap; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Registers a set of PSR-0 directories for a given prefix, either |
|
| 97 | + * appending or prepending to the ones previously set for this prefix. |
|
| 98 | + * |
|
| 99 | + * @param string $prefix The prefix |
|
| 100 | + * @param array|string $paths The PSR-0 root directories |
|
| 101 | + * @param bool $prepend Whether to prepend the directories |
|
| 102 | + */ |
|
| 103 | + public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | + if ( ! $prefix ) { |
|
| 105 | + if ( $prepend ) { |
|
| 106 | + $this->fallbackDirsPsr0 = array_merge( |
|
| 107 | + (array) $paths, |
|
| 108 | + $this->fallbackDirsPsr0 |
|
| 109 | + ); |
|
| 110 | + } else { |
|
| 111 | + $this->fallbackDirsPsr0 = array_merge( |
|
| 112 | + $this->fallbackDirsPsr0, |
|
| 113 | + (array) $paths |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $first = $prefix[0]; |
|
| 121 | + if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | + $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 123 | + |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + if ( $prepend ) { |
|
| 127 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 128 | + (array) $paths, |
|
| 129 | + $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 130 | + ); |
|
| 131 | + } else { |
|
| 132 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | + $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 134 | + (array) $paths |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Registers a set of PSR-4 directories for a given namespace, either |
|
| 141 | + * appending or prepending to the ones previously set for this namespace. |
|
| 142 | + * |
|
| 143 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 144 | + * @param array|string $paths The PSR-4 base directories |
|
| 145 | + * @param bool $prepend Whether to prepend the directories |
|
| 146 | + * |
|
| 147 | + * @throws \InvalidArgumentException |
|
| 148 | + */ |
|
| 149 | + public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | + if ( ! $prefix ) { |
|
| 151 | + // Register directories for the root namespace. |
|
| 152 | + if ( $prepend ) { |
|
| 153 | + $this->fallbackDirsPsr4 = array_merge( |
|
| 154 | + (array) $paths, |
|
| 155 | + $this->fallbackDirsPsr4 |
|
| 156 | + ); |
|
| 157 | + } else { |
|
| 158 | + $this->fallbackDirsPsr4 = array_merge( |
|
| 159 | + $this->fallbackDirsPsr4, |
|
| 160 | + (array) $paths |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 164 | + // Register directories for a new namespace. |
|
| 165 | + $length = strlen( $prefix ); |
|
| 166 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 168 | + } |
|
| 169 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | + } elseif ( $prepend ) { |
|
| 172 | + // Prepend directories for an already registered namespace. |
|
| 173 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 174 | + (array) $paths, |
|
| 175 | + $this->prefixDirsPsr4[ $prefix ] |
|
| 176 | + ); |
|
| 177 | + } else { |
|
| 178 | + // Append directories for an already registered namespace. |
|
| 179 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | + $this->prefixDirsPsr4[ $prefix ], |
|
| 181 | + (array) $paths |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Registers a set of PSR-0 directories for a given prefix, |
|
| 188 | + * replacing any others previously set for this prefix. |
|
| 189 | + * |
|
| 190 | + * @param string $prefix The prefix |
|
| 191 | + * @param array|string $paths The PSR-0 base directories |
|
| 192 | + */ |
|
| 193 | + public function set( $prefix, $paths ) { |
|
| 194 | + if ( ! $prefix ) { |
|
| 195 | + $this->fallbackDirsPsr0 = (array) $paths; |
|
| 196 | + } else { |
|
| 197 | + $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Registers a set of PSR-4 directories for a given namespace, |
|
| 203 | + * replacing any others previously set for this namespace. |
|
| 204 | + * |
|
| 205 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 206 | + * @param array|string $paths The PSR-4 base directories |
|
| 207 | + * |
|
| 208 | + * @throws \InvalidArgumentException |
|
| 209 | + */ |
|
| 210 | + public function setPsr4( $prefix, $paths ) { |
|
| 211 | + if ( ! $prefix ) { |
|
| 212 | + $this->fallbackDirsPsr4 = (array) $paths; |
|
| 213 | + } else { |
|
| 214 | + $length = strlen( $prefix ); |
|
| 215 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 217 | + } |
|
| 218 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Turns on searching the include path for class files. |
|
| 225 | + * |
|
| 226 | + * @param bool $useIncludePath |
|
| 227 | + */ |
|
| 228 | + public function setUseIncludePath( $useIncludePath ) { |
|
| 229 | + $this->useIncludePath = $useIncludePath; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Can be used to check if the autoloader uses the include path to check |
|
| 234 | + * for classes. |
|
| 235 | + * |
|
| 236 | + * @return bool |
|
| 237 | + */ |
|
| 238 | + public function getUseIncludePath() { |
|
| 239 | + return $this->useIncludePath; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Turns off searching the prefix and fallback directories for classes |
|
| 244 | + * that have not been registered with the class map. |
|
| 245 | + * |
|
| 246 | + * @param bool $classMapAuthoritative |
|
| 247 | + */ |
|
| 248 | + public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 249 | + $this->classMapAuthoritative = $classMapAuthoritative; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Should class lookup fail if not found in the current class map? |
|
| 254 | + * |
|
| 255 | + * @return bool |
|
| 256 | + */ |
|
| 257 | + public function isClassMapAuthoritative() { |
|
| 258 | + return $this->classMapAuthoritative; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
| 263 | + * |
|
| 264 | + * @param string|null $apcuPrefix |
|
| 265 | + */ |
|
| 266 | + public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | + $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * The APCu prefix in use, or null if APCu caching is not enabled. |
|
| 272 | + * |
|
| 273 | + * @return string|null |
|
| 274 | + */ |
|
| 275 | + public function getApcuPrefix() { |
|
| 276 | + return $this->apcuPrefix; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Registers this instance as an autoloader. |
|
| 281 | + * |
|
| 282 | + * @param bool $prepend Whether to prepend the autoloader or not |
|
| 283 | + */ |
|
| 284 | + public function register( $prepend = false ) { |
|
| 285 | + spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Unregisters this instance as an autoloader. |
|
| 290 | + */ |
|
| 291 | + public function unregister() { |
|
| 292 | + spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Loads the given class or interface. |
|
| 297 | + * |
|
| 298 | + * @param string $class The name of the class |
|
| 299 | + * @return bool|null True if loaded, null otherwise |
|
| 300 | + */ |
|
| 301 | + public function loadClass( $class ) { |
|
| 302 | + if ( $file = $this->findFile( $class ) ) { |
|
| 303 | + includeFile( $file ); |
|
| 304 | + |
|
| 305 | + return true; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Finds the path to the file where the class is defined. |
|
| 311 | + * |
|
| 312 | + * @param string $class The name of the class |
|
| 313 | + * |
|
| 314 | + * @return string|false The path if found, false otherwise |
|
| 315 | + */ |
|
| 316 | + public function findFile( $class ) { |
|
| 317 | + // class map lookup |
|
| 318 | + if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | + return $this->classMap[ $class ]; |
|
| 320 | + } |
|
| 321 | + if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + if ( null !== $this->apcuPrefix ) { |
|
| 325 | + $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | + if ( $hit ) { |
|
| 327 | + return $file; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 332 | + |
|
| 333 | + // Search for Hack files if we are running on HHVM |
|
| 334 | + if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | + $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( null !== $this->apcuPrefix ) { |
|
| 339 | + apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if ( false === $file ) { |
|
| 343 | + // Remember that this class does not exist. |
|
| 344 | + $this->missingClasses[ $class ] = true; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $file; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + private function findFileWithExtension( $class, $ext ) { |
|
| 351 | + // PSR-4 lookup |
|
| 352 | + $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 353 | + |
|
| 354 | + $first = $class[0]; |
|
| 355 | + if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 356 | + $subPath = $class; |
|
| 357 | + while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | + $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | + $search = $subPath . '\\'; |
|
| 360 | + if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | + $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | + foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | + if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 364 | + return $file; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // PSR-4 fallback dirs |
|
| 372 | + foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 374 | + return $file; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // PSR-0 lookup |
|
| 379 | + if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 380 | + // namespaced class name |
|
| 381 | + $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | + . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 383 | + } else { |
|
| 384 | + // PEAR-like class name |
|
| 385 | + $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | + foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | + if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | + foreach ( $dirs as $dir ) { |
|
| 392 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 393 | + return $file; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // PSR-0 fallback dirs |
|
| 401 | + foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 403 | + return $file; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + // PSR-0 include paths. |
|
| 408 | + if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 409 | + return $file; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -419,5 +419,5 @@ discard block |
||
| 419 | 419 | * Prevents access to $this/self from included files. |
| 420 | 420 | */ |
| 421 | 421 | function includeFile( $file ) { |
| 422 | - include $file; |
|
| 422 | + include $file; |
|
| 423 | 423 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | private $apcuPrefix; |
| 59 | 59 | |
| 60 | 60 | public function getPrefixes() { |
| 61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 61 | + if ( ! empty($this->prefixesPsr0)) { |
|
| 62 | + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return array(); |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * @param array $classMap Class to filename map |
| 86 | 86 | */ |
| 87 | - public function addClassMap( array $classMap ) { |
|
| 88 | - if ( $this->classMap ) { |
|
| 89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 87 | + public function addClassMap(array $classMap) { |
|
| 88 | + if ($this->classMap) { |
|
| 89 | + $this->classMap = array_merge($this->classMap, $classMap); |
|
| 90 | 90 | } else { |
| 91 | 91 | $this->classMap = $classMap; |
| 92 | 92 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @param array|string $paths The PSR-0 root directories |
| 101 | 101 | * @param bool $prepend Whether to prepend the directories |
| 102 | 102 | */ |
| 103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | - if ( ! $prefix ) { |
|
| 105 | - if ( $prepend ) { |
|
| 103 | + public function add($prefix, $paths, $prepend = false) { |
|
| 104 | + if ( ! $prefix) { |
|
| 105 | + if ($prepend) { |
|
| 106 | 106 | $this->fallbackDirsPsr0 = array_merge( |
| 107 | 107 | (array) $paths, |
| 108 | 108 | $this->fallbackDirsPsr0 |
@@ -118,19 +118,19 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $first = $prefix[0]; |
| 121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 121 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
| 122 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
| 123 | 123 | |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | - if ( $prepend ) { |
|
| 127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 126 | + if ($prepend) { |
|
| 127 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
| 128 | 128 | (array) $paths, |
| 129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 129 | + $this->prefixesPsr0[$first][$prefix] |
|
| 130 | 130 | ); |
| 131 | 131 | } else { |
| 132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 132 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
| 133 | + $this->prefixesPsr0[$first][$prefix], |
|
| 134 | 134 | (array) $paths |
| 135 | 135 | ); |
| 136 | 136 | } |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @throws \InvalidArgumentException |
| 148 | 148 | */ |
| 149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | - if ( ! $prefix ) { |
|
| 149 | + public function addPsr4($prefix, $paths, $prepend = false) { |
|
| 150 | + if ( ! $prefix) { |
|
| 151 | 151 | // Register directories for the root namespace. |
| 152 | - if ( $prepend ) { |
|
| 152 | + if ($prepend) { |
|
| 153 | 153 | $this->fallbackDirsPsr4 = array_merge( |
| 154 | 154 | (array) $paths, |
| 155 | 155 | $this->fallbackDirsPsr4 |
@@ -160,24 +160,24 @@ discard block |
||
| 160 | 160 | (array) $paths |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 163 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
| 164 | 164 | // Register directories for a new namespace. |
| 165 | - $length = strlen( $prefix ); |
|
| 166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 165 | + $length = strlen($prefix); |
|
| 166 | + if ('\\' !== $prefix[$length - 1]) { |
|
| 167 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
| 168 | 168 | } |
| 169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | - } elseif ( $prepend ) { |
|
| 169 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
| 170 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
| 171 | + } elseif ($prepend) { |
|
| 172 | 172 | // Prepend directories for an already registered namespace. |
| 173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 173 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
| 174 | 174 | (array) $paths, |
| 175 | - $this->prefixDirsPsr4[ $prefix ] |
|
| 175 | + $this->prefixDirsPsr4[$prefix] |
|
| 176 | 176 | ); |
| 177 | 177 | } else { |
| 178 | 178 | // Append directories for an already registered namespace. |
| 179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | - $this->prefixDirsPsr4[ $prefix ], |
|
| 179 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
| 180 | + $this->prefixDirsPsr4[$prefix], |
|
| 181 | 181 | (array) $paths |
| 182 | 182 | ); |
| 183 | 183 | } |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | * @param string $prefix The prefix |
| 191 | 191 | * @param array|string $paths The PSR-0 base directories |
| 192 | 192 | */ |
| 193 | - public function set( $prefix, $paths ) { |
|
| 194 | - if ( ! $prefix ) { |
|
| 193 | + public function set($prefix, $paths) { |
|
| 194 | + if ( ! $prefix) { |
|
| 195 | 195 | $this->fallbackDirsPsr0 = (array) $paths; |
| 196 | 196 | } else { |
| 197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 197 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -207,16 +207,16 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @throws \InvalidArgumentException |
| 209 | 209 | */ |
| 210 | - public function setPsr4( $prefix, $paths ) { |
|
| 211 | - if ( ! $prefix ) { |
|
| 210 | + public function setPsr4($prefix, $paths) { |
|
| 211 | + if ( ! $prefix) { |
|
| 212 | 212 | $this->fallbackDirsPsr4 = (array) $paths; |
| 213 | 213 | } else { |
| 214 | - $length = strlen( $prefix ); |
|
| 215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 214 | + $length = strlen($prefix); |
|
| 215 | + if ('\\' !== $prefix[$length - 1]) { |
|
| 216 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
| 217 | 217 | } |
| 218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 218 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
| 219 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @param bool $useIncludePath |
| 227 | 227 | */ |
| 228 | - public function setUseIncludePath( $useIncludePath ) { |
|
| 228 | + public function setUseIncludePath($useIncludePath) { |
|
| 229 | 229 | $this->useIncludePath = $useIncludePath; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @param bool $classMapAuthoritative |
| 247 | 247 | */ |
| 248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 248 | + public function setClassMapAuthoritative($classMapAuthoritative) { |
|
| 249 | 249 | $this->classMapAuthoritative = $classMapAuthoritative; |
| 250 | 250 | } |
| 251 | 251 | |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @param string|null $apcuPrefix |
| 265 | 265 | */ |
| 266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 266 | + public function setApcuPrefix($apcuPrefix) { |
|
| 267 | + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -281,15 +281,15 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @param bool $prepend Whether to prepend the autoloader or not |
| 283 | 283 | */ |
| 284 | - public function register( $prepend = false ) { |
|
| 285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 284 | + public function register($prepend = false) { |
|
| 285 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Unregisters this instance as an autoloader. |
| 290 | 290 | */ |
| 291 | 291 | public function unregister() { |
| 292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 292 | + spl_autoload_unregister(array($this, 'loadClass')); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | * @param string $class The name of the class |
| 299 | 299 | * @return bool|null True if loaded, null otherwise |
| 300 | 300 | */ |
| 301 | - public function loadClass( $class ) { |
|
| 302 | - if ( $file = $this->findFile( $class ) ) { |
|
| 303 | - includeFile( $file ); |
|
| 301 | + public function loadClass($class) { |
|
| 302 | + if ($file = $this->findFile($class)) { |
|
| 303 | + includeFile($file); |
|
| 304 | 304 | |
| 305 | 305 | return true; |
| 306 | 306 | } |
@@ -313,54 +313,54 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @return string|false The path if found, false otherwise |
| 315 | 315 | */ |
| 316 | - public function findFile( $class ) { |
|
| 316 | + public function findFile($class) { |
|
| 317 | 317 | // class map lookup |
| 318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | - return $this->classMap[ $class ]; |
|
| 318 | + if (isset($this->classMap[$class])) { |
|
| 319 | + return $this->classMap[$class]; |
|
| 320 | 320 | } |
| 321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 321 | + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { |
|
| 322 | 322 | return false; |
| 323 | 323 | } |
| 324 | - if ( null !== $this->apcuPrefix ) { |
|
| 325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | - if ( $hit ) { |
|
| 324 | + if (null !== $this->apcuPrefix) { |
|
| 325 | + $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
| 326 | + if ($hit) { |
|
| 327 | 327 | return $file; |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 331 | + $file = $this->findFileWithExtension($class, '.php'); |
|
| 332 | 332 | |
| 333 | 333 | // Search for Hack files if we are running on HHVM |
| 334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 334 | + if (false === $file && defined('HHVM_VERSION')) { |
|
| 335 | + $file = $this->findFileWithExtension($class, '.hh'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( null !== $this->apcuPrefix ) { |
|
| 339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 338 | + if (null !== $this->apcuPrefix) { |
|
| 339 | + apcu_add($this->apcuPrefix.$class, $file); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( false === $file ) { |
|
| 342 | + if (false === $file) { |
|
| 343 | 343 | // Remember that this class does not exist. |
| 344 | - $this->missingClasses[ $class ] = true; |
|
| 344 | + $this->missingClasses[$class] = true; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | return $file; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - private function findFileWithExtension( $class, $ext ) { |
|
| 350 | + private function findFileWithExtension($class, $ext) { |
|
| 351 | 351 | // PSR-4 lookup |
| 352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 352 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 353 | 353 | |
| 354 | 354 | $first = $class[0]; |
| 355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 355 | + if (isset($this->prefixLengthsPsr4[$first])) { |
|
| 356 | 356 | $subPath = $class; |
| 357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | - $search = $subPath . '\\'; |
|
| 360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 357 | + while (false !== $lastPos = strrpos($subPath, '\\')) { |
|
| 358 | + $subPath = substr($subPath, 0, $lastPos); |
|
| 359 | + $search = $subPath.'\\'; |
|
| 360 | + if (isset($this->prefixDirsPsr4[$search])) { |
|
| 361 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 362 | + foreach ($this->prefixDirsPsr4[$search] as $dir) { |
|
| 363 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 364 | 364 | return $file; |
| 365 | 365 | } |
| 366 | 366 | } |
@@ -369,27 +369,27 @@ discard block |
||
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // PSR-4 fallback dirs |
| 372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 372 | + foreach ($this->fallbackDirsPsr4 as $dir) { |
|
| 373 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 374 | 374 | return $file; |
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | // PSR-0 lookup |
| 379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 379 | + if (false !== $pos = strrpos($class, '\\')) { |
|
| 380 | 380 | // namespaced class name |
| 381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 381 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
| 382 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
| 383 | 383 | } else { |
| 384 | 384 | // PEAR-like class name |
| 385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 385 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | - foreach ( $dirs as $dir ) { |
|
| 392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 388 | + if (isset($this->prefixesPsr0[$first])) { |
|
| 389 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
| 390 | + if (0 === strpos($class, $prefix)) { |
|
| 391 | + foreach ($dirs as $dir) { |
|
| 392 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 393 | 393 | return $file; |
| 394 | 394 | } |
| 395 | 395 | } |
@@ -398,14 +398,14 @@ discard block |
||
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // PSR-0 fallback dirs |
| 401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 401 | + foreach ($this->fallbackDirsPsr0 as $dir) { |
|
| 402 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 403 | 403 | return $file; |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // PSR-0 include paths. |
| 408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 408 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
| 409 | 409 | return $file; |
| 410 | 410 | } |
| 411 | 411 | |
@@ -418,6 +418,6 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * Prevents access to $this/self from included files. |
| 420 | 420 | */ |
| 421 | -function includeFile( $file ) { |
|
| 421 | +function includeFile($file) { |
|
| 422 | 422 | include $file; |
| 423 | 423 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | // autoload_namespaces.php @generated by Composer |
| 4 | 4 | |
| 5 | -$vendorDir = dirname( ( __DIR__ ) ); |
|
| 6 | -$baseDir = dirname( $vendorDir ); |
|
| 5 | +$vendorDir = dirname((__DIR__)); |
|
| 6 | +$baseDir = dirname($vendorDir); |
|
| 7 | 7 | |
| 8 | 8 | return array(); |