update v1.0.4

This commit is contained in:
sujitprasad
2016-01-04 18:05:45 +05:30
parent 372485336b
commit 4864e5a3f1
529 changed files with 20956 additions and 8178 deletions

View File

@@ -14,11 +14,13 @@ class CollectionEngine extends BaseEngine {
/**
* Constant for OR queries in internal search
*
* @var string
*/
const OR_CONDITION = 'OR';
/**
* Constant for AND queries in internal search
*
* @var string
*/
const AND_CONDITION = 'AND';
@@ -37,9 +39,10 @@ class CollectionEngine extends BaseEngine {
* @var array Different options
*/
private $options = array(
'stripOrder' => false,
'stripSearch' => false,
'caseSensitive' => false,
'sortFlags' => SORT_NATURAL,
'stripOrder' => false,
'stripSearch' => false,
'caseSensitive' => false,
);
/**
@@ -116,6 +119,18 @@ class CollectionEngine extends BaseEngine {
return $this->stripOrder($callback);
}
/**
* Set the sort behaviour of the doInternalOrder() function.
*
* @param int $sort_flags For details see: http://php.net/manual/en/function.sort.php
* @return $this
*/
public function setOrderFlags($sort_flags = SORT_NATURAL)
{
$this->options['sortFlags'] = $sort_flags;
return $this;
}
public function setCaseSensitive($value)
{
$this->options['caseSensitive'] = $value;
@@ -264,7 +279,7 @@ class CollectionEngine extends BaseEngine {
{
return $row[$column];
}
}, SORT_NATURAL);
}, $this->options['sortFlags']);
if($this->orderDirection == BaseEngine::ORDER_DESC)
$this->workingCollection = $this->workingCollection->reverse();

View File

@@ -22,42 +22,6 @@
</tbody>
</table>
<script>
$(function () {
//Enable check and uncheck all functionality
$(".checkbox-toggle").click(function () {
var clicks = $(this).data('clicks');
if (clicks) {
//Uncheck all checkboxes
$(".mailbox-messages input[type='checkbox']").iCheck("uncheck");
$(".fa", this).removeClass("fa-check-square-o").addClass('fa-square-o');
} else {
//Check all checkboxes
$(".mailbox-messages input[type='checkbox']").iCheck("check");
$(".fa", this).removeClass("fa-square-o").addClass('fa-check-square-o');
}
$(this).data("clicks", !clicks);
});
});
$(function() {
// Enable check and uncheck all functionality
$(".checkbox-toggle").click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
//Uncheck all checkboxes
$("input[type='checkbox']", ".mailbox-messages").iCheck("uncheck");
} else {
//Check all checkboxes
$("input[type='checkbox']", ".mailbox-messages").iCheck("check");
}
$(this).data("clicks", !clicks);
});
});
</script>
<script src="{{asset("lb-faveo/plugins/iCheck/icheck.min.js")}}" type="text/javascript"></script>
@if (!$noScript)
@include(Config::get('chumper.datatable.table.script_view'), array('id' => $id, 'options' => $options))
@endif

5
vendor/chumper/zipper/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
/.idea

11
vendor/chumper/zipper/.travis.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
language: php
php:
- 5.4
- 5.5
before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev
script: phpunit

191
vendor/chumper/zipper/LICENSE vendored Normal file
View File

@@ -0,0 +1,191 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, "control" means (i) the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.
"Object" form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of
this License; and
You must cause any modified files to carry prominent notices stating that You
changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets "[]" replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same "printed page" as the copyright notice for easier identification within
third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License 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.

150
vendor/chumper/zipper/README.md vendored Normal file
View File

