rhysnhall / etsy-php-sdk

PHP SDK for Etsy API v3.
MIT License
47 stars 36 forks source link

Fatal error: Uncaught Error: Class 'Etsy\Resources\*****Resource Using*******' not found in #6

Closed developerarun closed 3 years ago

developerarun commented 3 years ago

Probably due to base name basename()

On Windows, both slash (/) and backslash () are used as the directory separator characters. In other environments, it is the forward-slash (/).

/**
   * Performs a request and updates the current resource with the return properties. Will perform a PUT request by default.
   *
   * @param string $url
   * @param array $data
   * @param string $method
   * @return Resource
   */
  protected function updateRequest(string $url, array $data, $method = "PUT") {
    $result = $this->request(
        $method,
        $url,
        basename(get_class($this)),
        $data
      );
    // Update the existing properties.
    $properties = get_object_vars($result)['_properties'];
    foreach($properties as $property => $value) {
      if(isset($this->_properties->{$property})) {
        $this->_properties->{$property} = $value;
      }
    }
    return $this;
  }

This function passes the resources name to request function which was actually class name and that was creating issues while updating entities

Here basename return the same class as input provided to it LIKE "Etsy\Resources\ShippingProfile" and same passed as a resource to request function so while creating a resource in createResource function it becomes "Etsy\Resources\Etsy\Resources\ShippingProfile" and create an issue,

Replacing "basename(get_class($this))," with "basename(str_replace("\\", "/", get_class($this)))," solves the problem

rhysnhall commented 3 years ago

I am unable to recreate this. Are you able to provide any further context?

developerarun commented 3 years ago

I am unable to recreate this. Are you able to provide any further context?

Which Operating system you are using? I am using Linux PHP 7.3

This should create an issue on the Linux

developerarun commented 3 years ago

I am unable to recreate this. Are you able to provide any further context?

Which Operating system you are using? I am using Linux PHP 7.3 This should create an issue on the Linux

I have checked its working with Windows and on Linux system have issue due to same reason

rhysnhall commented 3 years ago

Thanks, I have just tested this on a Linux machine and get the error. This is bad oversight on my behalf, I'll fix it up and release tonight.

rhysnhall commented 3 years ago

This has been resolved.

developerarun commented 3 years ago

This has been resolved.

Thanks for your effort