Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
docs-phd5
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dmstr
docs-phd5
Commits
025cb747
Commit
025cb747
authored
Nov 28, 2017
by
Tobias Munk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated docs application commands (WIP)
parent
13758650
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
33 deletions
+147
-33
docs.php
.app/config/docs.php
+3
-1
DocsController.php
.app/src/modules/docs/commands/DocsController.php
+25
-32
EnvVisitor.php
.app/src/modules/docs/components/EnvVisitor.php
+39
-0
DocsHelper.php
.app/src/modules/docs/helpers/DocsHelper.php
+80
-0
No files found.
.app/config/docs.php
View file @
025cb747
...
...
@@ -17,7 +17,9 @@ Event::on(
return
[
'aliases'
=>
[
'schmunk42/markdocs/commands'
=>
__DIR__
.
'/../src/modules/docs/commands'
'schmunk42/markdocs/commands'
=>
__DIR__
.
'/../src/modules/docs/commands'
,
'schmunk42/markdocs/components'
=>
__DIR__
.
'/../src/modules/docs/components'
,
'schmunk42/markdocs/helpers'
=>
__DIR__
.
'/../src/modules/docs/helpers'
],
'controllerMap'
=>
[
'markdocs'
=>
DocsController
::
class
,
...
...
.app/src/modules/docs/commands/DocsController.php
View file @
025cb747
...
...
@@ -9,62 +9,55 @@
namespace
schmunk42\markdocs\commands
;
use
schmunk42\markdocs\helpers\DocsHelper
;
use
yii\console\Controller
;
use
yii\helpers\FileHelper
;
use
yii\helpers\Markdown
;
class
DocsController
extends
Controller
{
public
$verbose
=
false
;
private
$_basePath
;
private
$_toc
;
public
function
actionIndex
(
$path
)
public
function
options
(
$actionID
)
{
return
[
'verbose'
];
}
public
function
actionCheckToc
(
$path
)
{
$this
->
_basePath
=
\Yii
::
getAlias
(
$path
);
$this
->
stdout
(
'Docs'
.
PHP_EOL
);
$tocLinks
=
$this
->
parseToc
(
);
$tocLinks
=
DocsHelper
::
parseToc
(
$path
,
'README.md'
);
$files
=
FileHelper
::
findFiles
(
$path
,
[
'only'
=>
[
'*.md'
]]);
foreach
(
$files
AS
$file
)
{
#\Yii::trace("Processing {$file}...");
$this
->
stdout
(
"Processing
{
$file
}
..."
.
PHP_EOL
);
\Yii
::
trace
(
"Processing
{
$file
}
..."
);
$links
[]
=
str_replace
(
$path
,
''
,
$file
);
}
#var_dump($links, $tocLinks);
$notInToc
=
array_diff
(
$links
,
$tocLinks
);
$brokenLinks
=
array_diff
(
$tocLinks
,
$links
);
var_dump
(
$notInToc
,
$brokenLinks
);
}
p
rivate
function
markdownFileAsDomDocument
(
$file
)
p
ublic
function
actionEnvList
(
$path
)
{
$html
=
Markdown
::
process
(
file_get_contents
(
$file
));
if
(
!
$html
)
{
$this
->
stdout
(
"EMPTY!"
);
return
false
;
$files
=
FileHelper
::
findFiles
(
$path
,
[
'only'
=>
[
'*.php'
],
'except'
=>
[
'tests/'
]]);
$list
=
DocsHelper
::
findEnvVariables
(
$files
);
foreach
(
$list
as
$var
=>
$occurences
)
{
$this
->
stdout
(
"- `
{
$var
}
` "
);
if
(
$this
->
verbose
)
{
$this
->
stdout
(
"["
.
count
(
$occurences
)
.
"] "
);
foreach
(
$occurences
as
$occurence
)
{
$this
->
stdout
(
$occurence
[
'file'
]
.
":"
.
$occurence
[
'line'
]
.
";"
);
}
}
$this
->
stdout
(
PHP_EOL
);
}
$doc
=
new
\DOMDocument
();
libxml_use_internal_errors
(
true
);
$doc
->
strictErrorChecking
=
false
;
$doc
->
loadHtml
(
$html
);
echo
$html
;
return
$doc
;
}
private
function
getMarkdownFiles
()
{
}
private
function
parseToc
(
$tocFile
=
'README.md'
)
{
echo
$this
->
_basePath
.
'/'
.
$tocFile
;
$xpath
=
new
\DOMXPath
(
$this
->
markdownFileAsDomDocument
(
$this
->
_basePath
.
'/'
.
$tocFile
));
$list
=
$xpath
->
query
(
'//a'
);
foreach
(
$list
AS
$element
)
{
$links
[]
=
$element
->
getAttribute
(
'href'
);
}
return
$links
;
}
}
\ No newline at end of file
.app/src/modules/docs/components/EnvVisitor.php
0 → 100644
View file @
025cb747
<?php
namespace
schmunk42\markdocs\components
;
use
PhpParser\Node
;
use
PhpParser\NodeVisitorAbstract
;
use
yii\base\ErrorException
;
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2017 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class
EnvVisitor
extends
NodeVisitorAbstract
{
private
$_envVariables
=
[];
public
function
leaveNode
(
Node
$node
)
{
if
(
$node
instanceof
Node\Expr\FuncCall
)
{
try
{
if
(
isset
(
$node
->
name
->
parts
[
0
])
&&
$node
->
name
->
parts
[
0
]
===
'getenv'
)
{
$value
=
$node
->
args
[
0
]
->
value
;
$this
->
_envVariables
[
$value
->
value
]
=
[
'line'
=>
$value
->
getAttribute
(
'startLine'
)];
}
}
catch
(
ErrorException
$e
)
{
var_dump
(
$node
);
}
}
}
public
function
getEnvVariables
()
{
return
$this
->
_envVariables
;
}
}
\ No newline at end of file
.app/src/modules/docs/helpers/DocsHelper.php
0 → 100644
View file @
025cb747
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2017 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
schmunk42\markdocs\helpers
;
use
PhpParser\Lexer
;
use
PhpParser\Parser
;
use
schmunk42\markdocs\components\EnvVisitor
;
use
yii\helpers\FileHelper
;
use
yii\helpers\Markdown
;
class
DocsHelper
{
public
static
function
findEnvVariables
(
$files
)
{
$traverser
=
new
\PhpParser\NodeTraverser
();
$parser
=
new
Parser
(
new
Lexer
);
foreach
(
$files
as
$file
)
{
$envVisitior
=
new
EnvVisitor
();
$traverser
->
addVisitor
(
$envVisitior
);
$code
=
file_get_contents
(
$file
);
try
{
$ast
=
$parser
->
parse
(
$code
);
$traverser
->
traverse
(
$ast
);
$occurrences
=
$envVisitior
->
getEnvVariables
();
foreach
(
$occurrences
as
$var
=>
$occurrence
)
{
$list
[
$var
][]
=
[
'file'
=>
$file
,
'line'
=>
$occurrence
[
'line'
]];
}
}
catch
(
\Error
$error
)
{
\Yii
::
error
(
"Parse error:
{
$error
->
getMessage
()
}
"
);
return
;
}
}
ksort
(
$list
);
return
$list
;
}
public
static
function
getSourceFiles
(
$path
)
{
return
FileHelper
::
findFiles
(
$path
,
[
'only'
=>
[
'*.php'
]]);
}
public
static
function
parseToc
(
$basePath
,
$tocFile
=
'README.md'
)
{
echo
$basePath
.
'/'
.
$tocFile
;
$xpath
=
new
\DOMXPath
(
self
::
markdownFileAsDomDocument
(
$basePath
.
'/'
.
$tocFile
));
$list
=
$xpath
->
query
(
'//a'
);
foreach
(
$list
AS
$element
)
{
$links
[]
=
$element
->
getAttribute
(
'href'
);
}
return
$links
;
}
private
static
function
markdownFileAsDomDocument
(
$file
)
{
$html
=
Markdown
::
process
(
file_get_contents
(
$file
));
if
(
!
$html
)
{
return
false
;
}
$doc
=
new
\DOMDocument
();
libxml_use_internal_errors
(
true
);
$doc
->
strictErrorChecking
=
false
;
$doc
->
loadHtml
(
$html
);
return
$doc
;
}
private
function
getMarkdownFiles
()
{
}
}
\ 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