├── .github ├── logo.png ├── FUNDING.yml └── logo.svg ├── CHANGELOG.md ├── .gitignore ├── src ├── Exception │ ├── MissingExtraException.php │ ├── MissingEnvException.php │ └── MissingAuthException.php ├── RemoteFilesystem.php └── Plugin.php ├── composer.json ├── LICENSE ├── CONTRIBUTING.md └── README.md /.github/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lubusIN/composer-edd-plugin/HEAD/.github/logo.png -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | #github: lubusin 4 | patreon: lubus 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | **Change Log** 2 | -------------- 3 | 4 | All notable changes to "Composer EDD Plugin" will be documented here 5 | 6 | ***1.0.0*** 7 | 8 | Released on [TODO] 9 | 10 | - Initial plugin release 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | composer.lock 3 | /vendor/ 4 | 5 | # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control 6 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 7 | # composer.lock 8 | -------------------------------------------------------------------------------- /src/Exception/MissingExtraException.php: -------------------------------------------------------------------------------- 1 | fileUrl = $fileUrl; 44 | parent::__construct( $io, $config, $options, $disableTls ); 45 | } 46 | 47 | /** 48 | * Copy the remote file to local. 49 | * 50 | * @param string $originUrl The origin URL 51 | * @param string $fileUrl The file URL (ignored) 52 | * @param string $fileName the local filename 53 | * @param bool $progress Display the progression 54 | * @param array $options Additional context options 55 | * @return bool true 56 | */ 57 | public function copy( 58 | $originUrl, 59 | $fileUrl, 60 | $fileName, 61 | $progress = true, 62 | $options = [] 63 | ) { 64 | return parent::copy( 65 | $originUrl, 66 | $this->fileUrl, 67 | $fileName, 68 | $progress, 69 | $options 70 | ); 71 | } 72 | } -------------------------------------------------------------------------------- /.github/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Plugin.php: -------------------------------------------------------------------------------- 1 | composer = $composer; 36 | $this->io = $io; 37 | 38 | if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . '.env' ) ) { 39 | $dotenv = Dotenv::createImmutable( getcwd() ); 40 | $dotenv->load(); 41 | } 42 | } 43 | 44 | /** 45 | * Set subscribed events. 46 | * 47 | * @return array 48 | */ 49 | public static function getSubscribedEvents() { 50 | return array( 51 | PackageEvents::PRE_PACKAGE_INSTALL => 'getDownloadUrl', 52 | PackageEvents::PRE_PACKAGE_UPDATE => 'getDownloadUrl', 53 | PluginEvents::PRE_FILE_DOWNLOAD => 'onPreFileDownload', 54 | ); 55 | } 56 | 57 | /** 58 | * Get package from operation. 59 | * 60 | * @param OperationInterface $operation 61 | * @return mixed 62 | */ 63 | protected function getPackageFromOperation( OperationInterface $operation ) { 64 | if ( 'update' === $operation->getJobType() ) { 65 | return $operation->getTargetPackage(); 66 | } 67 | return $operation->getPackage(); 68 | } 69 | 70 | /** 71 | * Get download URL for our plugins. 72 | * 73 | * @param PackageEvent $event 74 | */ 75 | public function getDownloadUrl( PackageEvent $event ) { 76 | $this->downloadUrl = ''; 77 | $package = $this->getPackageFromOperation( $event->getOperation() ); 78 | $package_version = $package->getPrettyVersion(); 79 | $package_dist_url = $package->getDistUrl(); 80 | $package_extra = $package->getExtra(); 81 | 82 | if (!empty( $package_extra['edd_installer'])) { 83 | if (empty($package_extra['item_name'])) { 84 | throw new MissingExtraException('item_name'); 85 | } 86 | 87 | if (empty($package_extra['license'])) { 88 | throw new MissingExtraException('license'); 89 | } 90 | else { 91 | if (!getenv($package_extra['license'])) { 92 | throw new MissingEnvException('license'); 93 | } 94 | } 95 | 96 | if (empty($package_extra['url'])) { 97 | throw new MissingExtraException('url'); 98 | } else { 99 | if (!getenv($package_extra['url'])) { 100 | throw new MissingEnvException('url'); 101 | } 102 | } 103 | 104 | if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . 'auth.json' ) ) { 105 | $auth_file = getcwd() . DIRECTORY_SEPARATOR . 'auth.json'; 106 | $auth_data = json_decode(file_get_contents($auth_file), true); 107 | $package = parse_url($package_dist_url); 108 | 109 | print $package['host']; 110 | 111 | if (!array_key_exists($package['host'], $auth_data['http-basic'])) { 112 | throw new MissingAuthException('Auth credentials missing for ' . $package['host']); 113 | } 114 | } else { 115 | throw new MissingAuthException('Auth file auth.json missing'); 116 | } 117 | 118 | $package_details = [ 119 | 'edd_action' => 'get_version', 120 | 'license' => getenv( $package_extra['license'] ), 121 | 'item_name' => $package_extra['item_name'], 122 | 'url' => getenv( $package_extra['url'] ), 123 | 'version' => $package_version, 124 | ]; 125 | 126 | $context = stream_context_create([ 127 | "http" => [ 128 | "method" => "POST", 129 | 'header' =>"Content-Type: application/json; charset=utf-8", 130 | "timeout" => 30, 131 | ], 132 | ]); 133 | 134 | $edd_response = file_get_contents($package_dist_url . '?' . http_build_query($package_details), false, $context); 135 | 136 | if( !$edd_response) { 137 | throw new Exception('Unable to connect to ' . $package_dist_url); 138 | } 139 | 140 | $edd_data = json_decode($edd_response, true); 141 | 142 | if( !empty($edd_data['download_link'])) { 143 | $this->downloadUrl = $edd_data['download_link']; 144 | } 145 | 146 | } 147 | } 148 | 149 | /** 150 | * Process our plugin downloads. 151 | * 152 | * @param PreFileDownloadEvent $event 153 | */ 154 | public function onPreFileDownload( PreFileDownloadEvent $event ) { 155 | if ( empty( $this->downloadUrl ) ) { 156 | return; 157 | } 158 | 159 | $RemoteFileSystem = $event->getRemoteFilesystem(); 160 | $EddStore = new RemoteFilesystem( 161 | $this->downloadUrl, 162 | $this->io, 163 | $this->composer->getConfig(), 164 | $RemoteFileSystem->getOptions(), 165 | $RemoteFileSystem->isTlsDisabled() 166 | ); 167 | $event->setRemoteFilesystem( $EddStore ); 168 | } 169 | 170 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
163 |
164 |
165 | [LUBUS](http://lubus.in) is a web design agency based in Mumbai, India.
166 |
167 | You can pledge on [patreon](https://www.patreon.com/lubus) to support the development & maintenance of various [opensource](https://github.com/lubusIN/) stuffs we are building.
168 |
169 | ## License
170 |
171 | Composer EDD Plugin is open-sourced software licensed under the [MIT license](LICENSE)
172 |
--------------------------------------------------------------------------------