Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emtiazzahid committed Feb 6, 2020
0 parents commit 46cd171
Show file tree
Hide file tree
Showing 12 changed files with 490 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea/
/vendor
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/emtiazzahid/laravel-composer).


## Pull Requests

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **Create feature branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


## Running Tests

``` bash
$ composer test
```


**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 MIT

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "emtiazzahid/laravel-composer",
"description": "A description for laravel-composer.",
"type": "package",
"license": "MIT",
"keywords": [
"laravel"
],
"authors": [
{
"name": "Md. Emtiaz Zahid",
"email": "[email protected]"
}
],
"require": {
"illuminate/support": "^6.0"
},
"autoload": {
"classmap": [
"src/controllers"
],
"psr-4": {
"EmtiazZahid\\LaravelComposer\\": "./src"
}
},
"autoload-dev": {
"psr-4": {
"EmtiazZahid\\LaravelComposer\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"extra": {
"laravel": {
"providers": [
"EmtiazZahid\\LaravelComposer\\LaravelComposerServiceProvider"
]
}
}
}
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">

<testsuites>
<testsuite name="emtiazzahid/laravel-composer Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>

<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
35 changes: 35 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# laravel-composer

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Travis](https://img.shields.io/travis/emtiazzahid/laravel-composer.svg?style=flat-square)]()
[![Total Downloads](https://img.shields.io/packagist/dt/emtiazzahid/laravel-composer.svg?style=flat-square)](https://packagist.org/packages/emtiazzahid/laravel-composer)

## Install
`composer require emtiazzahid/laravel-composer`

## Usage
Write a few lines about the usage of this package.

## Testing
Run the tests with:

``` bash
vendor/bin/phpunit
```

## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Credits

- [Md. Emtiaz Zahid](https://github.com/emtiazzahid)
- [All Contributors](https://github.com/emtiazzahid/laravel-composer/contributors)

## Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

## License
The MIT License (MIT). Please see [License File](/LICENSE.md) for more information.
13 changes: 13 additions & 0 deletions src/EmtiazZahid/LaravelComposer/LaravelComposerParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace EmtiazZahid\LaravelComposer;

class LaravelComposerParser
{
public function installedPackages($packages)
{
$packagesArray = json_decode($packages, true);

return $packagesArray['installed'];
}
}
44 changes: 44 additions & 0 deletions src/EmtiazZahid/LaravelComposer/LaravelComposerServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace EmtiazZahid\LaravelComposer;

use Illuminate\Support\ServiceProvider;

class LaravelComposerServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind('LaravelComposerParser', function () {
return new LaravelComposerParser();
});
}

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
if (method_exists($this, 'package')) {
$this->package('emtiazzahid/laravel-composer', 'laravel-composer', __DIR__ . '/../../');
}

if (method_exists($this, 'loadViewsFrom')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'laravel-composer');
}

if (method_exists($this, 'publishes')) {
$this->publishes([
__DIR__.'/../../views' => base_path('/resources/views/vendor/laravel-composer'),
], 'views');
}

$this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
}
}
21 changes: 21 additions & 0 deletions src/Facades/LaravelComposerFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace EmtiazZahid\LaravelComposer\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class GitLogFacade
* @package EmtiazZahid\GitLogLaravel
*/

class LaravelComposerFacade extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor()
{
return 'LaravelComposer';
}
}
101 changes: 101 additions & 0 deletions src/controllers/LaravelComposerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace EmtiazZahid\LaravelComposer;

use EmtiazZahid\LaravelComposer\LaravelComposerParser;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Symfony\Component\Process\Process;

/**
* Class GitLogLaravelController
* @package EmtiazZahid\GitLogLaravel
*/
class LaravelComposerController extends Controller
{
public $laravelComposerParser;
/**
* @var string
*/
protected $view_log = 'laravel-composer::index';

public function __construct(LaravelComposerParser $laravelComposerParser)
{
$this->laravelComposerParser = $laravelComposerParser;
}

/**
* @param Request $request
* @return array|mixed
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(Request $request)
{
if (!session('laravel-composer-data')) {
$data = [
'packages' => $this->laravelComposerParser->installedPackages($this->processRun(['composer', 'show','-l','--direct','--format=json']))
];

session(['laravel-composer-data' => $data]);
}

return app('view')->make($this->view_log, session('laravel-composer-data'));
}

public function processRun($commands)
{
$process = new Process($commands, null, ['COMPOSER_HOME' => '$HOME/.config/composer']);
$process->setWorkingDirectory(base_path());
$process->setTimeout(120);
$process->run();



if (!$process->isSuccessful()) {
throw new \Symfony\Component\Process\Exception\ProcessFailedException($process);
}

return $process->getOutput();
}

public function packageDownload($name, $version)
{
$fileName = str_replace("_","/",$name);

$this->processRun(['composer', 'archive',$fileName,$version,'--format=zip','--file='.$name]);

return response()->download(base_path($name.'.zip'))->deleteFileAfterSend(true);
}

public function packageRemove($name)
{
$fileName = str_replace("_","/",$name);

try {
$result = $this->processRun(['composer', 'remove', $fileName, '--dev']);
}catch (\Exception $exception) {
$result = $exception->getMessage();
}

session()->flash('laravel-composer-data');

return redirect()->back()->with(['result' => $result]);
}

public function packageDetails($name, Request $request)
{
$fileName = str_replace("_","/",$name);

try {
$result = $this->processRun(['composer', 'show', $fileName, '--format=json']);
}catch (\Exception $exception) {
$result = $exception->getMessage();
}

$request->session()->flash('result', $result);

return \Redirect()->back()->with('result' , $result);
}


}
14 changes: 14 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


Route::prefix('laravel-composer')->middleware(['web'])->group(function () {

Route::get('package-download/{name}/{version}', '\EmtiazZahid\LaravelComposer\LaravelComposerController@packageDownload')
->name('laravel-composer.package-download');

Route::get('package-remove/{name}', '\EmtiazZahid\LaravelComposer\LaravelComposerController@packageRemove')
->name('laravel-composer.package-remove');

Route::get('package-details/{name}', '\EmtiazZahid\LaravelComposer\LaravelComposerController@packageDetails')
->name('laravel-composer.package-details');
});
Loading

0 comments on commit 46cd171

Please sign in to comment.