@@ -0,0 +1,150 @@
#Zipper
[![Build Status](https://travis-ci.org/Chumper/Zipper.png)](https://travis-ci.org/Chumper/Zipper)
This is a simple Wrapper around the ZipArchive methods with some handy functions.
##Installation
1a- To install this package for laravel 5 just require it in your
`composer.json` with `"Chumper/Zipper": "0.6.0"`
1b- To install this package for laravel 4 just require it in your
`composer.json` with `"Chumper/Zipper": "0.5.1"`
2- goto `app/config/app.php`
.add to providers
'Chumper\Zipper\ZipperServiceProvider'
.add to aliases
'Zipper' => 'Chumper\Zipper\Zipper'
You can now access Zipper with the `Zipper` alias.
##Simple example
```php
$files = glob('public/files/*');
Zipper::make('public/test.zip')->add($files);
```
- by default the package will create the `test.zip` in the project route folder but in the example above we changed it to `project_route/public/`.
####Another example
```php
$zipper = new \Chumper\Zipper\Zipper;
$zipper->make('test.zip')->folder('test')->add('composer.json');
$zipper->zip('test.zip')->folder('test')->add('composer.json','test');
$zipper->remove('composer.lock');
$zipper->folder('mySuperPackage')->add(
array(
'vendor',
'composer.json'
),
);
$zipper->getFileContent('mySuperPackage/composer.json');
$zipper->make('test.zip')->extractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);
```
- You can easily chain most functions, except `getFileContent`, `getStatus`, `close` and `extractTo` which must come at the end of the chaine.
The main reason i wrote this little package is the `extractTo` method since it allows you to be very flexible when extracting zips.
So you can for example implement an update method which will just override the changed files.
##Functions
**make($pathToFile)**
`Create` or `Open` a zip archive; if the file does not exists it will create a new one.
It will return the Zipper instance so you can chain easily.
**add($files/folder)**
You can add and array of Files, or a Folder which all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.
**addString($filename, $content)**
add a single file to the zip by specifying a name and content as strings.
**remove($file/s)**
removes a single file or an array of files from the zip.
**folder($folder)**
Specify a folder to 'add files to' or 'remove files from' from the zip, example
Zipper::make('test.zip')->folder('test')->add('composer.json');
Zipper::make('test.zip')->folder('test')->remove('composer.json');
**home()**
Resets the folder pointer.
**zip($fileName)**
Uses the ZipRepository for file handling.
**getFileContent($filePath)**
get the content of a file in the zip. This will return the content or false.
**getStatus()**
get the opening status of the zip as integer.
**close()**
closes the zip and writes all changes.
**extractTo($path)**
Extracts the content of the zip archive to the specified location, for example
Zipper::make('test.zip')->folder('test')->extractTo('foo');
This will go into the folder `test` in the zip file and extract the content of that folder only to the folder `foo`, this is equal to using the `Zipper::WHITELIST`.
This command is really nice to get just a part of the zip file, you can also pass a 2nd & 3rd param to specify a single or an array of files that will be
white listed
>**Zipper::WHITELIST**
>
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::WHITELIST);
Which will extract the `test.zip` into the `public` folder but **only** the folder `vendor` inside the zip will be extracted.
or black listed
>**Zipper::BLACKLIST**
>
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::BLACKLIST);
Which will extract the `test.zip` into the `public` folder except the folder `vendor` inside the zip will not be extracted.
##Development
May it is a goot idea to add other compress functions like rar, phar or bzip2 etc...
Everything is setup for that, if you want just fork and develop further.
If you need other functions or got errors, please leave an issue on github.

31
vendor/chumper/zipper/composer.json vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "chumper/zipper",
"type": "library",
"description": "This is a little neat helper for the ZipArchive methods with handy functions",
"keywords": ["laravel", "ZIP", "Archive"],
"homepage": "http://github.com/Chumper/zipper",
"license": "Apache2",
"authors": [
{
"name": "Nils Plaschke",
"email": "github@nilsplaschke.de",
"homepage": "http://nilsplaschke.de",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "5.x",
"illuminate/filesystem": "5.x"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "dev-master"
},
"autoload": {
"psr-0": {
"Chumper\\Zipper": "src/"
}
},
"minimum-stability": "dev"
}

18
vendor/chumper/zipper/phpunit.xml vendored Normal file
View File

@@ -0,0 +1,18 @@
<?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"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,13 @@
<?php namespace Chumper\Zipper\Facades;
use Illuminate\Support\Facades\Facade;
class Zipper extends Facade{
protected static function getFacadeAccessor()
{
return 'zipper';
}
}

View File

