forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix LegacyProxy::get_instance_of for classesd having an
instance
me…
…thod. Pass the arguments as `...$args` instead of `$args`. Also fix related unit test, and remove unnecessary `is_function`.
- Loading branch information
Showing
4 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/php/src/Internal/DependencyManagement/ExampleClasses/ClassWithSingleton.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* ClassWithSingleton class file. | ||
* | ||
* @package Automattic\WooCommerce\Tests\Internal\DependencyManagement\ExampleClasses | ||
*/ | ||
|
||
// This class is in the root namespace on purpose, since it simulates being a legacy class in the 'includes' directory. | ||
|
||
/** | ||
* An example of a class that holds a singleton instance. | ||
*/ | ||
class ClassWithSingleton { | ||
|
||
/** | ||
* @var ClassWithSingleton The singleton instance of the class. | ||
*/ | ||
public static $instance; | ||
|
||
/** | ||
* @var array The arguments supplied to 'instance'. | ||
*/ | ||
public static $instance_args; | ||
|
||
/** | ||
* Gets the singleton instance of the class. | ||
* | ||
* @param mixed ...$args Any arguments required by the method. | ||
* | ||
* @return ClassWithSingleton The singleton instance of the class. | ||
*/ | ||
public static function instance( ...$args ) { | ||
if ( is_null( self::$instance ) ) { | ||
self::$instance = new ClassWithSingleton(); | ||
self::$instance_args = $args; | ||
} | ||
return self::$instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters