shadiakiki1986/flysystem-git

There is no license information available for the latest version (0.0.8) of this package.

Flysystem adapter for git repositories

0.0.8 2016-11-24 06:53 UTC

This package is auto-updated.

Last update: 2024-03-27 01:37:52 UTC


README

Build Status

Adapter for flysystem that interfaces to any git repository served with a node-git-rest-api server via git-rest-api-client-php

Usage

Install from packagist

composer install shadiakiki1986/flysystem-git

Launch a node-git-rest-api server

docker run -p 8081:8081 -it shadiakiki1986/docker-node-git-rest-api

Example

<?php
require_once 'vendor/autoload.php';

use League\Flysystem\Filesystem;

// prepare adapter
// http://github.com/shadiakiki1986/git-rest-api-client-php
$git = new \GitRestApi\Client('http://localhost:8081');

// for read-write, include the correct username/password below
$remote = 'https://someone:somepass@github.com/shadiakiki1986/git-data-repo-testDataRepo';
$repo = $git->cloneRemote($remote,1); // passing 1 for clone --depth to save some time for repositories with a long history

// for writing to the remote repo, i.e. if "push" variable below is true, need to set username and email
// not needed if read-only usage
$repo->putConfig('user.name','phpunit test flysystem-git');
$repo->putConfig('user.email','shadiakiki1986@gmail.com');

// initialize filesystem for further usage
$push = false; // set to false to make read/write possible without pushing to remote. Set to true to push to remote
$pull = true; // set to true to skip pulling from the remote repository at each transaction in order to save on time
$adapter = new \shadiakiki1986\Flysystem\Git($repo,$push,$pull);
$filesystem = new Filesystem($adapter);

// read a file
$contents = $filesystem->read('bla');

// if username/password above are correct, can also update the file
$filesystem->update('bla','some new content');

// write to a new file
$filesystem->write('new folder/new file','content of file');