Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Not prefixing all classes? #50

Closed
qriouslad opened this issue Oct 11, 2022 · 3 comments
Closed

Not prefixing all classes? #50

qriouslad opened this issue Oct 11, 2022 · 3 comments

Comments

@qriouslad
Copy link

Hi Brian,

I spent sometime tonight figuring out how to make this work, including setting up a composer package at https://packagist.org/packages/qriouslad/codestar-framework for the library I needed to prefix.

I've successfully executed the strauss script via composer to prefix that package, however, I noticed not all classes are properly prefixed.

For example, in setup.class.php, while if ( class_exists( 'CSF_Options' )) is successfully prefixed into if ( class_exists( 'Prefix_CSF_Options' )), the if (class_exists( 'CSF_Metabox' )) part remains the same, not getting prefixed, as well as other classes in that file.

Since this library is not using namespaces yet, I needed to use this in the package composer.json:

"autoload": { "classmap": ["src/"] },

...where the library files are inside the /src/ folder. Could this be a method that is not yet fully supported by strauss?

@BrianHenryIE
Copy link
Owner

BrianHenryIE commented Oct 13, 2022

The CSF_Metabox class is not present in your library.

Strauss scans the files in the library, decides what the updated name should be (prefix+original), then makes those replacements. In this case, CSF_Metabox was never seen, so its class is not being prefixed, so references to it don't get updated.

If you have CSF_Metabox in a second library and both are included in your project, the reference should be updated correctly.

@qriouslad
Copy link
Author

@BrianHenryIE ah, got it. Thanks for explaining. It's great to get strauss working finally. Looking forward to use it more in future projects.

@estevao90
Copy link

@BrianHenryIE, I'm running into a similar issue when I try to use Strauss with the stripe-php library (https://github.com/stripe/stripe-php)

Basically, Strauss is not changing the classes in the instanceof checks.

My special config:

"override_autoload": {
	"stripe/stripe-php": {
		"psr-4": {
			"Stripe\\": "lib/"
		},
		"files": [
			"data"
		]
	}
}

An example of the problem:

Original file:
https://github.com/stripe/stripe-php/blob/master/lib/ApiOperations/All.php#L20

Strauss changes:

public static function all($params = null, $opts = null)
  {
      self::_validateParams($params);
      $url = static::classUrl();

      list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
      $obj = \NewPrefix\Stripe\Util\Util::convertToStripeObject($response->json, $opts);
      if (!($obj instanceof \Stripe\Collection)) {
          throw new \NewPrefix\Stripe\Exception\UnexpectedValueException(
              'Expected type ' . \NewPrefix\Stripe\Collection::class . ', got "' . \get_class($obj) . '" instead.'
          );
      }
      $obj->setLastResponse($response);
      $obj->setFilters($params);

      return $obj;
  }

So, Strauss changed the class in the message but did not change the conditional above.

Any ideas?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants