Skip to content

Commit 5275546

Browse files
committed
intial commit
0 parents  commit 5275546

24 files changed

+642
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install --dev
11+
12+
script: phpunit

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# File Manager (Laravel Bundle)
2+
3+
This package allows you to manage file uploads (store and deliver) to local server, cdn, and any other storage provider that you want.
4+
5+
6+
7+
8+

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "softservlet/file-manager",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Softservlet",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.3.0",
12+
"illuminate/support": "4.1.*"
13+
},
14+
"autoload": {
15+
"classmap": [
16+
"src/migrations"
17+
],
18+
"psr-0": {
19+
"Softservlet\\FileManager\\": "src/"
20+
}
21+
},
22+
"minimum-stability": "dev"
23+
}

hacking.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### Delivering files
2+
The file delivery can be used in many ways.
3+
For example a type of delivery can be though http URL, another can be though storage path, another can be though CDN file ID.
4+
Any of this string we will call 'URI'.
5+
6+
7+
A file can be stored many ways:
8+
* file:///var/www/file.ext
9+
* http://domain.com/file.ext
10+
* foo://domain.com/file.ext
11+
12+
So a file is always stored in a location that matches the following pattern of URI:
13+
14+
<schema>:<locatie>[?<interogarea>][#<fragmentul>]
15+
16+
For example if we store a file in openstack onbject storage we can have the following uri for it:
17+
18+
openstackv1://4281c348eaf83e70ddce0e07221c3d28
19+
20+
Each file must have the following attributes:
21+
22+
* URI
23+
* Name
24+
* MimeType
25+
26+

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

public/.gitkeep

Whitespace-only changes.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php namespace Softservlet\FileManager\Deliver;
2+
3+
use Exception;
4+
5+
/**
6+
* @author Marius Leustean <[email protected]>
7+
*
8+
* @version 1.0
9+
*/
10+
11+
class UriParser
12+
{
13+
/**
14+
* @brief the uri to be parsed
15+
*
16+
* @var string
17+
*/
18+
protected $uri;
19+
20+
/**
21+
* @brief the uri schema
22+
*
23+
* @var string
24+
*/
25+
protected $schema;
26+
27+
/**
28+
* @brief the uri location
29+
*
30+
* @var string
31+
*/
32+
protected $location;
33+
34+
/**
35+
* @brief the uri query (after ?)
36+
*
37+
* @var string
38+
*/
39+
protected $query;
40+
41+
/**
42+
* @brief uri fragment (after #)
43+
*
44+
* @var fragment
45+
*/
46+
protected $fragment;
47+
48+
/**
49+
* @brief class constructor
50+
*
51+
* @param string $uri to be parsed
52+
*/
53+
public function __construct($uri)
54+
{
55+
$this->parseUri($uri);
56+
}
57+
58+
/**
59+
* @brief get the uri schema
60+
*
61+
* @return string
62+
*/
63+
public function getSchema()
64+
{
65+
return $this->schema;
66+
}
67+
68+
/**
69+
* @brief get the uri location part
70+
*
71+
* @return string
72+
*/
73+
public function getLocation()
74+
{
75+
return $this->location;
76+
}
77+
78+
/**
79+
* @brief get the uri query string
80+
*
81+
* @return string
82+
*/
83+
public function getQuery()
84+
{
85+
return $this->query;
86+
}
87+
88+
/**
89+
* @brief get the uri fragment part
90+
*
91+
* @return string
92+
*/
93+
public function getFragment()
94+
{
95+
return $this->fragment;
96+
}
97+
/**
98+
* @brief parse the uri into variables
99+
*
100+
* @param uri to be parsed
101+
*
102+
* @return void
103+
*/
104+
protected function parseUri($uri)
105+
{
106+
$split = preg_split('/\:\/{2}|\?|\#/i', $uri);
107+
108+
if(count($split) <= 2) {
109+
throw new Exception(sprintf("The uri [%s] is not valid", $uri));
110+
}
111+
112+
$this->uri = $uri;
113+
$this->schema = $split[0];
114+
$this->location = $split[1];
115+
116+
if(isset($split[2])) {
117+
$this->query = $split[2];
118+
}
119+
120+
if(isset($split[3])) {
121+
$this->fragment = $split[3];
122+
}
123+
}
124+
}
125+

src/Softservlet/FileManager/Deliver/UrlInterface.php

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php namespace Softservlet\FileManager\File;
2+
3+
/**
4+
* @author Marius Leustean <[email protected]>
5+
*
6+
* @version 1.0
7+
*/
8+
interface FileDescriptorInterface
9+
{
10+
/**
11+
* @brief return the file mime type
12+
*
13+
* @return string mime type
14+
*/
15+
public function mime():
16+
17+
/**
18+
* @brief return the file cintents
19+
*
20+
* @return string/octet-stream the contents of the file
21+
*/
22+
public function contents();
23+
24+
/**
25+
* @brief return the size of the file in bytes
26+
*
27+
* @return int size
28+
*/
29+
public function size();
30+
31+
/**
32+
* @brief get the file name
33+
*
34+
* @return string
35+
*/
36+
public function name();
37+
38+
}
39+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php namespace Softservlet\FileManager\File;
2+
3+
/**
4+
* @author Marius Leustean <[email protected]>
5+
*
6+
* @version 1.0
7+
*/
8+
interface FileInterface
9+
{
10+
/**
11+
* @brief get the file URI
12+
*
13+
*
14+
* @return string uri
15+
*/
16+
public function uri();
17+
18+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php namespace Softservlet\FileManager\File;
2+
3+
use finfo;
4+
use Softservlet\FileManager\File\FileInterface;
5+
use Softservlet\FileManager\Deliver\UriParser;
6+
7+
/**
8+
* @author Marius Leustean <[email protected]>
9+
*
10+
* @version 1.0
11+
*/
12+
class LocalFileDescriptor implements FileDescriptorInterface
13+
{
14+
/**
15+
* @brief file object
16+
*
17+
* @var FileInterface
18+
*/
19+
protected $file;
20+
21+
/**
22+
* @brief file location on the disk
23+
*
24+
* @var string
25+
*/
26+
protected $location;
27+
28+
29+
public function __construct(FileInterface $file)
30+
{
31+
$this->file = $file;
32+
33+
$parser = new UriParser($this->file->uri());
34+
35+
$this->location = $parser->getLocation();
36+
}
37+
38+
39+
/**
40+
* @brief return the file mime type
41+
*
42+
* @return string mime type
43+
*/
44+
public function mime()
45+
{
46+
$finfo = new finfo(FILEINFO_MIME_TYPE, $this->location);
47+
return $finfo->file($this->location);
48+
}
49+
50+
/**
51+
* @brief return the file cintents
52+
*
53+
* @return string/octet-stream the contents of the file
54+
*/
55+
public function contents()
56+
{
57+
return file_get_contents($this->location);
58+
}
59+
60+
/**
61+
* @brief return the size of the file in bytes
62+
*
63+
* @return int size
64+
*/
65+
public function size()
66+
{
67+
return filesize($this->location);
68+
}
69+
70+
/**
71+
* @brief get the file name
72+
*
73+
* @return string
74+
*/
75+
public function name()
76+
{
77+
return basename($this->location);
78+
}
79+
80+
}

0 commit comments

Comments
 (0)