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

[lunox-core] Facade cannot access getter or properties #46

Closed
axmad386 opened this issue Jun 29, 2023 · 0 comments · Fixed by #50
Closed

[lunox-core] Facade cannot access getter or properties #46

axmad386 opened this issue Jun 29, 2023 · 0 comments · Fixed by #50
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@axmad386
Copy link
Member

When classed get wrapped on Facade using useFacade helper, all class properties and getter is not accessible. This is because Facade __getStatic magic method only triggered when we access class method. I think this code will fix this issue. Tested on another project using vitest.

  static __getStatic(name: string, abstract: string | symbol) {
   // before, we didn't check target property here 
   // because this.app is still undefined here due to static method
   // so by using app(), we can rebind app here
    let target: any;
    if (!this.app && app()) {
      this.setApplicationFacade(app());
      target = this.resolveFacadeInstance(abstract);
     // Tara... we can access target getter or property here
      if (target[name]) {
        return target[name];
      }
    }
    return (...args: any) => {
     // if target not resolved before, resolve here
      if (!target) {
        target = this.resolveFacadeInstance(abstract);
      }
      // this for checking Route facade is being called
      if (target.facadeCalled) {
        target.facadeCalled();
      }

      // check method is callable in instance
      if (target[name]) {
        return target[name].call(target, ...args);
      }

      // check method is callable in class
      if (target.constructor) {
        if (target.constructor[name]) {
          return target.constructor[name].call(target.constructor, ...args);
        }
      }

      throw new BadMethodCallException(`Method ${target.constructor.name}.${name} does not exist.`);
    };
  }
@axmad386 axmad386 added the enhancement New feature or request label Jun 29, 2023
@axmad386 axmad386 added this to the v2.0.0 milestone Jun 29, 2023
@axmad386 axmad386 self-assigned this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant