Skip to content

Commit

Permalink
PHP - Detect static function modifier and allow all characters in arg…
Browse files Browse the repository at this point in the history
…uments
  • Loading branch information
Hirse committed Mar 12, 2015
1 parent 733434b commit aa82ba3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/languages/PHP.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define(function (require, exports, module) {
var defaultVisibilty = "public";
var unnamedPlaceholder = "function";

function createListEntry(name, args, vis, line, ch) {
function createListEntry(name, args, vis, isStatic, line, ch) {
var $elements = [];
var $name = $(document.createElement("span"));
$name.addClass("outline-entry-name");
Expand All @@ -16,11 +16,15 @@ define(function (require, exports, module) {
$arguments.addClass("outline-entry-arg");
$arguments.text(args);
$elements.push($arguments);
var classes = "outline-entry-php outline-entry-icon outline-entry-" + vis;
if (isStatic) {
classes += " outline-entry-static";
}
return {
name: name,
line: line,
ch: ch,
classes: "outline-entry-php outline-entry-icon outline-entry-" + vis,
classes: classes,
$html: $elements
};
}
Expand All @@ -33,14 +37,15 @@ define(function (require, exports, module) {
* @returns {Array} List of outline entries.
*/
function getOutlineList(lines, showArguments, showUnnamed) {
var regex = /(?:([\w$]+)\s*[=:]\s*)?(public|protected|private)?\s*function(?:\s+(?:&\s*)?([\w]+))?\s*(\([\w,\s&$='"\\()]*\))/g;
var regex = /(?:([\w$]+)\s*[=:]\s*)?(public|protected|private)?\s*(static)?\s*function(?:\s+(?:&\s*)?([\w]+))?\s*(\(.*\))/g;
var result = [];
lines.forEach(function (line, index) {
var match = regex.exec(line);
while (match !== null) {
var name = (match[1] || match[3] || "").trim();
var name = (match[1] || match[4] || "").trim();
var vis = match[2] || defaultVisibilty;
var args = showArguments ? match[4] : "";
var isStatic = match[3] === "static";
var args = showArguments ? match[5] : "";
match = regex.exec(line);
if (name.length === 0) {
if (showUnnamed) {
Expand All @@ -50,7 +55,7 @@ define(function (require, exports, module) {
continue;
}
}
result.push(createListEntry(name, args, vis, index, line.length));
result.push(createListEntry(name, args, vis, isStatic, index, line.length));
}
});
return result;
Expand Down
5 changes: 5 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
.outline-entry-icon:before {
display: inline-block;
font-family: Ionicons;
font-style: normal;
margin-right: 3px;
text-align: center;
width: 12px;
Expand Down Expand Up @@ -222,6 +223,10 @@
font-family: sans-serif;
}

.outline-entry-php.outline-entry-static {
font-style: italic;
}


/* Markdown */
.outline-entry-md {
Expand Down

0 comments on commit aa82ba3

Please sign in to comment.