Skip to content

Commit a9d5f81

Browse files
committed
added basic index generation
1 parent 64f72f8 commit a9d5f81

31 files changed

Lines changed: 1029 additions & 385 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
vendor/
12
tests/
2-
phpcompletePSR.rar

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ To enable omni complete add following line to `.vimrc`,
107107

108108
Then issuing `<C-X><C-O>` in insert mode will open the completion pop-up menu.
109109

110-
This plugin is tested in Windows and Linux. It should work in OSX also.
110+
This plugin is tested in Windows and Linux. It should work in OSX also.
111111

112112
For now this plugin supports [Composer](http://getcomposer.org/) PHP projects.
113113
Upon detecting a composer project the plugin scans classmap generated by `php
114114
composer.phar dumpautoload --optimize` command. By default composer command is
115115
set to `php composer.phar`. The command can be changed by setting
116-
`g:phpcomplete_index_composer_command` global variable.
116+
`g:phpcomplete_index_composer_command` global variable.
117117

118118
The plugin is dependent on `@var`, `@param`, `@return` doc-comments to give proper context aware
119119
autocomplete. So documenting your class will help tremendously. It does not
@@ -155,7 +155,7 @@ Extensions
155155
Phpcomplete Extended pluign exposes api hooks so that it can be possible to
156156
provide framework specific autocomplete suggestion. For example facades in
157157
laravel, DIC services in Symfony2 etc. The plugin api divided in two part, `PHP`
158-
and `vim`. PHP part is responsible for creating index related to the framework,
158+
and `vim`. PHP part is responsible for creating index related to the framework,
159159
and vim part is responsible for providing autocomplete menu entries based on the
160160
index. For reference see
161161
[phpcomplete-extended-symfony](https://github.com/m2mdas/phpcomplete-extended-symfony)
@@ -166,10 +166,11 @@ License
166166
-------
167167
MIT licensed.
168168

169-
Acknowledgement
170-
---------------
169+
Acknowledgement
170+
---------------
171171

172-
This plugin would not be possible without the works of
172+
This plugin would not be possible without the works of
173+
[M2mdas](https://github.com/m2mdas),
173174
[Shougo](https://github.com/Shougo),
174175
[shawncplus](https://github.com/shawncplus/),
175176
[tpope](https://github.com/tpope/), [vim-jp](https://github.com/vim-jp),

bin/indexer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4-
require(__DIR__ . "/vendor/autoload.php");
4+
require(dirname(__DIR__) . "/vendor/autoload.php");
55

66
set_time_limit(0);
77
ini_set('memory_limit','1000M');
@@ -24,5 +24,4 @@
2424
} else {
2525
$command = new \Command\ErrorCommand;
2626
}
27-
2827
$command->run($arguments);

bin/src/Command/GenerateCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ public function run(array $arguments = []){
1010
$generator = $this->get("IndexGenerator");
1111

1212
$index = $generator->generateIndex($this->get("Index"));
13-
printf("Parsed: %d, time: %f\n", count($index->getClassMap()), microtime(true) - $time);
1413
$index = $this->prepareIndex($index);
15-
printf("time: %f\n", microtime(true) - $time);
16-
return;
1714
$indexWriter = $this->get('IndexWriter');
1815

1916
$indexWriter->writeIndex($index);
20-
$indexWriter->writeReport($generator->getInvalidClasses());
17+
//$indexWriter->writeReport($generator->getInvalidClasses());
2118
}
2219
protected function prepareIndex($index){
2320
$jsonIndex = json_encode($index->toArray());

bin/src/DI/Container.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ public function __construct(){
99
$this->loadBasicServices();
1010
$this->loadParser();
1111
$this->map['Composer'] = new \Utils\Composer($this->get("Path"));
12-
$this->map['ClassUtils'] = new \Utils\ClassUtils(
12+
$this->map["ClassUtils"] = new \Utils\ClassUtils(
1313
$this->get("Path"),
14-
$this->get("ClassParser")
14+
$this->get("Parser")
1515
);
1616
$this->map["IndexGenerator"] = new \IndexGenerator(
1717
$this->get("Path"),
1818
$this->get("Composer"),
1919
$this->get("ClassUtils")
2020
);
2121
$this->map["IndexWriter"] = new \Utils\IndexWriter(
22-
$this->get("IndexGenerator"),
2322
$this->get("Path")
2423
);
2524
}
@@ -28,7 +27,7 @@ public function get($service){
2827
return $this->map[$service];
2928
}
3029
else {
31-
throw new \Exception("Unknown service \"{$service}\"");
30+
throw new ServiceNotFoundException("Unknown service \"{$service}\"");
3231
}
3332
}
3433
public function set($serviceName, $service, $overwrite = false){
@@ -42,7 +41,7 @@ public function set($serviceName, $service, $overwrite = false){
4241
}
4342
private function loadBasicServices(){
4443
$this->map = [
45-
'Index' => new \DTO\Index(),
44+
'Index' => new \Entity\Index(),
4645
'PathUtils' => new \Phine\Path\Path(),
4746
'PhpParser' => new \PhpParser\Parser(new \PhpParser\Lexer),
4847
'Traverser' => new \PhpParser\NodeTraverser(),
@@ -51,11 +50,36 @@ private function loadBasicServices(){
5150
$this->map['Path'] = new \Utils\PathResolver($this->get("PathUtils"));
5251
}
5352
private function loadParser(){
54-
$this->map['ClassParser'] = new \Parser\ClassParser(
53+
$this->set("UseParser", new \Parser\UseParser);
54+
$this->set("MethodParser", new \Parser\MethodParser(
55+
$this->get("UseParser")
56+
));
57+
$this->set("PropertyParser", new \Parser\PropertyParser(
58+
$this->get("UseParser")
59+
));
60+
$this->set("CommentParser", new \Parser\CommentParser(
61+
$this->get("UseParser")
62+
));
63+
$this->map["ClassParser"] = new \Parser\ClassParser(
64+
$this->get("CommentParser"),
65+
$this->get("MethodParser"),
66+
$this->get("PropertyParser"),
67+
$this->get("UseParser")
68+
);
69+
$this->map["InterfaceParser"] = new \Parser\InterfaceParser(
70+
$this->get("CommentParser"),
71+
$this->get("MethodParser"),
72+
$this->get("PropertyParser")
73+
);
74+
75+
$this->map['Parser'] = new \Parser\Parser(
5576
$this->get("PhpParser"),
77+
$this->get("ClassParser"),
78+
$this->get("InterfaceParser"),
79+
$this->get("UseParser"),
5680
$this->get("Path")
5781
);
58-
$this->map['ClassParser']->setTraverser($this->get('Traverser'));
59-
$this->map['ClassParser']->setVisitor($this->get('Visitor'));
82+
$this->map['Parser']->setTraverser($this->get('Traverser'));
83+
$this->map['Parser']->setVisitor($this->get('Visitor'));
6084
}
6185
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace DI;
4+
5+
class ServiceNotFoundException extends \Exception {
6+
7+
}

bin/src/DTO/FQCN.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

bin/src/DTO/MethodData.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

bin/src/Entity/ClassData.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Entity;
4+
5+
class ClassData{
6+
const MODIFIER_PUBLIC = 1;
7+
const MODIFIER_PROTECTED = 2;
8+
const MODIFIER_PRIVATE = 4;
9+
const MODIFIER_STATIC = 8;
10+
const MODIFIER_ABSTRACT = 16;
11+
const MODIFIER_FINAL = 32;
12+
public $interfaces = [];
13+
public $parentClasses = [];
14+
public $methods;
15+
public $properties;
16+
public $constants = [];
17+
/** @var Uses */
18+
public $uses;
19+
20+
/**
21+
*
22+
* @var FQCN
23+
*/
24+
public $fqcn;
25+
public $doc = "";
26+
public $startLine = 0;
27+
public $file = "";
28+
public function __construct(FQCN $fqcn, $file){
29+
$this->fqcn = $fqcn;
30+
$this->file = $file;
31+
$this->methods = new MethodsCollection();
32+
$this->properties = new PropertiesCollection();
33+
}
34+
public function getParentClass(){
35+
return "";
36+
}
37+
public function setParentClass($parentClass){
38+
if(!in_array($parentClass, $this->parentClasses)){
39+
array_unshift($this->parentClasses, $parentClass);
40+
}
41+
}
42+
public function addInterface($interface){
43+
if(!in_array($interface, $this->interfaces)){
44+
$this->interfaces[] = $interface;
45+
}
46+
}
47+
public function addMethod(MethodData $method){
48+
$this->methods->add($method);
49+
}
50+
public function addProp(ClassProperty $prop){
51+
$this->properties->add($prop);
52+
}
53+
public function addConst($constName){
54+
if(!in_array($constName, $this->constants)){
55+
$this->constants[] = $constName;
56+
}
57+
}
58+
public function toArray(){
59+
return [
60+
"methods" => $this->methods->toArray(),
61+
"namespaces" => $this->uses->toArray(),
62+
"properties" => $this->properties->toArray(),
63+
"constants" => $this->constants,
64+
"interfaces" => $this->interfaces,
65+
"classname" => $this->fqcn->className,
66+
"parentclasses" => $this->parentClasses,
67+
"docComment" => $this->doc,
68+
"startLine" => $this->startLine,
69+
"file" => $this->file,
70+
"parentclass" => $this->getParentClass()
71+
];
72+
}
73+
}

bin/src/Entity/ClassProperty.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Entity;
4+
5+
class ClassProperty {
6+
public $name = "";
7+
public $modifier = 0;
8+
public $type = "";
9+
public $defauls = "";
10+
public $doc = "";
11+
12+
public function isPublic() {
13+
return (bool) ($this->modifier & ClassData::MODIFIER_PUBLIC);
14+
}
15+
16+
public function isProtected() {
17+
return (bool) ($this->modifier & ClassData::MODIFIER_PROTECTED);
18+
}
19+
20+
public function isPrivate() {
21+
return (bool) ($this->modifier & ClassData::MODIFIER_PRIVATE);
22+
}
23+
24+
public function isStatic() {
25+
return (bool) ($this->modifier & ClassData::MODIFIER_STATIC);
26+
}
27+
28+
public function setModifier($modifier){
29+
$this->modifier = $modifier;
30+
}
31+
32+
public function toArray(){
33+
return [
34+
'type' => $this->type,
35+
'docComment' => $this->doc,
36+
'array_type' => 0,
37+
'inheritdoc' => 0
38+
];
39+
}
40+
}

0 commit comments

Comments
 (0)