@@ -0,0 +1,88 @@
<?php namespace Chumper\Zipper\Repositories;
/**
* RepositoryInterface that needs to be implemented by every Repository
*
* Class RepositoryInterface
* @package Chumper\Zipper\Repositories
*/
/**
* Class RepositoryInterface
* @package Chumper\Zipper\Repositories
*/
interface RepositoryInterface
{
/**
* Construct with a given path
*
* @param $filePath
* @param bool $new
* @param $archiveImplementation
*/
function __construct($filePath, $new = false, $archiveImplementation = null);
/**
* Add a file to the opened Archive
*
* @param $pathToFile
* @param $pathInArchive
* @return void
*/
public function addFile($pathToFile, $pathInArchive);
/**
* Remove a file permanently from the Archive
*
* @param $pathInArchive
* @return void
*/
public function removeFile($pathInArchive);
/**
* Get the content of a file
*
* @param $pathInArchive
* @return string
*/
public function getFileContent($pathInArchive);
/**
* Get the stream of a file
*
* @param $pathInArchive
* @return mixed
*/
public function getFileStream($pathInArchive);
/**
* Will loop over every item in the archive and will execute the callback on them
* Will provide the filename for every item
*
* @param $callback
* @return void
*/
public function each($callback);
/**
* Checks whether the file is in the archive
*
* @param $fileInArchive
* @return boolean
*/
public function fileExists($fileInArchive);
/**
* Returns the status of the archive as a string
*
* @return string
*/
public function getStatus();
/**
* Closes the archive and saves it
* @return void
*/
public function close();
}

View File

@@ -0,0 +1,141 @@
<?php namespace Chumper\Zipper\Repositories;
use Exception;
use ZipArchive;
class ZipRepository implements RepositoryInterface
{
private $archive;
/**
* Construct with a given path
*
* @param $filePath
* @param bool $create
* @param $archive
* @throws \Exception
* @return ZipRepository
*/
function __construct($filePath, $create = false, $archive = null)
{
//Check if ZipArchive is available
if (!class_exists('ZipArchive'))
throw new Exception('Error: Your PHP version is not compiled with zip support');
$this->archive = $archive ? $archive : new ZipArchive;
if ($create)
$this->archive->open($filePath, ZipArchive::CREATE);
else
$this->archive->open($filePath);
}
/**
* Add a file to the opened Archive
*
* @param $pathToFile
* @param $pathInArchive
* @return void
*/
public function addFile($pathToFile, $pathInArchive)
{
$this->archive->addFile($pathToFile, $pathInArchive);
}
/**
* Add a file to the opened Archive using its contents
*
* @param $name
* @param $content
* @return void
*/
public function addFromString($name, $content)
{
$this->archive->addFromString($name, $content);
}
/**
* Remove a file permanently from the Archive
*
* @param $pathInArchive
* @return void
*/
public function removeFile($pathInArchive)
{
$this->archive->deleteName($pathInArchive);
}
/**
* Get the content of a file
*
* @param $pathInArchive
* @return string
*/
public function getFileContent($pathInArchive)
{
return $this->archive->getFromName($pathInArchive);
}
/**
* Get the stream of a file
*
* @param $pathInArchive
* @return mixed
*/
public function getFileStream($pathInArchive)
{
return $this->archive->getStream($pathInArchive);
}
/**
* Will loop over every item in the archive and will execute the callback on them
* Will provide the filename for every item
*
* @param $callback
* @return void
*/
public function each($callback)
{
for ($i = 0; $i < $this->archive->numFiles; $i++) {
//skip if folder
$stats = $this->archive->statIndex($i);
if ($stats['size'] == 0 && $stats['crc'] == 0)
continue;
call_user_func_array($callback, array(
'file' => $this->archive->getNameIndex($i),
));
}
}
/**
* Checks whether the file is in the archive
*
* @param $fileInArchive
* @return boolean
*/
public function fileExists($fileInArchive)
{
return $this->archive->locateName($fileInArchive) !== false;
}
/**
* Returns the status of the archive as a string
*
* @return string
*/
public function getStatus()
{
return $this->archive->getStatusString();
}
/**
* Closes the archive and saves it
* @return void
*/
public function close()
{
@$this->archive->close();
}
}

View File

