Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
038e6cad
Commit
038e6cad
authored
Oct 17, 2009
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Fix CLI documentation of schema-tool task
parent
cc592319
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
157 additions
and
17 deletions
+157
-17
Parser.php
lib/Doctrine/Common/Annotations/Parser.php
+5
-5
AbstractPrinter.php
lib/Doctrine/ORM/Tools/Cli/Printers/AbstractPrinter.php
+147
-6
SchemaToolTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php
+5
-6
No files found.
lib/Doctrine/Common/Annotations/Parser.php
View file @
038e6cad
...
...
@@ -201,7 +201,7 @@ class Parser
}
/**
* Annotation ::= "@" AnnotationName [
"(" [Values] ")"
]
* Annotation ::= "@" AnnotationName [
"(" [Values] ")"
]
* AnnotationName ::= QualifiedName | SimpleName
* QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
* NameSpacePart ::= identifier
...
...
@@ -262,7 +262,7 @@ class Parser
}
/**
* Values ::= Value {"," Value}*
* Values ::=
Array |
Value {"," Value}*
*
* @return array
*/
...
...
@@ -320,7 +320,7 @@ class Parser
}
/**
* PlainValue ::= integer | string | float | Array | Annotation
* PlainValue ::= integer | string | float |
boolean |
Array | Annotation
*
* @return mixed
*/
...
...
@@ -410,7 +410,7 @@ class Parser
/**
* ArrayEntry ::= Value | KeyValuePair
* KeyValuePair ::= Key "=" Value
* KeyValuePair ::= Key "="
Plain
Value
* Key ::= string | integer
*
* @return array
...
...
@@ -429,7 +429,7 @@ class Parser
$key
=
$this
->
_lexer
->
token
[
'value'
];
$this
->
match
(
'='
);
return
array
(
$key
=>
$this
->
Value
());
return
array
(
$key
=>
$this
->
Plain
Value
());
}
return
array
(
$this
->
Value
());
...
...
lib/Doctrine/ORM/Tools/Cli/Printers/AbstractPrinter.php
View file @
038e6cad
...
...
@@ -20,7 +20,7 @@
*/
namespace
Doctrine\ORM\Tools\Cli\Printers
;
error_reporting
(
E_ALL
|
E_STRICT
);
use
Doctrine\ORM\Tools\Cli\Style
;
/**
...
...
@@ -38,6 +38,11 @@ use Doctrine\ORM\Tools\Cli\Style;
*/
abstract
class
AbstractPrinter
{
/**
* Defines the tab length
*/
const
TAB_LENGTH
=
8
;
/**
* @var resource Output Stream
*/
...
...
@@ -61,7 +66,7 @@ abstract class AbstractPrinter
public
function
__construct
(
$stream
=
STDOUT
)
{
$this
->
_stream
=
$stream
;
$this
->
_maxColumnSize
=
80
;
$this
->
setMaxColumnSize
(
0
)
;
$this
->
_initStyles
();
}
...
...
@@ -74,10 +79,14 @@ abstract class AbstractPrinter
{
// Defines base styles
$this
->
addStyles
(
array
(
'HEADER'
=>
new
Style
(),
'ERROR'
=>
new
Style
(),
'WARNING'
=>
new
Style
(),
'KEYWORD'
=>
new
Style
(),
'REQ_ARG'
=>
new
Style
(),
'OPT_ARG'
=>
new
Style
(),
'INFO'
=>
new
Style
(),
'COMMENT'
=>
new
Style
(),
'HEADER'
=>
new
Style
(),
'NONE'
=>
new
Style
(),
));
}
...
...
@@ -134,11 +143,13 @@ abstract class AbstractPrinter
/**
* Sets the maximum column size (defines the CLI margin).
*
* @param integer $maxColumnSize The maximum column size for a message
* @param integer $maxColumnSize The maximum column size for a message.
* Must be higher than 25 and assigns default
* value (if invalid) to 80 columns.
*/
public
function
setMaxColumnSize
(
$maxColumnSize
)
{
$this
->
_maxColumnSize
=
$maxColumnSize
;
$this
->
_maxColumnSize
=
(
$maxColumnSize
>
25
)
?
$maxColumnSize
:
80
;
}
/**
...
...
@@ -165,6 +176,136 @@ abstract class AbstractPrinter
return
$this
->
write
(
$message
.
PHP_EOL
,
$style
);
}
public
function
writeTaskDocumentation
(
$taskName
,
$arguments
=
array
(),
$description
,
$options
=
array
())
{
// Writting task name
$this
->
write
(
'Task: '
,
'HEADER'
)
->
writeln
(
$taskName
,
'KEYWORD'
);
// Synopsis
$this
->
writeln
(
'Synopsis:'
,
'HEADER'
);
$this
->
writeSynopsis
(
$taskName
,
$arguments
);
// We need to split the description according to maximum column size
$this
->
writeln
(
'Description:'
,
'HEADER'
);
$this
->
writeDescription
(
$description
);
// Find largest length option name (it is mandatory for tab spacing)
$lengths
=
array_map
(
create_function
(
'$v'
,
'return strlen($v["name"]);'
),
$options
);
sort
(
$lengths
,
SORT_NUMERIC
);
$highestLength
=
end
(
$lengths
);
$maxTabs
=
ceil
(
$highestLength
/
self
::
TAB_LENGTH
);
// Options (required + optional arguments)
$this
->
writeln
(
'Options:'
,
'HEADER'
);
for
(
$i
=
0
,
$len
=
count
(
$options
);
$i
<
$len
;
$i
++
)
{
$this
->
writeOption
(
$options
[
$i
],
$maxTabs
,
$highestLength
);
if
(
$i
!=
$len
-
1
)
{
$this
->
write
(
PHP_EOL
);
}
}
}
public
function
writeSynopsis
(
$taskName
,
$arguments
=
array
())
{
// Required arguments
$requiredArguments
=
''
;
if
(
isset
(
$arguments
[
'required'
]))
{
$requiredArguments
=
' '
.
((
is_array
(
$arguments
[
'required'
]))
?
implode
(
' '
,
$arguments
[
'required'
])
:
$arguments
[
'required'
]);
}
// Optional arguments
$optionalArguments
=
''
;
if
(
isset
(
$arguments
[
'optional'
]))
{
$optionalArguments
=
' '
.
((
is_array
(
$arguments
[
'optional'
]))
?
implode
(
' '
,
$arguments
[
'optional'
])
:
$arguments
[
'optional'
]);
}
$this
->
write
(
$taskName
,
'KEYWORD'
);
if
((
$l
=
strlen
(
$taskName
.
$requiredArguments
))
>
$this
->
_maxColumnSize
)
{
$this
->
write
(
PHP_EOL
);
}
$this
->
write
(
' '
.
$requiredArguments
,
'REQ_ARG'
);
if
((
$l
+
strlen
(
$optionalArguments
))
>
$this
->
_maxColumnSize
)
{
$this
->
write
(
PHP_EOL
);
}
$this
->
write
(
' '
.
$optionalArguments
,
'OPT_ARG'
);
$this
->
write
(
PHP_EOL
);
}
protected
function
writeDescription
(
$description
)
{
$descriptionLength
=
strlen
(
$description
);
$startPos
=
0
;
$maxSize
=
$endPos
=
$this
->
_maxColumnSize
;
// Description
while
(
$startPos
<
$descriptionLength
)
{
$descriptionPart
=
trim
(
substr
(
$description
,
$startPos
,
$endPos
+
1
));
$endPos
=
((
$l
=
strlen
(
$descriptionPart
))
>
$maxSize
)
?
strrpos
(
$descriptionPart
,
' '
)
:
$l
;
$endPos
=
(
$endPos
===
false
)
?
strlen
(
$description
)
:
$endPos
+
1
;
// Write description line
$this
->
writeln
(
trim
(
substr
(
$description
,
$startPos
,
$endPos
)));
$startPos
+=
$endPos
;
$endPos
=
$maxSize
;
}
}
protected
function
writeOption
(
$option
,
$maxTabs
,
$highestLength
)
{
// Option name
$this
->
write
(
$option
[
'name'
],
(
isset
(
$option
[
'required'
])
&&
$option
[
'required'
])
?
'REQ_ARG'
:
'OPT_ARG'
);
// Tab spacing
$optionLength
=
strlen
(
$option
[
'name'
]);
$tabs
=
floor
(
$optionLength
/
self
::
TAB_LENGTH
);
$decrementer
=
0
;
//echo '[' .$tabs. ']';
if
((
$optionLength
%
self
::
TAB_LENGTH
!=
0
))
{
$decrementer
=
1
;
//$tabs--;
}
$this
->
write
(
str_repeat
(
" "
,
(
$maxTabs
-
$tabs
)
*
self
::
TAB_LENGTH
));
// Description
$descriptionLength
=
strlen
(
$option
[
'description'
]);
$startPos
=
0
;
$maxSize
=
$endPos
=
$this
->
_maxColumnSize
-
(
$maxTabs
*
self
::
TAB_LENGTH
);
while
(
$startPos
<
$descriptionLength
)
{
$descriptionPart
=
trim
(
substr
(
$option
[
'description'
],
$startPos
,
$endPos
+
1
));
$endPos
=
((
$l
=
strlen
(
$descriptionPart
))
>=
$maxSize
)
?
strrpos
(
$descriptionPart
,
' '
)
:
$l
;
$endPos
=
(
$endPos
===
false
)
?
strlen
(
$option
[
'description'
])
:
$endPos
+
1
;
$descriptionLine
=
((
$startPos
!=
0
)
?
str_repeat
(
" "
,
$maxTabs
*
self
::
TAB_LENGTH
)
:
''
)
.
trim
(
substr
(
$option
[
'description'
],
$startPos
,
$endPos
));
$this
->
writeln
(
$descriptionLine
);
$startPos
+=
$endPos
;
$endPos
=
$maxSize
;
}
}
/**
* Formats the given message with the defined style.
*
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php
View file @
038e6cad
...
...
@@ -68,14 +68,14 @@ class SchemaToolTask extends AbstractTask
->
writeln
(
"
\t\t
Updates the schema in EntityManager (update tables on Database)"
)
->
writeln
(
"
\t\t\t
If defined, --create and --drop can not be requested on same task"
)
->
write
(
PHP_EOL
)
->
write
(
'--re-create'
,
'REQ_ARG'
)
->
writeln
(
"
\t\t
Runs --drop then --create to re-create the database."
)
->
write
(
PHP_EOL
)
->
write
(
'--dump-sql'
,
'OPT_ARG'
)
->
writeln
(
"
\t\t
Instead of try to apply generated SQLs into EntityManager, output them."
)
->
write
(
PHP_EOL
)
->
write
(
'--class-dir=<path>'
,
'OPT_ARG'
)
->
writeln
(
"
\t
Optional class directory to fetch for Entities."
)
->
write
(
PHP_EOL
)
->
write
(
'--re-create'
,
'OPT_ARG'
)
->
writeln
(
"
\t\t
Runs --drop then --create to re-create the database."
)
->
write
(
PHP_EOL
);
}
...
...
@@ -90,9 +90,8 @@ class SchemaToolTask extends AbstractTask
private
function
_writeSynopsis
(
$printer
)
{
$printer
->
write
(
'schema-tool'
,
'KEYWORD'
)
->
write
(
' (--create | --drop | --update)'
,
'REQ_ARG'
)
->
write
(
' [--dump-sql] [--class-dir=<path>]'
,
'OPT_ARG'
)
->
writeln
(
' [--re-create]'
,
'OPT_ARG'
);
->
write
(
' (--create | --drop | --update | --re-create)'
,
'REQ_ARG'
)
->
writeln
(
' [--dump-sql] [--class-dir=<path>]'
,
'OPT_ARG'
);
}
/**
...
...
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