Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
570f475d
Commit
570f475d
authored
Mar 14, 2012
by
Jordi Boggiano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve phar compression
parent
39184eb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
src/Silex/Compiler.php
src/Silex/Compiler.php
+12
-4
No files found.
src/Silex/Compiler.php
View file @
570f475d
...
@@ -87,7 +87,7 @@ class Compiler
...
@@ -87,7 +87,7 @@ class Compiler
$path
=
str_replace
(
dirname
(
dirname
(
__DIR__
))
.
DIRECTORY_SEPARATOR
,
''
,
$file
->
getRealPath
());
$path
=
str_replace
(
dirname
(
dirname
(
__DIR__
))
.
DIRECTORY_SEPARATOR
,
''
,
$file
->
getRealPath
());
$content
=
file_get_contents
(
$file
);
$content
=
file_get_contents
(
$file
);
if
(
$strip
)
{
if
(
$strip
)
{
$content
=
self
::
strip
Comments
(
$content
);
$content
=
self
::
strip
Whitespace
(
$content
);
}
}
$content
=
str_replace
(
'@package_version@'
,
$this
->
version
,
$content
);
$content
=
str_replace
(
'@package_version@'
,
$this
->
version
,
$content
);
...
@@ -147,15 +147,15 @@ EOF;
...
@@ -147,15 +147,15 @@ EOF;
}
}
/**
/**
* Removes
comments from a PHP source string
.
* Removes
whitespace from a PHP source string while preserving line numbers
.
*
*
* Based on Kernel::stripComments(), but keeps line numbers intact.
* Based on Kernel::stripComments(), but keeps line numbers intact.
*
*
* @param string $source A PHP string
* @param string $source A PHP string
*
*
* @return string The PHP string with the
comments
removed
* @return string The PHP string with the
whitespace
removed
*/
*/
static
public
function
strip
Comments
(
$source
)
static
public
function
strip
Whitespace
(
$source
)
{
{
if
(
!
function_exists
(
'token_get_all'
))
{
if
(
!
function_exists
(
'token_get_all'
))
{
return
$source
;
return
$source
;
...
@@ -167,6 +167,14 @@ EOF;
...
@@ -167,6 +167,14 @@ EOF;
$output
.=
$token
;
$output
.=
$token
;
}
elseif
(
in_array
(
$token
[
0
],
array
(
T_COMMENT
,
T_DOC_COMMENT
)))
{
}
elseif
(
in_array
(
$token
[
0
],
array
(
T_COMMENT
,
T_DOC_COMMENT
)))
{
$output
.=
str_repeat
(
"
\n
"
,
substr_count
(
$token
[
1
],
"
\n
"
));
$output
.=
str_repeat
(
"
\n
"
,
substr_count
(
$token
[
1
],
"
\n
"
));
}
elseif
(
T_WHITESPACE
===
$token
[
0
])
{
// reduce wide spaces
$whitespace
=
preg_replace
(
'{[ \t]+}'
,
' '
,
$token
[
1
]);
// normalize newlines to \n
$whitespace
=
preg_replace
(
'{(?:\r\n|\r|\n)}'
,
"
\n
"
,
$whitespace
);
// trim leading spaces
$whitespace
=
preg_replace
(
'{\n +}'
,
"
\n
"
,
$whitespace
);
$output
.=
$whitespace
;
}
else
{
}
else
{
$output
.=
$token
[
1
];
$output
.=
$token
[
1
];
}
}
...
...
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