@@ -0,0 +1,474 @@
<?php namespace Chumper\Zipper;
use Chumper\Zipper\Repositories\RepositoryInterface;
use Exception;
use Illuminate\Filesystem\Filesystem;
/**
* This Zipper class is a wrapper around the ZipArchive methods with some handy functions
*
* Class Zipper
* @package Chumper\Zipper
*/
class Zipper
{
/**
* Constant for extracting
*/
const WHITELIST = 1;
/**
* Constant for extracting
*/
const BLACKLIST = 2;
/**
* @var string Represents the current location in the archive
*/
private $currentFolder = '';
/**
* @var Filesystem Handler to the file system
*/
private $file;
/**
* @var RepositoryInterface Handler to the archive
*/
private $repository;
/**
* @var string The path to the current zip file
*/
private $filePath;
/**
* Constructor
*
* @param Filesystem $fs
*/
function __construct(Filesystem $fs = null)
{
$this->file = $fs ? $fs : new Filesystem();
}
/**
* Create a new zip Archive if the file does not exists
* opens a zip archive if the file exists
*
* @param $pathToFile string The file to open
* @param RepositoryInterface|string $type The type of the archive, defaults to zip, possible are zip, phar
*
* @return $this Zipper instance
*/
public function make($pathToFile, $type = 'zip')
{
$new = $this->createArchiveFile($pathToFile);
$this->filePath = $pathToFile;
$name = 'Chumper\Zipper\Repositories\\' . ucwords($type) . 'Repository';
if (is_subclass_of($name, 'Chumper\Zipper\Repositories\RepositoryInterface'))
$this->repository = new $name($pathToFile, $new);
else
//TODO $type should be a class name and not a string
$this->repository = $type;
return $this;
}
/**
* Create a new zip archive or open an existing one
*
* @param $pathToFile
* @return $this
*/
public function zip($pathToFile)
{
$this->make($pathToFile);
return $this;
}
/**
* Create a new phar file or open one
*
* @param $pathToFile
* @return $this
*/
public function phar($pathToFile)
{
$this->make($pathToFile, 'phar');
return $this;
}
/**
* Extracts the opened zip archive to the specified location <br/>
* you can provide an array of files and folders and define if they should be a white list
* or a black list to extract.
*
* @param $path string The path to extract to
* @param array $files An array of files
* @param int $method The Method the files should be treated
*/
public function extractTo($path, array $files = array(), $method = Zipper::BLACKLIST)
{
$path = realpath($path);
if (!$this->file->exists($path))
$this->file->makeDirectory($path, 0755, true);
if ($method == Zipper::WHITELIST)
$this->extractWithWhiteList($path, $files);
else
$this->extractWithBlackList($path, $files);
}
/**
* Gets the content of a single file if available
*
* @param $filePath string The full path (including all folders) of the file in the zip
* @throws \Exception
* @return mixed returns the content or throws an exception
*/
public function getFileContent($filePath)
{
if ($this->repository->fileExists($filePath) === false)
throw new Exception(sprintf('The file "%s" cannot be found', $filePath));
return $this->repository->getFileContent($filePath);
}
/**
* Add one or multiple files to the zip.
*
* @param $pathToAdd array|string An array or string of files and folders to add
* @return $this Zipper instance
*/
public function add($pathToAdd)
{
if (is_array($pathToAdd)) {
foreach ($pathToAdd as $dir) {
$this->add($dir);
}
} else if ($this->file->isFile($pathToAdd)) {
$this->addFile($pathToAdd);
} else
$this->addDir($pathToAdd);
return $this;
}
/**
* Add a file to the zip using its contents
*
* @param $filename string The name of the file to create
* @param $content string The file contents
* @return $this Zipper instance
*/
public function addString($filename, $content)
{
$this->addFromString($filename, $content);
return $this;
}
/**
* Gets the status of the zip.
*
* @return integer The status of the internal zip file
*/
public function getStatus()
{
return $this->repository->getStatus();
}
/**
* Remove a file or array of files and folders from the zip archive
*
* @param $fileToRemove array|string The path/array to the files in the zip
* @return $this Zipper instance
*/
public function remove($fileToRemove)
{
if (is_array($fileToRemove)) {
$self = $this;
$this->repository->each(function ($file) use ($fileToRemove, $self) {
if (starts_with($file, $fileToRemove)) {
$self->getRepository()->removeFile($file);
}
});
} else
$this->repository->removeFile($fileToRemove);
return $this;
}
/**
* Returns the path of the current zip file if there is one.
* @return string The path to the file
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* Closes the zip file and frees all handles
*/
public function close()
{
if(!is_null($this->repository))
$this->repository->close();
$this->filePath = "";
}
/**
* Sets the internal folder to the given path.<br/>
* Useful for extracting only a segment of a zip file.
* @param $path
* @return $this
*/
public function folder($path)
{
$this->currentFolder = $path;
return $this;
}
/**
* Resets the internal folder to the root of the zip file.
*
* @return $this
*/
public function home()
{
$this->currentFolder = '';
return $this;
}
/**
* Deletes the archive file
*/
public function delete()
{
if(!is_null($this->repository))
$this->repository->close();
$this->file->delete($this->filePath);
$this->filePath = "";
}
/**
* Get the type of the Archive
*
* @return string
*/
public function getArchiveType()
{
return get_class($this->repository);
}
/**
* Destructor
*/
public function __destruct()
{
if(!is_null($this->repository))
$this->repository->close();
}
/**
* Get the current internal folder pointer
*
* @return string
*/
public function getCurrentFolderPath()
{
return $this->currentFolder;
}
/**
* Checks if a file is present in the archive
*
* @param $fileInArchive
* @return bool
*/
public function contains($fileInArchive)
{
return $this->repository->fileExists($fileInArchive);
}
/**
* @return RepositoryInterface
*/
public function getRepository()
{
return $this->repository;
}
/**
* @return Filesystem
*/
public function getFileHandler()
{
return $this->file;
}
/**
* Gets the path to the internal folder
*
* @return string
*/
public function getInternalPath()
{
return empty($this->currentFolder) ? '' : $this->currentFolder . '/';
}
//---------------------PRIVATE FUNCTIONS-------------
/**
* @param $pathToZip
* @throws \Exception
* @return bool
*/
private function createArchiveFile($pathToZip)
{
if (!$this->file->exists($pathToZip)) {
if (!$this->file->exists(dirname($pathToZip)))
$this->file->makeDirectory(dirname($pathToZip), 0755, true);
if (!$this->file->isWritable(dirname($pathToZip)))
throw new Exception(sprintf('The path "%s" is not writeable', $pathToZip));
return true;
}
return false;
}
/**
* @param $pathToDir
*/
private function addDir($pathToDir)
{
// First go over the files in this directory and add them to the repository.
foreach ($this->file->files($pathToDir) as $file) {
$this->addFile($pathToDir . '/' . basename($file));
}
// Now let's visit the subdirectories and add them, too.
foreach ($this->file->directories($pathToDir) as $dir) {
$old_folder = $this->currentFolder;
$this->currentFolder = empty($this->currentFolder) ? basename($dir) : $this->currentFolder . '/' . basename($dir);
$this->addDir($pathToDir . '/' . basename($dir));
$this->currentFolder = $old_folder;
}
}
/**
* Add the file to the zip
*
* @param $pathToAdd
*/
private function addFile($pathToAdd)
{
$info = pathinfo($pathToAdd);
$file_name = isset($info['extension']) ?
$info['filename'] . '.' . $info['extension'] :
$info['filename'];
$this->repository->addFile($pathToAdd, $this->getInternalPath() . $file_name);
}
/**
* Add the file to the zip from content
*
* @param $filename
* @param $content
*/
private function addFromString($filename, $content)
{
$this->repository->addFromString($this->getInternalPath() . $filename, $content);
}
/**
* @param $path
* @param $filesArray
* @throws \Exception
*/
private function extractWithBlackList($path, $filesArray)
{
$self = $this;
$this->repository->each(function ($fileName) use ($path, $filesArray, $self) {
$oriName = $fileName;
$currentPath = $self->getCurrentFolderPath();
if (!empty($currentPath) && !starts_with($fileName, $currentPath))
return;
if (starts_with($fileName, $filesArray)) {
return;
}
$tmpPath = str_replace($self->getInternalPath(), '', $fileName);
// We need to create the directory first in case it doesn't exist
$full_path = $path . '/' . $tmpPath;
$dir = substr($full_path, 0, strrpos($full_path, '/'));
if(!is_dir($dir))
$self->getFileHandler()->makeDirectory($dir, 0777, true, true);
$self->getFileHandler()->put($path . '/' . $tmpPath, $self->getRepository()->getFileStream($oriName));
});
}
/**
* @param $path
* @param $filesArray
* @throws \Exception
*/
private function extractWithWhiteList($path, $filesArray)
{
$self = $this;
$this->repository->each(function ($fileName) use ($path, $filesArray, $self) {
$oriName = $fileName;
$currentPath = $self->getCurrentFolderPath();
if (!empty($currentPath) && !starts_with($fileName, $currentPath))
return;
if (starts_with($self->getInternalPath() . $fileName, $filesArray)) {
$tmpPath = str_replace($self->getInternalPath(), '', $fileName);
// We need to create the directory first in case it doesn't exist
$full_path = $path . '/' . $tmpPath;
$dir = substr($full_path, 0, strrpos($full_path, '/'));
if(!is_dir($dir))
$self->getFileHandler()->makeDirectory($dir, 0777, true, true);
$self->getFileHandler()->put($path . '/' . $tmpPath, $self->getRepository()->getFileStream($oriName));
}
});
}
/**
* List files that are within the archive
*
* @return array
*/
public function listFiles()
{
$filesList = array();
$this->repository->each(
function ($file) use (&$filesList) {
$filesList[] = $file;
}
);
return $filesList;
}
}

