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
554425d7
Commit
554425d7
authored
Nov 10, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintain line numbers when minifying php for the phar
parent
20eeadbc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
src/Silex/Compiler.php
src/Silex/Compiler.php
+30
-1
No files found.
src/Silex/Compiler.php
View file @
554425d7
...
@@ -80,7 +80,7 @@ class Compiler
...
@@ -80,7 +80,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
=
Kernel
::
stripComments
(
$content
);
$content
=
self
::
stripComments
(
$content
);
}
}
$content
=
str_replace
(
'@package_version@'
,
$this
->
version
,
$content
);
$content
=
str_replace
(
'@package_version@'
,
$this
->
version
,
$content
);
...
@@ -138,4 +138,33 @@ if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'
...
@@ -138,4 +138,33 @@ if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'
__HALT_COMPILER();
__HALT_COMPILER();
EOF;
EOF;
}
}
/**
* Removes comments from a PHP source string.
*
* Based on Kernel::stripComments(), but keeps line numbers intact.
*
* @param string $source A PHP string
*
* @return string The PHP string with the comments removed
*/
static
public
function
stripComments
(
$source
)
{
if
(
!
function_exists
(
'token_get_all'
))
{
return
$source
;
}
$output
=
''
;
foreach
(
token_get_all
(
$source
)
as
$token
)
{
if
(
is_string
(
$token
))
{
$output
.=
$token
;
}
elseif
(
in_array
(
$token
[
0
],
array
(
T_COMMENT
,
T_DOC_COMMENT
)))
{
$output
.=
str_repeat
(
"
\n
"
,
substr_count
(
$token
[
1
],
"
\n
"
));
}
else
{
$output
.=
$token
[
1
];
}
}
return
$output
;
}
}
}
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