Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
e33aa9fc
Commit
e33aa9fc
authored
Jan 05, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified model and context creation
parent
b17c8270
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
122 deletions
+93
-122
BaseDoc.php
extensions/yii/apidoc/models/BaseDoc.php
+17
-0
ClassDoc.php
extensions/yii/apidoc/models/ClassDoc.php
+5
-28
Context.php
extensions/yii/apidoc/models/Context.php
+56
-9
File.php
extensions/yii/apidoc/models/File.php
+0
-54
InterfaceDoc.php
extensions/yii/apidoc/models/InterfaceDoc.php
+4
-16
TraitDoc.php
extensions/yii/apidoc/models/TraitDoc.php
+5
-15
class.php
extensions/yii/apidoc/views/class.php
+6
-0
No files found.
extensions/yii/apidoc/models/BaseDoc.php
View file @
e33aa9fc
...
...
@@ -22,6 +22,23 @@ class BaseDoc extends Object
public
$startLine
;
public
$endLine
;
/**
* @param \phpDocumentor\Reflection\BaseReflector $reflector
* @param array $config
*/
public
function
__construct
(
$reflector
,
$config
=
[])
{
// base properties
$this
->
name
=
ltrim
(
$reflector
->
getName
(),
'\\'
);
$this
->
startLine
=
$reflector
->
getNode
()
->
getAttribute
(
'startLine'
);
$this
->
endLine
=
$reflector
->
getNode
()
->
getAttribute
(
'endLine'
);
// TODO docblock
parent
::
__construct
(
$config
);
}
public
function
loadSource
(
$reflection
)
{
$this
->
sourcePath
=
str_replace
(
'\\'
,
'/'
,
str_replace
(
YII_PATH
,
''
,
$reflection
->
getFileName
()));
...
...
extensions/yii/apidoc/models/ClassDoc.php
View file @
e33aa9fc
...
...
@@ -19,37 +19,23 @@ class ClassDoc extends BaseDoc
public
$interfaces
=
[];
public
$traits
=
[];
// will be set by Context::updateReferences()
public
$subclasses
=
[];
// TODO
public
$properties
=
[];
public
$methods
=
[];
public
$events
=
[];
public
$constants
=
[];
// public $protectedPropertyCount=0;
// public $publicPropertyCount=0;
// public $protectedMethodCount=0;
// public $publicMethodCount=0;
//
// public $nativePropertyCount=0;
// public $nativeMethodCount=0;
// public $nativeEventCount=0;
public
$sinceVersion
;
public
$subclasses
=
[];
/**
* @param \phpDocumentor\Reflection\ClassReflector $reflector
* @param Context $context
* @param array $config
*/
public
function
__construct
(
$reflector
,
$con
text
=
null
,
$con
fig
=
[])
public
function
__construct
(
$reflector
,
$config
=
[])
{
// base properties
$this
->
name
=
ltrim
(
$reflector
->
getName
(),
'\\'
);
$this
->
startLine
=
$reflector
->
getNode
()
->
getAttribute
(
'startLine'
);
$this
->
endLine
=
$reflector
->
getNode
()
->
getAttribute
(
'endLine'
);
parent
::
__construct
(
$reflector
,
$config
);
$this
->
parentClass
=
ltrim
(
$reflector
->
getParentClass
(),
'\\'
);
if
(
empty
(
$this
->
parentClass
))
{
...
...
@@ -68,13 +54,5 @@ class ClassDoc extends BaseDoc
// TODO methods
// TODO properties
// TODO docblock
if
(
$context
!==
null
)
{
$context
->
addClass
(
$this
);
}
parent
::
__construct
(
$config
);
}
}
\ No newline at end of file
extensions/yii/apidoc/models/Context.php
View file @
e33aa9fc
...
...
@@ -8,15 +8,16 @@
namespace
yii\apidoc\models
;
use
phpDocumentor\Reflection\FileReflector
;
use
yii\base\Component
;
use
yii\base\Exception
;
class
Context
extends
Component
{
public
$basePath
;
/**
* @var array list of php files that have been added to this context.
*/
public
$files
=
[];
/**
* @var ClassDoc[]
*/
...
...
@@ -30,32 +31,66 @@ class Context extends Component
*/
public
$traits
=
[];
public
function
addFile
(
$fileName
)
{
$file
=
new
File
(
$fileName
,
$this
);
$this
->
files
[
$fileName
]
=
$file
;
if
(
isset
(
$this
->
files
[
$fileName
]))
{
return
;
}
$this
->
files
[
$fileName
]
=
$fileName
;
$reflection
=
new
FileReflector
(
$fileName
,
true
);
$reflection
->
process
();
foreach
(
$reflection
->
getClasses
()
as
$class
)
{
$class
=
new
ClassDoc
(
$class
,
$this
);
$class
->
sourceFile
=
$fileName
;
$this
->
addClass
(
$class
);
}
foreach
(
$reflection
->
getInterfaces
()
as
$interface
)
{
$interface
=
new
InterfaceDoc
(
$interface
,
$this
);
$interface
->
sourceFile
=
$fileName
;
$this
->
addInterface
(
$interface
);
}
foreach
(
$reflection
->
getTraits
()
as
$trait
)
{
$trait
=
new
TraitDoc
(
$trait
,
$this
);
$trait
->
sourceFile
=
$fileName
;
$this
->
addTrait
(
$trait
);
}
}
/**
* @param ClassDoc $class
* @throws \yii\base\Exception when class is already part of this context
*/
public
function
addClass
(
$class
)
{
if
(
isset
(
$this
->
classes
[
$class
->
name
]))
{
throw
new
Exception
(
'Duplicate class definition: '
.
$class
->
name
.
' in file '
.
$class
->
fileName
);
throw
new
Exception
(
'Duplicate class definition: '
.
$class
->
name
.
' in file '
.
$class
->
sourceFile
.
'.'
);
}
$this
->
classes
[
$class
->
name
]
=
$class
;
}
/**
* @param InterfaceDoc $interface
* @throws \yii\base\Exception when interface is already part of this context
*/
public
function
addInterface
(
$interface
)
{
if
(
isset
(
$this
->
interfaces
[
$interface
->
name
]))
{
throw
new
Exception
(
'Duplicate interface definition: '
.
$interface
->
name
.
' in file '
.
$interface
->
fileNam
e
);
throw
new
Exception
(
'Duplicate interface definition: '
.
$interface
->
name
.
' in file '
.
$interface
->
sourceFil
e
);
}
$this
->
interfaces
[
$interface
->
name
]
=
$interface
;
}
/**
* @param TraitDoc $trait
* @throws \yii\base\Exception when trait is already part of this context
*/
public
function
addTrait
(
$trait
)
{
if
(
isset
(
$this
->
traits
[
$trait
->
name
]))
{
throw
new
Exception
(
'Duplicate trait definition: '
.
$trait
->
name
.
' in file '
.
$trait
->
fileNam
e
);
throw
new
Exception
(
'Duplicate trait definition: '
.
$trait
->
name
.
' in file '
.
$trait
->
sourceFil
e
);
}
$this
->
traits
[
$trait
->
name
]
=
$trait
;
}
...
...
@@ -74,7 +109,19 @@ class Context extends Component
foreach
(
$this
->
classes
as
$class
)
{
$this
->
updateSubclassInferfacesTraits
(
$class
);
}
// TODO update interface and trait usages
// update implementedBy and usedBy for interfaces and traits
foreach
(
$this
->
classes
as
$class
)
{
foreach
(
$class
->
interfaces
as
$interface
)
{
if
(
isset
(
$this
->
interfaces
[
$interface
]))
{
$this
->
interfaces
[
$interface
]
->
implementedBy
[]
=
$class
->
name
;
}
}
foreach
(
$class
->
traits
as
$trait
)
{
if
(
isset
(
$this
->
traits
[
$trait
]))
{
$this
->
traits
[
$trait
]
->
usedBy
[]
=
$class
->
name
;
}
}
}
}
/**
...
...
extensions/yii/apidoc/models/File.php
deleted
100644 → 0
View file @
b17c8270
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\apidoc\models
;
use
phpDocumentor\Reflection\FileReflector
;
use
yii\base\Object
;
class
File
extends
Object
{
public
$name
;
public
$namespaces
=
[];
/**
* @var ClassDoc[]
*/
public
$classes
=
[];
/**
* @var InterfaceDoc[]
*/
public
$interfaces
=
[];
/**
* @var TraitDoc[]
*/
public
$traits
=
[];
private
$_reflection
;
public
function
__construct
(
$fileName
,
$context
,
$config
=
[])
{
$this
->
name
=
$fileName
;
$this
->
_reflection
=
new
FileReflector
(
$fileName
,
true
);
$this
->
_reflection
->
process
();
foreach
(
$this
->
_reflection
->
getClasses
()
as
$class
)
{
$class
=
new
ClassDoc
(
$class
,
$context
);
$class
->
sourceFile
=
$fileName
;
$this
->
classes
[]
=
$class
;
}
foreach
(
$this
->
_reflection
->
getInterfaces
()
as
$interface
)
{
$this
->
interfaces
[]
=
new
InterfaceDoc
(
$interface
,
$context
);
}
foreach
(
$this
->
_reflection
->
getTraits
()
as
$trait
)
{
$this
->
traits
[]
=
new
TraitDoc
(
$trait
,
$context
);
}
parent
::
__construct
(
$config
);
}
}
\ No newline at end of file
extensions/yii/apidoc/models/InterfaceDoc.php
View file @
e33aa9fc
...
...
@@ -11,35 +11,24 @@ class InterfaceDoc extends BaseDoc
{
public
$parentInterfaces
=
[];
// will be set by Context::updateReferences()
public
$implementedBy
=
[];
// TODO
public
$methods
=
[];
/**
* @param \phpDocumentor\Reflection\InterfaceReflector $reflector
* @param Context $context
* @param array $config
*/
public
function
__construct
(
$reflector
,
$con
text
=
null
,
$con
fig
=
[])
public
function
__construct
(
$reflector
,
$config
=
[])
{
// base properties
$this
->
name
=
ltrim
(
$reflector
->
getName
(),
'\\'
);
$this
->
startLine
=
$reflector
->
getNode
()
->
getAttribute
(
'startLine'
);
$this
->
endLine
=
$reflector
->
getNode
()
->
getAttribute
(
'endLine'
);
parent
::
__construct
(
$reflector
,
$config
);
foreach
(
$reflector
->
getParentInterfaces
()
as
$interface
)
{
$this
->
parentInterfaces
[]
=
ltrim
(
$interface
,
'\\'
);
}
// TODO methods
// TODO docblock
if
(
$context
!==
null
)
{
$context
->
addInterface
(
$this
);
}
parent
::
__construct
(
$config
);
}
}
\ No newline at end of file
extensions/yii/apidoc/models/TraitDoc.php
View file @
e33aa9fc
...
...
@@ -10,25 +10,23 @@ namespace yii\apidoc\models;
class
TraitDoc
extends
BaseDoc
{
// classes using the trait
public
$usedByClasses
=
[];
// will be set by Context::updateReferences()
public
$usedBy
=
[];
public
$traits
=
[];
// TODO
public
$properties
=
[];
public
$methods
=
[];
/**
* @param \phpDocumentor\Reflection\TraitReflector $reflector
* @param Context $context
* @param array $config
*/
public
function
__construct
(
$reflector
,
$con
text
=
null
,
$con
fig
=
[])
public
function
__construct
(
$reflector
,
$config
=
[])
{
// base properties
$this
->
name
=
ltrim
(
$reflector
->
getName
(),
'\\'
);
$this
->
startLine
=
$reflector
->
getNode
()
->
getAttribute
(
'startLine'
);
$this
->
endLine
=
$reflector
->
getNode
()
->
getAttribute
(
'endLine'
);
parent
::
__construct
(
$reflector
,
$config
);
foreach
(
$reflector
->
getTraits
()
as
$trait
)
{
$this
->
traits
[]
=
ltrim
(
$trait
,
'\\'
);
...
...
@@ -38,12 +36,5 @@ class TraitDoc extends BaseDoc
// TODO properties
// TODO docblock
if
(
$context
!==
null
)
{
$context
->
addTrait
(
$this
);
}
parent
::
__construct
(
$config
);
}
}
\ No newline at end of file
extensions/yii/apidoc/views/class.php
View file @
e33aa9fc
...
...
@@ -15,6 +15,12 @@ use yii\apidoc\models\TraitDoc;
}
elseif
(
$item
instanceof
TraitDoc
)
{
echo
'Trait '
;
}
else
{
if
(
$item
->
isFinal
)
{
echo
'Final '
;
}
if
(
$item
->
isAbstract
)
{
echo
'Abstract '
;
}
echo
'Class '
;
}
echo
$item
->
name
;
...
...
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