View File

@@ -0,0 +1,55 @@
<?php namespace Chumper\Zipper;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
class ZipperServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['zipper'] = $this->app->share(function($app)
{
$return = $app->make('Chumper\Zipper\Zipper');
return $return;
});
$this->app->booting(function()
{
$loader = AliasLoader::getInstance();
$loader->alias('Zipper', 'Chumper\Zipper\Facades\Zipper');
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('zipper');
}
}

0
vendor/chumper/zipper/tests/.gitkeep vendored Normal file
View File

View File

@@ -0,0 +1,110 @@
<?php
use Chumper\Zipper\Repositories\RepositoryInterface;
class ArrayArchive implements RepositoryInterface
{
private $entries = array();
/**
* Construct with a given path
*
* @param $filePath
* @param bool $new
* @param $archiveImplementation
*/
function __construct($filePath, $new = false, $archiveImplementation = null)
{
}
/**
* Add a file to the opened Archive
*
* @param $pathToFile
* @param $pathInArchive
* @return void
*/
public function addFile($pathToFile, $pathInArchive)
{
$this->entries[$pathInArchive] = $pathInArchive;
}
/**
* Remove a file permanently from the Archive
*
* @param $pathInArchive
* @return void
*/
public function removeFile($pathInArchive)
{
unset($this->entries[$pathInArchive]);
}
/**
* Get the content of a file
*
* @param $pathInArchive
* @return string
*/
public function getFileContent($pathInArchive)
{
return $this->entries[$pathInArchive];
}
/**
* Get the stream of a file
*
* @param $pathInArchive
* @return mixed
*/
public function getFileStream($pathInArchive)
{
return $this->entries[$pathInArchive];
}
/**
* Will loop over every item in the archive and will execute the callback on them
* Will provide the filename for every item
*
* @param $callback
* @return void
*/
public function each($callback)
{
foreach ($this->entries as $entry) {
call_user_func_array($callback, array(
'file' => $entry,
));
}
}
/**
* Checks whether the file is in the archive
*
* @param $fileInArchive
* @return boolean
*/
public function fileExists($fileInArchive)
{
return array_key_exists($fileInArchive, $this->entries);
}
/**
* Returns the status of the archive as a string
*
* @return string
*/
public function getStatus()
{
return "OK";
}
/**
* Closes the archive and saves it
* @return void
*/
public function close()
{
}
}

