Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
f0b01009
Commit
f0b01009
authored
Nov 28, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code formatting.
parent
fc34ba6e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
368 additions
and
373 deletions
+368
-373
FileFinder.php
lib/Doctrine/FileFinder.php
+135
-373
GlobToRegex.php
lib/Doctrine/FileFinder/GlobToRegex.php
+127
-0
NumberCompare.php
lib/Doctrine/FileFinder/NumberCompare.php
+106
-0
No files found.
lib/Doctrine/FileFinder.php
View file @
f0b01009
<?php
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
/*
* $Id$
* $Id$
*
*
...
@@ -36,7 +28,7 @@
...
@@ -36,7 +28,7 @@
*
*
* All rules may be invoked several times, except for ->in() method.
* All rules may be invoked several times, except for ->in() method.
* Some rules are cumulative (->name() for example) whereas others are destructive
* Some rules are cumulative (->name() for example) whereas others are destructive
* (most recent value is used, ->max
d
epth() method for example).
* (most recent value is used, ->max
D
epth() method for example).
*
*
* All methods return the current Doctrine_FileFinder object to allow easy chaining:
* All methods return the current Doctrine_FileFinder object to allow easy chaining:
*
*
...
@@ -61,11 +53,11 @@ class Doctrine_FileFinder
...
@@ -61,11 +53,11 @@ class Doctrine_FileFinder
protected
$prunes
=
array
();
protected
$prunes
=
array
();
protected
$discards
=
array
();
protected
$discards
=
array
();
protected
$execs
=
array
();
protected
$execs
=
array
();
protected
$min
d
epth
=
0
;
protected
$min
D
epth
=
0
;
protected
$sizes
=
array
();
protected
$sizes
=
array
();
protected
$max
d
epth
=
1000000
;
protected
$max
D
epth
=
1000000
;
protected
$relative
=
false
;
protected
$relative
=
false
;
protected
$follow
_l
ink
=
false
;
protected
$follow
L
ink
=
false
;
/**
/**
* Sets maximum directory depth.
* Sets maximum directory depth.
...
@@ -75,9 +67,9 @@ class Doctrine_FileFinder
...
@@ -75,9 +67,9 @@ class Doctrine_FileFinder
* @param integer level
* @param integer level
* @return object current Doctrine_FileFinder object
* @return object current Doctrine_FileFinder object
*/
*/
public
function
max
d
epth
(
$level
)
public
function
max
D
epth
(
$level
)
{
{
$this
->
max
d
epth
=
$level
;
$this
->
max
D
epth
=
$level
;
return
$this
;
return
$this
;
}
}
...
@@ -90,14 +82,14 @@ class Doctrine_FileFinder
...
@@ -90,14 +82,14 @@ class Doctrine_FileFinder
* @param integer level
* @param integer level
* @return object current Doctrine_FileFinder object
* @return object current Doctrine_FileFinder object
*/
*/
public
function
min
d
epth
(
$level
)
public
function
min
D
epth
(
$level
)
{
{
$this
->
min
d
epth
=
$level
;
$this
->
min
D
epth
=
$level
;
return
$this
;
return
$this
;
}
}
public
function
get
_t
ype
()
public
function
get
T
ype
()
{
{
return
$this
->
type
;
return
$this
->
type
;
}
}
...
@@ -111,21 +103,17 @@ class Doctrine_FileFinder
...
@@ -111,21 +103,17 @@ class Doctrine_FileFinder
public
static
function
type
(
$name
)
public
static
function
type
(
$name
)
{
{
$finder
=
new
Doctrine_FileFinder
();
$finder
=
new
Doctrine_FileFinder
();
return
$finder
->
setType
(
$name
);
return
$finder
->
setType
(
$name
);
}
}
public
function
setType
(
$name
)
public
function
setType
(
$name
)
{
{
if
(
strtolower
(
substr
(
$name
,
0
,
3
))
==
'dir'
)
if
(
strtolower
(
substr
(
$name
,
0
,
3
))
==
'dir'
)
{
{
$this
->
type
=
'directory'
;
$this
->
type
=
'directory'
;
}
}
else
if
(
strtolower
(
$name
)
==
'any'
)
{
else
if
(
strtolower
(
$name
)
==
'any'
)
{
$this
->
type
=
'any'
;
$this
->
type
=
'any'
;
}
}
else
{
else
{
$this
->
type
=
'file'
;
$this
->
type
=
'file'
;
}
}
...
@@ -135,34 +123,26 @@ class Doctrine_FileFinder
...
@@ -135,34 +123,26 @@ class Doctrine_FileFinder
/*
/*
* glob, patterns (must be //) or strings
* glob, patterns (must be //) or strings
*/
*/
protected
function
to
_r
egex
(
$str
)
protected
function
to
R
egex
(
$str
)
{
{
if
(
$str
{
0
}
==
'/'
&&
$str
{
strlen
(
$str
)
-
1
}
==
'/'
)
if
(
$str
{
0
}
==
'/'
&&
$str
{
strlen
(
$str
)
-
1
}
==
'/'
)
{
{
return
$str
;
return
$str
;
}
}
else
{
else
return
Doctrine_FileFinder_GlobToRegex
::
globToRegex
(
$str
);
{
return
Doctrine_GlobToRegex
::
glob_to_regex
(
$str
);
}
}
}
}
protected
function
args
_to_array
(
$arg_l
ist
,
$not
=
false
)
protected
function
args
ToArray
(
$argL
ist
,
$not
=
false
)
{
{
$list
=
array
();
$list
=
array
();
for
(
$i
=
0
;
$i
<
count
(
$arg_list
);
$i
++
)
for
(
$i
=
0
;
$i
<
count
(
$argList
);
$i
++
)
{
{
if
(
is_array
(
$argList
[
$i
]))
{
if
(
is_array
(
$arg_list
[
$i
]))
foreach
(
$argList
[
$i
]
as
$arg
)
{
{
$list
[]
=
array
(
$not
,
$this
->
toRegex
(
$arg
));
foreach
(
$arg_list
[
$i
]
as
$arg
)
{
$list
[]
=
array
(
$not
,
$this
->
to_regex
(
$arg
));
}
}
}
}
else
{
else
$list
[]
=
array
(
$not
,
$this
->
toRegex
(
$argList
[
$i
]));
{
$list
[]
=
array
(
$not
,
$this
->
to_regex
(
$arg_list
[
$i
]));
}
}
}
}
...
@@ -184,7 +164,7 @@ class Doctrine_FileFinder
...
@@ -184,7 +164,7 @@ class Doctrine_FileFinder
public
function
name
()
public
function
name
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$this
->
names
=
array_merge
(
$this
->
names
,
$this
->
args
_to_a
rray
(
$args
));
$this
->
names
=
array_merge
(
$this
->
names
,
$this
->
args
ToA
rray
(
$args
));
return
$this
;
return
$this
;
}
}
...
@@ -196,10 +176,10 @@ class Doctrine_FileFinder
...
@@ -196,10 +176,10 @@ class Doctrine_FileFinder
* @param list a list of patterns, globs or strings
* @param list a list of patterns, globs or strings
* @return object current Doctrine_FileFinder object
* @return object current Doctrine_FileFinder object
*/
*/
public
function
not
_n
ame
()
public
function
not
N
ame
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$this
->
names
=
array_merge
(
$this
->
names
,
$this
->
args
_to_a
rray
(
$args
,
true
));
$this
->
names
=
array_merge
(
$this
->
names
,
$this
->
args
ToA
rray
(
$args
,
true
));
return
$this
;
return
$this
;
}
}
...
@@ -217,9 +197,8 @@ class Doctrine_FileFinder
...
@@ -217,9 +197,8 @@ class Doctrine_FileFinder
public
function
size
()
public
function
size
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
for
(
$i
=
0
;
$i
<
count
(
$args
);
$i
++
)
for
(
$i
=
0
;
$i
<
count
(
$args
);
$i
++
)
{
{
$this
->
sizes
[]
=
new
Doctrine_FileFinder_NumberCompare
(
$args
[
$i
]);
$this
->
sizes
[]
=
new
Doctrine_NumberCompare
(
$args
[
$i
]);
}
}
return
$this
;
return
$this
;
...
@@ -234,7 +213,7 @@ class Doctrine_FileFinder
...
@@ -234,7 +213,7 @@ class Doctrine_FileFinder
public
function
prune
()
public
function
prune
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$this
->
prunes
=
array_merge
(
$this
->
prunes
,
$this
->
args
_to_a
rray
(
$args
));
$this
->
prunes
=
array_merge
(
$this
->
prunes
,
$this
->
args
ToA
rray
(
$args
));
return
$this
;
return
$this
;
}
}
...
@@ -248,7 +227,7 @@ class Doctrine_FileFinder
...
@@ -248,7 +227,7 @@ class Doctrine_FileFinder
public
function
discard
()
public
function
discard
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$this
->
discards
=
array_merge
(
$this
->
discards
,
$this
->
args
_to_a
rray
(
$args
));
$this
->
discards
=
array_merge
(
$this
->
discards
,
$this
->
args
ToA
rray
(
$args
));
return
$this
;
return
$this
;
}
}
...
@@ -260,7 +239,7 @@ class Doctrine_FileFinder
...
@@ -260,7 +239,7 @@ class Doctrine_FileFinder
*
*
* @return object current Doctrine_FileFinder object
* @return object current Doctrine_FileFinder object
*/
*/
public
function
ignore
_version_c
ontrol
()
public
function
ignore
VersionC
ontrol
()
{
{
$ignores
=
array
(
'.svn'
,
'CVS'
,
'_darcs'
,
'.arch-params'
,
'.monotone'
,
'.bzr'
);
$ignores
=
array
(
'.svn'
,
'CVS'
,
'_darcs'
,
'.arch-params'
,
'.monotone'
,
'.bzr'
);
...
@@ -281,14 +260,10 @@ class Doctrine_FileFinder
...
@@ -281,14 +260,10 @@ class Doctrine_FileFinder
public
function
exec
()
public
function
exec
()
{
{
$args
=
func_get_args
();
$args
=
func_get_args
();
for
(
$i
=
0
;
$i
<
count
(
$args
);
$i
++
)
for
(
$i
=
0
;
$i
<
count
(
$args
);
$i
++
)
{
{
if
(
is_array
(
$args
[
$i
])
&&
!
method_exists
(
$args
[
$i
][
0
],
$args
[
$i
][
1
]))
{
if
(
is_array
(
$args
[
$i
])
&&
!
method_exists
(
$args
[
$i
][
0
],
$args
[
$i
][
1
]))
{
throw
new
Doctrine_Exception
(
sprintf
(
'method "%s" does not exist for object "%s".'
,
$args
[
$i
][
1
],
$args
[
$i
][
0
]));
throw
new
Doctrine_Exception
(
sprintf
(
'method "%s" does not exist for object "%s".'
,
$args
[
$i
][
1
],
$args
[
$i
][
0
]));
}
}
else
if
(
!
is_array
(
$args
[
$i
])
&&
!
function_exists
(
$args
[
$i
]))
{
else
if
(
!
is_array
(
$args
[
$i
])
&&
!
function_exists
(
$args
[
$i
]))
{
throw
new
Doctrine_Exception
(
sprintf
(
'function "%s" does not exist.'
,
$args
[
$i
]));
throw
new
Doctrine_Exception
(
sprintf
(
'function "%s" does not exist.'
,
$args
[
$i
]));
}
}
...
@@ -315,9 +290,9 @@ class Doctrine_FileFinder
...
@@ -315,9 +290,9 @@ class Doctrine_FileFinder
*
*
* @return object current Doctrine_FileFinder object
* @return object current Doctrine_FileFinder object
*/
*/
public
function
follow
_l
ink
()
public
function
follow
L
ink
()
{
{
$this
->
follow
_l
ink
=
true
;
$this
->
follow
L
ink
=
true
;
return
$this
;
return
$this
;
}
}
...
@@ -332,200 +307,186 @@ class Doctrine_FileFinder
...
@@ -332,200 +307,186 @@ class Doctrine_FileFinder
$files
=
array
();
$files
=
array
();
$here_dir
=
getcwd
();
$here_dir
=
getcwd
();
$numargs
=
func_num_args
();
$numargs
=
func_num_args
();
$arg
_l
ist
=
func_get_args
();
$arg
L
ist
=
func_get_args
();
// first argument is an array?
// first argument is an array?
if
(
$numargs
==
1
&&
is_array
(
$arg_list
[
0
]))
if
(
$numargs
==
1
&&
is_array
(
$argList
[
0
]))
{
{
$argList
=
$argList
[
0
];
$arg_list
=
$arg_list
[
0
];
$numargs
=
count
(
$argList
);
$numargs
=
count
(
$arg_list
);
}
}
for
(
$i
=
0
;
$i
<
$numargs
;
$i
++
)
for
(
$i
=
0
;
$i
<
$numargs
;
$i
++
)
{
{
$realDir
=
realpath
(
$argList
[
$i
]);
$real_dir
=
realpath
(
$arg_list
[
$i
]);
// absolute path?
// absolute path?
if
(
!
self
::
isPathAbsolute
(
$real_dir
))
if
(
!
self
::
isPathAbsolute
(
$realDir
))
{
{
$dir
=
$here_dir
.
DIRECTORY_SEPARATOR
.
$realDir
;
$dir
=
$here_dir
.
DIRECTORY_SEPARATOR
.
$real_dir
;
}
else
{
}
$dir
=
$realDir
;
else
{
$dir
=
$real_dir
;
}
}
if
(
!
is_dir
(
$real_dir
))
if
(
!
is_dir
(
$realDir
))
{
{
continue
;
continue
;
}
}
if
(
$this
->
relative
)
if
(
$this
->
relative
)
{
{
$files
=
array_merge
(
$files
,
str_replace
(
$dir
.
DIRECTORY_SEPARATOR
,
''
,
$this
->
_searchIn
(
$dir
)));
$files
=
array_merge
(
$files
,
str_replace
(
$dir
.
DIRECTORY_SEPARATOR
,
''
,
$this
->
search_in
(
$dir
)));
}
else
{
}
$files
=
array_merge
(
$files
,
$this
->
_searchIn
(
$dir
));
else
{
$files
=
array_merge
(
$files
,
$this
->
search_in
(
$dir
));
}
}
}
}
return
array_unique
(
$files
);
return
array_unique
(
$files
);
}
}
protected
function
search_i
n
(
$dir
,
$depth
=
0
)
protected
function
_searchI
n
(
$dir
,
$depth
=
0
)
{
{
if
(
$depth
>
$this
->
maxdepth
)
if
(
$depth
>
$this
->
maxDepth
)
{
{
return
array
();
return
array
();
}
}
if
(
is_link
(
$dir
)
&&
!
$this
->
follow_link
)
if
(
is_link
(
$dir
)
&&
!
$this
->
followLink
)
{
{
return
array
();
return
array
();
}
}
$files
=
array
();
$files
=
array
();
if
(
is_dir
(
$dir
))
if
(
is_dir
(
$dir
))
{
{
$currentDir
=
opendir
(
$dir
);
$current_dir
=
opendir
(
$dir
);
while
(
false
!==
$entryName
=
readdir
(
$currentDir
))
{
while
(
false
!==
$entryname
=
readdir
(
$current_dir
))
if
(
$entryName
==
'.'
||
$entryName
==
'..'
)
{
{
continue
;
if
(
$entryname
==
'.'
||
$entryname
==
'..'
)
continue
;
}
$current_entry
=
$dir
.
DIRECTORY_SEPARATOR
.
$entryname
;
$currentEntry
=
$dir
.
DIRECTORY_SEPARATOR
.
$entryName
;
if
(
is_link
(
$current_entry
)
&&
!
$this
->
follow_link
)
if
(
is_link
(
$currentEntry
)
&&
!
$this
->
followLink
)
{
{
continue
;
continue
;
}
}
if
(
is_dir
(
$current_entry
))
if
(
is_dir
(
$currentEntry
))
{
{
if
((
$this
->
type
==
'directory'
||
$this
->
type
==
'any'
)
&&
(
$depth
>=
$this
->
minDepth
)
&&
!
$this
->
_isDiscarded
(
$dir
,
$entryName
)
&&
$this
->
_matchNames
(
$dir
,
$entryName
)
&&
$this
->
_execOk
(
$dir
,
$entryName
))
{
if
((
$this
->
type
==
'directory'
||
$this
->
type
==
'any'
)
&&
(
$depth
>=
$this
->
mindepth
)
&&
!
$this
->
is_discarded
(
$dir
,
$entryname
)
&&
$this
->
match_names
(
$dir
,
$entryname
)
&&
$this
->
exec_ok
(
$dir
,
$entryname
))
$files
[]
=
realpath
(
$currentEntry
);
{
$files
[]
=
realpath
(
$current_entry
);
}
}
if
(
!
$this
->
is_pruned
(
$dir
,
$entryname
))
if
(
!
$this
->
_isPruned
(
$dir
,
$entryName
))
{
{
$files
=
array_merge
(
$files
,
$this
->
_searchIn
(
$currentEntry
,
$depth
+
1
));
$files
=
array_merge
(
$files
,
$this
->
search_in
(
$current_entry
,
$depth
+
1
));
}
}
}
}
else
{
else
if
((
$this
->
type
!=
'directory'
||
$this
->
type
==
'any'
)
&&
(
$depth
>=
$this
->
minDepth
)
&&
!
$this
->
_isDiscarded
(
$dir
,
$entryName
)
&&
$this
->
_matchNames
(
$dir
,
$entryName
)
&&
$this
->
_sizeOk
(
$dir
,
$entryName
)
&&
$this
->
_execOk
(
$dir
,
$entryName
))
{
{
$files
[]
=
realpath
(
$currentEntry
);
if
((
$this
->
type
!=
'directory'
||
$this
->
type
==
'any'
)
&&
(
$depth
>=
$this
->
mindepth
)
&&
!
$this
->
is_discarded
(
$dir
,
$entryname
)
&&
$this
->
match_names
(
$dir
,
$entryname
)
&&
$this
->
size_ok
(
$dir
,
$entryname
)
&&
$this
->
exec_ok
(
$dir
,
$entryname
))
{
$files
[]
=
realpath
(
$current_entry
);
}
}
}
}
}
}
closedir
(
$current_dir
);
closedir
(
$currentDir
);
}
}
return
$files
;
return
$files
;
}
}
protected
function
match_n
ames
(
$dir
,
$entry
)
protected
function
_matchN
ames
(
$dir
,
$entry
)
{
{
if
(
!
count
(
$this
->
names
))
return
true
;
if
(
!
count
(
$this
->
names
))
{
return
true
;
}
// we must match one "not_name" rules to be ko
// we must match one "not_name" rules to be ko
$one_not_name_rule
=
false
;
$oneNotNameRule
=
false
;
foreach
(
$this
->
names
as
$args
)
foreach
(
$this
->
names
as
$args
)
{
{
list
(
$not
,
$regex
)
=
$args
;
list
(
$not
,
$regex
)
=
$args
;
if
(
$not
)
if
(
$not
)
{
{
$oneNotNameRule
=
true
;
$one_not_name_rule
=
true
;
if
(
preg_match
(
$regex
,
$entry
))
{
if
(
preg_match
(
$regex
,
$entry
))
{
return
false
;
return
false
;
}
}
}
}
}
}
$one
_name_r
ule
=
false
;
$one
NameR
ule
=
false
;
// we must match one "name" rules to be ok
// we must match one "name" rules to be ok
foreach
(
$this
->
names
as
$args
)
foreach
(
$this
->
names
as
$args
)
{
{
list
(
$not
,
$regex
)
=
$args
;
list
(
$not
,
$regex
)
=
$args
;
if
(
!
$not
)
if
(
!
$not
)
{
{
$oneNameRule
=
true
;
$one_name_rule
=
true
;
if
(
preg_match
(
$regex
,
$entry
))
{
if
(
preg_match
(
$regex
,
$entry
))
{
return
true
;
return
true
;
}
}
}
}
}
}
if
(
$one_not_name_rule
&&
$one_name_rule
)
if
(
$oneNotNameRule
&&
$oneNameRule
)
{
{
return
false
;
return
false
;
}
}
else
if
(
$oneNotNameRule
)
{
else
if
(
$one_not_name_rule
)
{
return
true
;
return
true
;
}
}
else
if
(
$oneNameRule
)
{
else
if
(
$one_name_rule
)
{
return
false
;
return
false
;
}
}
else
{
else
{
return
true
;
return
true
;
}
}
}
}
protected
function
size_o
k
(
$dir
,
$entry
)
protected
function
_sizeO
k
(
$dir
,
$entry
)
{
{
if
(
!
count
(
$this
->
sizes
))
return
true
;
if
(
!
count
(
$this
->
sizes
))
{
return
true
;
if
(
!
is_file
(
$dir
.
DIRECTORY_SEPARATOR
.
$entry
))
return
true
;
}
$filesize
=
filesize
(
$dir
.
DIRECTORY_SEPARATOR
.
$entry
);
if
(
!
is_file
(
$dir
.
DIRECTORY_SEPARATOR
.
$entry
))
{
foreach
(
$this
->
sizes
as
$number_compare
)
return
true
;
{
}
if
(
!
$number_compare
->
test
(
$filesize
))
return
false
;
$filesize
=
filesize
(
$dir
.
DIRECTORY_SEPARATOR
.
$entry
);
foreach
(
$this
->
sizes
as
$number_compare
)
{
if
(
!
$number_compare
->
test
(
$filesize
))
{
return
false
;
}
}
}
return
true
;
return
true
;
}
}
protected
function
is_p
runed
(
$dir
,
$entry
)
protected
function
_isP
runed
(
$dir
,
$entry
)
{
{
if
(
!
count
(
$this
->
prunes
))
return
false
;
if
(
!
count
(
$this
->
prunes
))
{
return
false
;
foreach
(
$this
->
prunes
as
$args
)
}
{
foreach
(
$this
->
prunes
as
$args
)
{
$regex
=
$args
[
1
];
$regex
=
$args
[
1
];
if
(
preg_match
(
$regex
,
$entry
))
return
true
;
if
(
preg_match
(
$regex
,
$entry
))
{
return
true
;
}
}
}
return
false
;
return
false
;
}
}
protected
function
is_d
iscarded
(
$dir
,
$entry
)
protected
function
_isD
iscarded
(
$dir
,
$entry
)
{
{
if
(
!
count
(
$this
->
discards
))
return
false
;
if
(
!
count
(
$this
->
discards
))
{
return
false
;
foreach
(
$this
->
discards
as
$args
)
}
{
foreach
(
$this
->
discards
as
$args
)
{
$regex
=
$args
[
1
];
$regex
=
$args
[
1
];
if
(
preg_match
(
$regex
,
$entry
))
return
true
;
if
(
preg_match
(
$regex
,
$entry
))
{
return
true
;
}
}
}
return
false
;
return
false
;
}
}
protected
function
exec_o
k
(
$dir
,
$entry
)
protected
function
_execO
k
(
$dir
,
$entry
)
{
{
if
(
!
count
(
$this
->
execs
))
return
true
;
if
(
!
count
(
$this
->
execs
))
{
return
true
;
foreach
(
$this
->
execs
as
$exec
)
}
{
if
(
!
call_user_func_array
(
$exec
,
array
(
$dir
,
$entry
)))
return
false
;
foreach
(
$this
->
execs
as
$exec
)
{
if
(
!
call_user_func_array
(
$exec
,
array
(
$dir
,
$entry
)))
{
return
false
;
}
}
}
return
true
;
return
true
;
...
@@ -538,209 +499,10 @@ class Doctrine_FileFinder
...
@@ -538,209 +499,10 @@ class Doctrine_FileFinder
$path
{
1
}
==
':'
&&
$path
{
1
}
==
':'
&&
(
$path
{
2
}
==
'\\'
||
$path
{
2
}
==
'/'
)
(
$path
{
2
}
==
'\\'
||
$path
{
2
}
==
'/'
)
)
)
)
)
{
{
return
true
;
return
true
;
}
}
return
false
;
}
}
/**
* Match globbing patterns against text.
*
* if match_glob("foo.*", "foo.bar") echo "matched\n";
*
* // prints foo.bar and foo.baz
* $regex = glob_to_regex("foo.*");
* for (array('foo.bar', 'foo.baz', 'foo', 'bar') as $t)
* {
* if (/$regex/) echo "matched: $car\n";
* }
*
* Doctrine_GlobToRegex implements glob(3) style matching that can be used to match
* against text, rather than fetching names from a filesystem.
*
* based on perl Text::Glob module.
*
* @package Doctrine
* @subpackage FileFinder
* @author Fabien Potencier <fabien.potencier@gmail.com> php port
* @author Richard Clamp <richardc@unixbeard.net> perl version
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@gmail.com>
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
* @version SVN: $Id: Doctrine_FileFinder.class.php 5110 2007-09-15 12:07:18Z fabien $
*/
class
Doctrine_GlobToRegex
{
protected
static
$strict_leading_dot
=
true
;
protected
static
$strict_wildcard_slash
=
true
;
public
static
function
setStrictLeadingDot
(
$boolean
)
{
self
::
$strict_leading_dot
=
$boolean
;
}
public
static
function
setStrictWildcardSlash
(
$boolean
)
{
self
::
$strict_wildcard_slash
=
$boolean
;
}
/**
* Returns a compiled regex which is the equiavlent of the globbing pattern.
*
* @param string glob pattern
* @return string regex
*/
public
static
function
glob_to_regex
(
$glob
)
{
$first_byte
=
true
;
$escaping
=
false
;
$in_curlies
=
0
;
$regex
=
''
;
for
(
$i
=
0
;
$i
<
strlen
(
$glob
);
$i
++
)
{
$car
=
$glob
[
$i
];
if
(
$first_byte
)
{
if
(
self
::
$strict_leading_dot
&&
$car
!=
'.'
)
{
$regex
.=
'(?=[^\.])'
;
}
$first_byte
=
false
;
}
if
(
$car
==
'/'
)
{
$first_byte
=
true
;
}
if
(
$car
==
'.'
||
$car
==
'('
||
$car
==
')'
||
$car
==
'|'
||
$car
==
'+'
||
$car
==
'^'
||
$car
==
'$'
)
{
$regex
.=
"
\\
$car
"
;
}
else
if
(
$car
==
'*'
)
{
$regex
.=
(
$escaping
?
"
\\
*"
:
(
self
::
$strict_wildcard_slash
?
"[^/]*"
:
".*"
));
}
else
if
(
$car
==
'?'
)
{
$regex
.=
(
$escaping
?
"
\\
?"
:
(
self
::
$strict_wildcard_slash
?
"[^/]"
:
"."
));
}
else
if
(
$car
==
'{'
)
{
$regex
.=
(
$escaping
?
"
\\
{"
:
"("
);
if
(
!
$escaping
)
++
$in_curlies
;
}
else
if
(
$car
==
'}'
&&
$in_curlies
)
{
$regex
.=
(
$escaping
?
"}"
:
")"
);
if
(
!
$escaping
)
--
$in_curlies
;
}
else
if
(
$car
==
','
&&
$in_curlies
)
{
$regex
.=
(
$escaping
?
","
:
"|"
);
}
else
if
(
$car
==
"
\\
"
)
{
if
(
$escaping
)
{
$regex
.=
"
\\\\
"
;
$escaping
=
false
;
}
else
{
$escaping
=
true
;
}
continue
;
}
else
{
$regex
.=
$car
;
$escaping
=
false
;
}
$escaping
=
false
;
}
return
"#^
$regex
$#"
;
}
}
/**
* Numeric comparisons.
*
* Doctrine_NumberCompare compiles a simple comparison to an anonymous
* subroutine, which you can call with a value to be tested again.
* Now this would be very pointless, if Doctrine_NumberCompare didn't understand
* magnitudes.
* The target value may use magnitudes of kilobytes (k, ki),
* megabytes (m, mi), or gigabytes (g, gi). Those suffixed
* with an i use the appropriate 2**n version in accordance with the
* IEC standard: http://physics.nist.gov/cuu/Units/binary.html
*
* based on perl Number::Compare module.
*
* @package Doctrine
* @subpackage FileFinder
* @author Fabien Potencier <fabien.potencier@gmail.com> php port
* @author Richard Clamp <richardc@unixbeard.net> perl version
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@gmail.com>
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
* @see http://physics.nist.gov/cuu/Units/binary.html
* @version SVN: $Id: Doctrine_FileFinder.class.php 5110 2007-09-15 12:07:18Z fabien $
*/
class
Doctrine_NumberCompare
{
protected
$test
=
''
;
public
function
__construct
(
$test
)
{
$this
->
test
=
$test
;
}
public
function
test
(
$number
)
{
if
(
!
preg_match
(
'{^([<>]=?)?(.*?)([kmg]i?)?$}i'
,
$this
->
test
,
$matches
))
{
throw
new
Doctrine_Exception
(
sprintf
(
'don\'t understand "%s" as a test.'
,
$this
->
test
));
}
$target
=
array_key_exists
(
2
,
$matches
)
?
$matches
[
2
]
:
''
;
$magnitude
=
array_key_exists
(
3
,
$matches
)
?
$matches
[
3
]
:
''
;
if
(
strtolower
(
$magnitude
)
==
'k'
)
$target
*=
1000
;
if
(
strtolower
(
$magnitude
)
==
'ki'
)
$target
*=
1024
;
if
(
strtolower
(
$magnitude
)
==
'm'
)
$target
*=
1000000
;
if
(
strtolower
(
$magnitude
)
==
'mi'
)
$target
*=
1024
*
1024
;
if
(
strtolower
(
$magnitude
)
==
'g'
)
$target
*=
1000000000
;
if
(
strtolower
(
$magnitude
)
==
'gi'
)
$target
*=
1024
*
1024
*
1024
;
$comparison
=
array_key_exists
(
1
,
$matches
)
?
$matches
[
1
]
:
'=='
;
if
(
$comparison
==
'=='
||
$comparison
==
''
)
{
return
(
$number
==
$target
);
}
else
if
(
$comparison
==
'>'
)
{
return
(
$number
>
$target
);
}
else
if
(
$comparison
==
'>='
)
{
return
(
$number
>=
$target
);
}
else
if
(
$comparison
==
'<'
)
{
return
(
$number
<
$target
);
}
else
if
(
$comparison
==
'<='
)
{
return
(
$number
<=
$target
);
}
return
false
;
return
false
;
}
}
}
}
\ No newline at end of file
lib/Doctrine/FileFinder/GlobToRegex.php
0 → 100644
View file @
f0b01009
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_FileFinder_GlobToRegex
*
* Match globbing patterns against text.
*
* if match_glob("foo.*", "foo.bar") echo "matched\n";
*
* // prints foo.bar and foo.baz
* $regex = globToRegex("foo.*");
* for (array('foo.bar', 'foo.baz', 'foo', 'bar') as $t)
* {
* if (/$regex/) echo "matched: $car\n";
* }
*
* Doctrine_FileFinder_GlobToRegex implements glob(3) style matching that can be used to match
* against text, rather than fetching names from a filesystem.
*
* based on perl Text::Glob module.
*
* @package Doctrine
* @subpackage FileFinder
* @author Fabien Potencier <fabien.potencier@gmail.com> php port
* @author Richard Clamp <richardc@unixbeard.net> perl version
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@gmail.com>
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
* @version SVN: $Id: Doctrine_FileFinder.class.php 5110 2007-09-15 12:07:18Z fabien $
*/
class
Doctrine_FileFinder_GlobToRegex
{
protected
static
$strictLeadingDot
=
true
;
protected
static
$strictWildcardSlash
=
true
;
public
static
function
setStrictLeadingDot
(
$boolean
)
{
self
::
$strictLeadingDot
=
$boolean
;
}
public
static
function
setStrictWildcardSlash
(
$boolean
)
{
self
::
$strictWildcardSlash
=
$boolean
;
}
/**
* Returns a compiled regex which is the equiavlent of the globbing pattern.
*
* @param string glob pattern
* @return string regex
*/
public
static
function
globToRegex
(
$glob
)
{
$firstByte
=
true
;
$escaping
=
false
;
$inCurlies
=
0
;
$regex
=
''
;
for
(
$i
=
0
;
$i
<
strlen
(
$glob
);
$i
++
)
{
$car
=
$glob
[
$i
];
if
(
$firstByte
)
{
if
(
self
::
$strictLeadingDot
&&
$car
!=
'.'
)
{
$regex
.=
'(?=[^\.])'
;
}
$firstByte
=
false
;
}
if
(
$car
==
'/'
)
{
$firstByte
=
true
;
}
if
(
$car
==
'.'
||
$car
==
'('
||
$car
==
')'
||
$car
==
'|'
||
$car
==
'+'
||
$car
==
'^'
||
$car
==
'$'
)
{
$regex
.=
"
\\
$car
"
;
}
else
if
(
$car
==
'*'
)
{
$regex
.=
(
$escaping
?
"
\\
*"
:
(
self
::
$strictWildcardSlash
?
"[^/]*"
:
".*"
));
}
else
if
(
$car
==
'?'
)
{
$regex
.=
(
$escaping
?
"
\\
?"
:
(
self
::
$strictWildcardSlash
?
"[^/]"
:
"."
));
}
else
if
(
$car
==
'{'
)
{
$regex
.=
(
$escaping
?
"
\\
{"
:
"("
);
if
(
!
$escaping
)
{
++
$inCurlies
;
}
}
else
if
(
$car
==
'}'
&&
$inCurlies
)
{
$regex
.=
(
$escaping
?
"}"
:
")"
);
if
(
!
$escaping
)
{
--
$inCurlies
;
}
}
else
if
(
$car
==
','
&&
$inCurlies
)
{
$regex
.=
(
$escaping
?
","
:
"|"
);
}
else
if
(
$car
==
"
\\
"
)
{
if
(
$escaping
)
{
$regex
.=
"
\\\\
"
;
$escaping
=
false
;
}
else
{
$escaping
=
true
;
}
continue
;
}
else
{
$regex
.=
$car
;
$escaping
=
false
;
}
$escaping
=
false
;
}
return
"#^
$regex
$#"
;
}
}
\ No newline at end of file
lib/Doctrine/FileFinder/NumberCompare.php
0 → 100644
View file @
f0b01009
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_FileFinder_NumberCompare
*
* Numeric comparisons.
*
* Doctrine_FileFinder_NumberCompare compiles a simple comparison to an anonymous
* subroutine, which you can call with a value to be tested again.
*
* Now this would be very pointless, if Doctrine_FileFinder_NumberCompare didn't understand
* magnitudes.
*
* The target value may use magnitudes of kilobytes (k, ki),
* megabytes (m, mi), or gigabytes (g, gi). Those suffixed
* with an i use the appropriate 2**n version in accordance with the
* IEC standard: http://physics.nist.gov/cuu/Units/binary.html
*
* based on perl Number::Compare module.
*
* @package Doctrine
* @subpackage FileFinder
* @author Fabien Potencier <fabien.potencier@gmail.com> php port
* @author Richard Clamp <richardc@unixbeard.net> perl version
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@gmail.com>
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
* @see http://physics.nist.gov/cuu/Units/binary.html
* @version SVN: $Id: Doctrine_FileFinder.class.php 5110 2007-09-15 12:07:18Z fabien $
*/
class
Doctrine_FileFinder_NumberCompare
{
protected
$test
=
''
;
public
function
__construct
(
$test
)
{
$this
->
test
=
$test
;
}
public
function
test
(
$number
)
{
if
(
!
preg_match
(
'{^([<>]=?)?(.*?)([kmg]i?)?$}i'
,
$this
->
test
,
$matches
))
{
throw
new
Doctrine_Exception
(
sprintf
(
'don\'t understand "%s" as a test.'
,
$this
->
test
));
}
$target
=
array_key_exists
(
2
,
$matches
)
?
$matches
[
2
]
:
''
;
$magnitude
=
array_key_exists
(
3
,
$matches
)
?
$matches
[
3
]
:
''
;
if
(
strtolower
(
$magnitude
)
==
'k'
)
{
$target
*=
1000
;
}
if
(
strtolower
(
$magnitude
)
==
'ki'
)
{
$target
*=
1024
;
}
if
(
strtolower
(
$magnitude
)
==
'm'
)
{
$target
*=
1000000
;
}
if
(
strtolower
(
$magnitude
)
==
'mi'
)
{
$target
*=
1024
*
1024
;
}
if
(
strtolower
(
$magnitude
)
==
'g'
)
{
$target
*=
1000000000
;
}
if
(
strtolower
(
$magnitude
)
==
'gi'
)
{
$target
*=
1024
*
1024
*
1024
;
}
$comparison
=
array_key_exists
(
1
,
$matches
)
?
$matches
[
1
]
:
'=='
;
if
(
$comparison
==
'=='
||
$comparison
==
''
)
{
return
(
$number
==
$target
);
}
else
if
(
$comparison
==
'>'
)
{
return
(
$number
>
$target
);
}
else
if
(
$comparison
==
'>='
)
{
return
(
$number
>=
$target
);
}
else
if
(
$comparison
==
'<'
)
{
return
(
$number
<
$target
);
}
else
if
(
$comparison
==
'<='
)
{
return
(
$number
<=
$target
);
}
return
false
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment