coenjacobs / mozart

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace, in order to prevent conflicts with other plugins loading the same dependencies in different versions.
https://coenjacobs.me/projects/mozart/
MIT License
426 stars 53 forks source link

AWS not working after Mozart has been ran #62

Open darthvader666uk opened 4 years ago

darthvader666uk commented 4 years ago

While this (https://github.com/coenjacobs/mozart/issues/43) issue was resolved, I found an issue with aws/aws-sdk-php not working once Mozart had been run.

The Namespace etc. had changed once being ran:

<?php
/**
 * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

namespace TEST\Aws\S3;

use TEST\Aws\Common\Client\AbstractClient;
use TEST\Aws\Common\Client\ClientBuilder;
use TEST\Aws\Common\Client\ExpiredCredentialsChecker;
use TEST\Aws\Common\Client\UploadBodyListener;
use TEST\Aws\Common\Enum\ClientOptions as Options;
use TEST\Aws\Common\Exception\RuntimeException;
use TEST\Aws\Common\Exception\InvalidArgumentException;
use TEST\Aws\Common\Signature\SignatureV4;
use TEST\Aws\Common\Model\MultipartUpload\AbstractTransfer;
use TEST\Aws\S3\Exception\AccessDeniedException;
use TEST\Aws\S3\Exception\Parser\S3ExceptionParser;
use TEST\Aws\S3\Exception\S3Exception;
use TEST\Aws\S3\Model\ClearBucket;
use TEST\Aws\S3\Model\MultipartUpload\AbstractTransfer as AbstractMulti;
use TEST\Aws\S3\Model\MultipartUpload\UploadBuilder;
use TEST\Aws\S3\Sync\DownloadSyncBuilder;
use TEST\Aws\S3\Sync\UploadSyncBuilder;
use Guzzle\Common\Collection;

But it still didnt appear to have found it. This is my Composer file:

{
    "name": "test/mozart",
    "description": "Test",
    "type": "project",
    "extra": {
        "mozart": {
            "dep_namespace": "Test\\",
            "dep_directory": "/dist/vendor/",
            "classmap_directory": "/dist/vendor/",
            "classmap_prefix": "Test_",
            "packages": [
                            "aws/aws-sdk-php"
                        ],
            "delete_vendor_directories": false
        },
        "patches": {
            "coenjacobs/mozart": {
                "DIRECTORY_SEPARATOR": "https://github.com/coenjacobs/mozart/pull/61.patch"
            }
        }
    },
    "require": {
        "aws/aws-sdk-php": "2.8.*",
        "cweagans/composer-patches": "~1.0",
        "coenjacobs/mozart": "dev-master"
    }
}

As @BrianHenryIE Mentioned in the previous issue:

on a quick glance, I see there is a files entry in the sdk's autoload key. I don't think Mozart handles an autoloader of type files. 

Any ideas?

BrianHenryIE commented 3 years ago

Fixed by #63 . Unrelated to files.

S3Client.php

use Test\Aws\Common\Client\AbstractClient;
use Test\Aws\Common\Client\ClientBuilder;
use Test\Aws\Common\Client\ExpiredCredentialsChecker;
use Test\Aws\Common\Client\UploadBodyListener;
use Test\Aws\Common\Enum\ClientOptions as Options;
use Test\Aws\Common\Exception\RuntimeException;
use Test\Aws\Common\Exception\InvalidArgumentException;
use Test\Aws\Common\Signature\SignatureV4;
use Test\Aws\Common\Model\MultipartUpload\AbstractTransfer;
use Test\Aws\S3\Exception\AccessDeniedException;
use Test\Aws\S3\Exception\Parser\S3ExceptionParser;
use Test\Aws\S3\Exception\S3Exception;
use Test\Aws\S3\Model\ClearBucket;
use Test\Aws\S3\Model\MultipartUpload\AbstractTransfer as AbstractMulti;
use Test\Aws\S3\Model\MultipartUpload\UploadBuilder;
use Test\Aws\S3\Sync\DownloadSyncBuilder;
use Test\Aws\S3\Sync\UploadSyncBuilder;
use Test\Guzzle\Common\Collection;
use Test\Guzzle\Http\EntityBody;
use Test\Guzzle\Http\Message\RequestInterface;
use Test\Guzzle\Iterator\FilterIterator;
use Test\Guzzle\Plugin\Backoff\BackoffPlugin;
use Test\Guzzle\Plugin\Backoff\CurlBackoffStrategy;
use Test\Guzzle\Plugin\Backoff\ExponentialBackoffStrategy;
use Test\Guzzle\Plugin\Backoff\HttpBackoffStrategy;
use Test\Guzzle\Plugin\Backoff\TruncatedBackoffStrategy;
use Test\Guzzle\Service\Command\CommandInterface;
use Test\Guzzle\Service\Command\Factory\AliasFactory;
use Test\Guzzle\Service\Command\Factory\CompositeFactory;
use Test\Guzzle\Service\Resource\Model;
use Test\Guzzle\Service\Resource\ResourceIteratorInterface;
{
  "name": "test/mozart",
  "description": "Test",
  "type": "project",
  "extra": {
    "mozart": {
      "dep_namespace": "Test\\",
      "dep_directory": "/dist/vendor/",
      "classmap_directory": "/dist/vendor/",
      "classmap_prefix": "Test_",
      "packages": [
        "aws/aws-sdk-php"
      ],
      "delete_vendor_directories": false
    },
    "patches": {
      "coenjacobs/mozart": {
        "Return one Autoloader per namespace": "https://github.com/coenjacobs/mozart/pull/63.patch"
      }
    }
  },
  "require": {
    "aws/aws-sdk-php": "2.8.*"
  },
  "require-dev": {
    "coenjacobs/mozart": "dev-master",
    "cweagans/composer-patches": "~1.0"
  }
}
ghost-writer-727 commented 3 years ago

I'm a noob to composer, but I don't think the problem has been properly identified yet. I got AWS working by chasing the errors and following them 1 by 1. There are a couple issues.

  1. non-classed functions don't autoload when using autoload by classmap, so a handful of AWS & Guzzle files need to be included using autoload by filename. See my real example: { "require": { "aws/aws-sdk-php": "^3.193" }, "extra": { "mozart": { "dep_namespace": "DirectoryOffloader", "dep_directory": "/vendor/DirectoryOffloader/dep/", "classmap_directory": "/vendor/DirectoryOffloader/classes/", "classmap_prefix": "DirectoryOffloader_", "delete_vendor_directories": true } }, "scripts": { "post-install-cmd": [ "\"vendor/bin/mozart\" compose", "composer dump-autoload" ], "post-update-cmd": [ "\"vendor/bin/mozart\" compose", "composer dump-autoload" ] }, "require-dev": { "coenjacobs/mozart": "^0.7.1" }, "autoload": { "classmap": [ "vendor/DirectoryOffloader" ], "files": [ "vendor/DirectoryOffloader/dep/Aws/functions.php", "vendor/DirectoryOffloader/dep/GuzzleHttp/functions_include.php", "vendor/DirectoryOffloader/dep/GuzzleHttp/Promise/functions_include.php", "vendor/DirectoryOffloader/dep/GuzzleHttp/Psr7/functions_include.php" ] } }

  2. When a function was used in a class, Mozart added the fqns to the front of the function. However, the page/class/method that called the function already has a fqns declared, so it doubled them up. IE: DirectoryOffloader/Aws/S3Client/DirectoryOffloader/Aws/someothernamespace/functionname() I fixed this by adding a "/" to the offending line so that it knows not to use the namespace of the current file also. Is this something Mozart should do for me?

  3. In Aws/Result.php, I noticed that Mozart added my custom namespace to the 2nd part of the use statement near the top of a file. It changed use JmesPath\Env as JmesPath; to use DirectoryOffloader\JmesPath\Env as DirectoryOffloader\JmesPath; creating a syntax error. I manually changed it to use DirectoryOffloader\JmesPath\Env as JmesPath;. Is this something that should be fixed in Mozart?

I've been developing Wordpress the wrong way since 2008, and I'm BRAND NEW to composer, so please be kind. I just hope this helps.

kodie commented 2 years ago

I'm running into the same exact issues as @porkifoy.