View File

@@ -0,0 +1,101 @@
<?php
use Chumper\Zipper\Repositories\ZipRepository;
/**
* Created by JetBrains PhpStorm.
* User: Nils
* Date: 28.08.13
* Time: 20:57
* To change this template use File | Settings | File Templates.
*/
class ZipRepositoryTest extends PHPUnit_Framework_TestCase
{
/**
* @var ZipRepository
*/
public $zip;
/**
* @var \Mockery\Mock
*/
public $mock;
public function setUp()
{
$this->mock = Mockery::mock(new ZipArchive);
$this->zip = new ZipRepository('foo', true, $this->mock);
}
public function testMake()
{
$zip = new ZipRepository('foo.zip', true);
$this->assertFalse($zip->fileExists('foo'));
}
public function testAddFile()
{
$this->mock->shouldReceive('addFile')->once()->with('bar', 'bar');
$this->mock->shouldReceive('addFile')->once()->with('bar', 'foo/bar');
$this->mock->shouldReceive('addFile')->once()->with('foo/bar', 'bar');
$this->zip->addFile('bar', 'bar');
$this->zip->addFile('bar', 'foo/bar');
$this->zip->addFile('foo/bar', 'bar');
}
public function testRemoveFile()
{
$this->mock->shouldReceive('deleteName')->once()->with('bar');
$this->mock->shouldReceive('deleteName')->once()->with('foo/bar');
$this->zip->removeFile('bar');
$this->zip->removeFile('foo/bar');
}
public function testGetFileContent()
{
$this->mock->shouldReceive('getFromName')->once()
->with('bar')->andReturn('foo');
$this->mock->shouldReceive('getFromName')->once()
->with('foo/bar')->andReturn('baz');
$this->assertEquals('foo', $this->zip->getFileContent('bar'));
$this->assertEquals('baz', $this->zip->getFileContent('foo/bar'));
}
public function testGetFileStream()
{
$this->mock->shouldReceive('getStream')->once()
->with('bar')->andReturn('foo');
$this->mock->shouldReceive('getStream')->once()
->with('foo/bar')->andReturn('baz');
$this->assertEquals('foo', $this->zip->getFileStream('bar'));
$this->assertEquals('baz', $this->zip->getFileStream('foo/bar'));
}
public function testFileExists()
{
$this->mock->shouldReceive('locateName')->once()
->with('bar')->andReturn(true);
$this->mock->shouldReceive('locateName')->once()
->with('foo/bar')->andReturn(false);
$this->assertTrue($this->zip->fileExists('bar'));
$this->assertFalse($this->zip->fileExists('foo/bar'));
}
public function testClose()
{
$this->zip->close();
}
protected function tearDown()
{
Mockery::close();
}
}

