Commit 95b3019e authored by Joe Hoyle's avatar Joe Hoyle
Browse files

Merge pull request #48 from bdurette/ll

Lazily load the s3 library
parents 35e10fa2 854f400c
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -2,14 +2,25 @@

class S3_Uploads_Stream_Wrapper extends Aws\S3\StreamWrapper {

	protected static $s3_uploads;

	public function __construct() {
		static::$client = static::$s3_uploads->s3();
	}

	/**
	 * Register the 's3://' stream wrapper
	 *
	 * @param S3Client $client Client to use with the stream wrapper
	 */
	public static function register( Aws\S3\S3Client $client) {
	public static function register_streamwrapper( $s3_uploads ) {
		static::$s3_uploads = $s3_uploads;

		if ( in_array( 's3', stream_get_wrappers() ) ) {
			stream_wrapper_unregister( 's3' );
		}

		stream_wrapper_register( 's3', __CLASS__, STREAM_IS_URL );
		static::$client = $client;
	}

	// Override
+5 −6
Original line number Diff line number Diff line
@@ -70,8 +70,10 @@ class S3_Uploads {
			require_once dirname( __FILE__ ) . '/class-s3-uploads-local-stream-wrapper.php';
			stream_wrapper_register( 's3', 'S3_Uploads_Local_Stream_Wrapper', STREAM_IS_URL );
		} else {
			$s3 = $this->s3();
			S3_Uploads_Stream_Wrapper::register( $s3 );
			require_once dirname( dirname( __FILE__ ) ) . '/lib/aws-sdk/aws-autoloader.php';
			require_once dirname( __FILE__ ) . '/class-s3-uploads-stream-wrapper.php';

			S3_Uploads_Stream_Wrapper::register_streamwrapper( $this );
			stream_context_set_option( stream_context_get_default(), 's3', 'ACL', 'public-read' );
		}

@@ -124,9 +126,6 @@ class S3_Uploads {
	 */
	public function s3() {

		require_once dirname( dirname( __FILE__ ) ) . '/lib/aws-sdk/aws-autoloader.php';
		require_once dirname( __FILE__ ). '/class-s3-uploads-stream-wrapper.php';

		if ( ! empty( $this->s3 ) )
			return $this->s3;