View File

@@ -0,0 +1,238 @@
<?php
use Chumper\Zipper\Zipper;
use Illuminate\Filesystem\Filesystem;
require_once 'ArrayArchive.php';
class ZipperTest extends PHPUnit_Framework_TestCase
{
/**
* @var \Chumper\Zipper\Zipper
*/
public $archive;
/**
* @var \Mockery\Mock
*/
public $file;
public function __construct()
{
$this->archive = new \Chumper\Zipper\Zipper(
$this->file = Mockery::mock(new Filesystem)
);
$this->archive->make('foo', new ArrayArchive('foo', true));
}
public function testMake()
{
$this->assertEquals('ArrayArchive', $this->archive->getArchiveType());
$this->assertEquals('foo', $this->archive->getFilePath());
}
public function testExtractTo()
{
}
public function testAddAndGet()
{
$this->file->shouldReceive('isFile')->with('foo.bar')
->times(3)->andReturn(true);
$this->file->shouldReceive('isFile')->with('foo')
->times(3)->andReturn(true);
/**Array**/
$this->file->shouldReceive('isFile')->with('/path/to/fooDir')
->once()->andReturn(false);
$this->file->shouldReceive('files')->with('/path/to/fooDir')
->once()->andReturn(array('foo.bar', 'bar.foo'));
$this->file->shouldReceive('directories')->with('/path/to/fooDir')
->once()->andReturn(array('fooSubdir'));
$this->file->shouldReceive('files')->with('/path/to/fooDir/fooSubdir')
->once()->andReturn(array('foo.bar'));
$this->file->shouldReceive('directories')->with('/path/to/fooDir/fooSubdir')
->once()->andReturn(array());
//test1
$this->archive->add('foo.bar');
$this->archive->add('foo');
$this->assertEquals('foo', $this->archive->getFileContent('foo'));
$this->assertEquals('foo.bar', $this->archive->getFileContent('foo.bar'));
//test2
$this->archive->add(array(
'foo.bar',
'foo'
));
$this->assertEquals('foo', $this->archive->getFileContent('foo'));
$this->assertEquals('foo.bar', $this->archive->getFileContent('foo.bar'));
/**
* test3:
* Add the local folder /path/to/fooDir as folder fooDir to the repository
* and make sure the folder structure within the repository is there.
*/
$this->archive->folder('fooDir')->add('/path/to/fooDir');
$this->assertEquals('fooDir/foo.bar', $this->archive->getFileContent('fooDir/foo.bar'));
$this->assertEquals('fooDir/bar.foo', $this->archive->getFileContent('fooDir/bar.foo'));
$this->assertEquals('fooDir/fooSubdir/foo.bar', $this->archive->getFileContent('fooDir/fooSubdir/foo.bar'));
}
/**
* @expectedException Exception
*/
public function testGetFileContent()
{
$this->archive->getFileContent('baz');
}
public function testRemove()
{
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->add('foo');
$this->assertTrue($this->archive->contains('foo'));
$this->archive->remove('foo');
$this->assertFalse($this->archive->contains('foo'));
//----
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->file->shouldReceive('isFile')->with('fooBar')
->andReturn(true);
$this->archive->add(array('foo', 'fooBar'));
$this->assertTrue($this->archive->contains('foo'));
$this->assertTrue($this->archive->contains('fooBar'));
$this->archive->remove(array('foo', 'fooBar'));
$this->assertFalse($this->archive->contains('foo'));
$this->assertFalse($this->archive->contains('fooBar'));
}
public function testExtractWhiteList()
{
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->add('foo');
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo');
$this->archive->extractTo('', array('foo'), Zipper::WHITELIST);
//----
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->folder('foo/bar')->add('foo');
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo/bar/foo');
$this->archive->extractTo('', array('foo'), Zipper::WHITELIST);
}
public function testExtractBlackList()
{
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->add('foo');
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo');
$this->archive->extractTo('', array(), Zipper::BLACKLIST);
//----
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->folder('foo/bar')->add('foo');
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo/bar/foo');
$this->archive->extractTo('', array('foo'), Zipper::BLACKLIST);
}
public function testNavigationFolderAndHome()
{
$this->archive->folder('foo/bar');
$this->assertEquals('foo/bar', $this->archive->getCurrentFolderPath());
//----
$this->file->shouldReceive('isFile')->with('foo')
->andReturn(true);
$this->archive->add('foo');
$this->assertEquals('foo/bar/foo', $this->archive->getFileContent('foo/bar/foo'));
//----
$this->file->shouldReceive('isFile')->with('bar')
->andReturn(true);
$this->archive->home()->add('bar');
$this->assertEquals('bar', $this->archive->getFileContent('bar'));
//----
$this->file->shouldReceive('isFile')->with('baz/bar/bing')
->andReturn(true);
$this->archive->folder('test')->add('baz/bar/bing');
$this->assertEquals('test/bing', $this->archive->getFileContent('test/bing'));
}
public function testListFiles()
{
// testing empty file
$this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
$this->file->shouldReceive('isFile')->with('bar.file')->andReturn(true);
$this->assertEquals(array(), $this->archive->listFiles());
// testing not empty file
$this->archive->add('foo.file');
$this->archive->add('bar.file');
$this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
// testing with a empty sub dir
$this->file->shouldReceive('isFile')->with('/path/to/subDirEmpty')->andReturn(false);
$this->file->shouldReceive('files')->with('/path/to/subDirEmpty')->andReturn(array());
$this->file->shouldReceive('directories')->with('/path/to/subDirEmpty')->andReturn(array());
$this->archive->folder('subDirEmpty')->add('/path/to/subDirEmpty');
$this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
// testing with a not empty sub dir
$this->file->shouldReceive('isFile')->with('/path/to/subDir')->andReturn(false);
$this->file->shouldReceive('isFile')->with('sub.file')->andReturn(true);
$this->file->shouldReceive('files')->with('/path/to/subDir')->andReturn(array('sub.file'));
$this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn(array());
$this->archive->folder('subDir')->add('/path/to/subDir');
$this->assertEquals(array('foo.file', 'bar.file', 'subDir/sub.file'), $this->archive->listFiles());
}
}