Skip to content

Commit f488762

Browse files
committed
[minor] CS: Use tabs for indentation
1 parent fe2e61c commit f488762

File tree

3 files changed

+158
-158
lines changed

3 files changed

+158
-158
lines changed

src/CompanionGenerator.php

+144-144
Original file line numberDiff line numberDiff line change
@@ -21,148 +21,148 @@
2121
abstract class CompanionGenerator
2222
{
2323

24-
private $namingStrategy;
25-
private $outputPath;
26-
private $tmpl;
27-
28-
/**
29-
* Create a new generator that outputs to the given path. The given output
30-
* path is used as a base path. The generation logic will append a PSR-0
31-
* compliant path to the specified path, taking into account both the value
32-
* of getCompanionNamespace() and the name of the companion as generated by
33-
* the NamingStrategy.
34-
*
35-
* # Example
36-
* For a class my\ns\Definition, the DefaultNamingStrategy and the following
37-
* implementation:
38-
*
39-
* class MyGenerator extends AbstractGenerator {
40-
* protected static $actorNamespace = 'my\dynamic\ns';
41-
*
42-
* public function __construct() {
43-
* parent::__construct('/path/to/site/target');
44-
* }
45-
*
46-
* protected function getCompanionNamespace() {
47-
* return 'my\dynamic\ns';
48-
* }
49-
*
50-
* // ...
51-
* }
52-
*
53-
* The companion will be my\dynamic\ns\my_ns_Definition and will output at
54-
* /path/to/site/target/my/dynamic/ns/my/ns/Definition.php
55-
*
56-
* @param string $outputPath The target path for the generated companion.
57-
*/
58-
public function __construct($outputPath)
59-
{
60-
$this->outputPath = rtrim($outputPath, '/');
61-
}
62-
63-
/**
64-
* Generate the code. This method delegates to the implementation for the
65-
* acutal generation then outputs to the specified path.
66-
*
67-
* @param string $defClass The definition for which to generate an actor.
68-
*/
69-
public function generate($defClass) {
70-
$this->init();
71-
72-
$templatePath = $this->getTemplatePath($defClass);
73-
74-
$companionNs = $this->getCompanionNamespace($defClass);
75-
$companionClass = $this->namingStrategy->getCompanionClassName(
76-
$defClass
77-
);
78-
$targetDir = $this->outputPath . '/' . $this->toPath($companionNs);
79-
$fileName = $this->toPath($companionClass);
80-
$outPath = $targetDir . '/' . $fileName . '.php';
81-
82-
$values = $this->getValues($defClass);
83-
$values['companionNs'] = $companionNs;
84-
$values['companionClass'] = $companionClass;
85-
$values['model'] = $defClass;
86-
$values['modelStr'] = str_replace('\\', '\\\\', $defClass);
87-
88-
$resolver = new TemplateResolver();
89-
$resolver->resolve($templatePath, $outPath, $values);
90-
}
91-
92-
/**
93-
* Getter for the generator's naming strategy. Access is useful when
94-
* a companion class name needs to be determined outside of normal companion
95-
* generation and loading.
96-
*
97-
* @return NamingStrategy
98-
*/
99-
public function getNamingStrategy() {
100-
return $this->namingStrategy;
101-
}
102-
103-
/**
104-
* This method is responsible for returning the base namespace in which
105-
* companion object reside.
106-
*
107-
* @param string $defClass The name of the class for which a companion is
108-
* being generated. This allows implementations to return different base
109-
* namespaces for a possible hierarchy of definitions.
110-
* @return string
111-
*/
112-
protected abstract function getCompanionNamespace($defClass);
113-
114-
/**
115-
* This method is responsible for returning the path to the template that is
116-
* used to generate the actor.
117-
*
118-
* @param string $defClass The name of the class for which a companion is
119-
* being generated. This allows implementations to return different
120-
* templates for different definitions.
121-
* @return string
122-
*/
123-
protected abstract function getTemplatePath($defClass);
124-
125-
/**
126-
* This method is responsible for actually generating the substitution values
127-
* for generating the actor for the specified definition class. These values
128-
* will be substituted into the template specified by getTemplatePath().
129-
*
130-
* @param string $defClass The name of the definition class.
131-
* @return array Substitution values for generating the actor.
132-
*/
133-
protected abstract function getValues($defClass);
134-
135-
/*
136-
* =========================================================================
137-
* Dependency setters
138-
* =========================================================================
139-
*/
140-
141-
public function setNamingStrategy(NamingStrategy $namingStrategy)
142-
{
143-
$this->namingStrategy = $namingStrategy;
144-
}
145-
146-
/*
147-
* =========================================================================
148-
* Private helpers
149-
* =========================================================================
150-
*/
151-
152-
/* Ensure dependency are initialized */
153-
private function init() {
154-
// Ensure that injectable dependencies have an implementation available.
155-
if ($this->namingStrategy === null) {
156-
$this->namingStrategy = new DefaultNamingStrategy();
157-
}
158-
159-
// If the template hasn't been set then initialize this instance
160-
if ($this->tmpl === null) {
161-
}
162-
}
163-
164-
/* Convert the given namespace/classname to a path fragment. */
165-
private function toPath($name) {
166-
return str_replace(array('\\', '_'), '/', $name);
167-
}
24+
private $namingStrategy;
25+
private $outputPath;
26+
private $tmpl;
27+
28+
/**
29+
* Create a new generator that outputs to the given path. The given output
30+
* path is used as a base path. The generation logic will append a PSR-0
31+
* compliant path to the specified path, taking into account both the value
32+
* of getCompanionNamespace() and the name of the companion as generated by
33+
* the NamingStrategy.
34+
*
35+
* # Example
36+
* For a class my\ns\Definition, the DefaultNamingStrategy and the following
37+
* implementation:
38+
*
39+
* class MyGenerator extends AbstractGenerator {
40+
* protected static $actorNamespace = 'my\dynamic\ns';
41+
*
42+
* public function __construct() {
43+
* parent::__construct('/path/to/site/target');
44+
* }
45+
*
46+
* protected function getCompanionNamespace() {
47+
* return 'my\dynamic\ns';
48+
* }
49+
*
50+
* // ...
51+
* }
52+
*
53+
* The companion will be my\dynamic\ns\my_ns_Definition and will output at
54+
* /path/to/site/target/my/dynamic/ns/my/ns/Definition.php
55+
*
56+
* @param string $outputPath The target path for the generated companion.
57+
*/
58+
public function __construct($outputPath)
59+
{
60+
$this->outputPath = rtrim($outputPath, '/');
61+
}
62+
63+
/**
64+
* Generate the code. This method delegates to the implementation for the
65+
* acutal generation then outputs to the specified path.
66+
*
67+
* @param string $defClass The definition for which to generate an actor.
68+
*/
69+
public function generate($defClass) {
70+
$this->init();
71+
72+
$templatePath = $this->getTemplatePath($defClass);
73+
74+
$companionNs = $this->getCompanionNamespace($defClass);
75+
$companionClass = $this->namingStrategy->getCompanionClassName(
76+
$defClass
77+
);
78+
$targetDir = $this->outputPath . '/' . $this->toPath($companionNs);
79+
$fileName = $this->toPath($companionClass);
80+
$outPath = $targetDir . '/' . $fileName . '.php';
81+
82+
$values = $this->getValues($defClass);
83+
$values['companionNs'] = $companionNs;
84+
$values['companionClass'] = $companionClass;
85+
$values['model'] = $defClass;
86+
$values['modelStr'] = str_replace('\\', '\\\\', $defClass);
87+
88+
$resolver = new TemplateResolver();
89+
$resolver->resolve($templatePath, $outPath, $values);
90+
}
91+
92+
/**
93+
* Getter for the generator's naming strategy. Access is useful when
94+
* a companion class name needs to be determined outside of normal companion
95+
* generation and loading.
96+
*
97+
* @return NamingStrategy
98+
*/
99+
public function getNamingStrategy() {
100+
return $this->namingStrategy;
101+
}
102+
103+
/**
104+
* This method is responsible for returning the base namespace in which
105+
* companion object reside.
106+
*
107+
* @param string $defClass The name of the class for which a companion is
108+
* being generated. This allows implementations to return different base
109+
* namespaces for a possible hierarchy of definitions.
110+
* @return string
111+
*/
112+
protected abstract function getCompanionNamespace($defClass);
113+
114+
/**
115+
* This method is responsible for returning the path to the template that is
116+
* used to generate the actor.
117+
*
118+
* @param string $defClass The name of the class for which a companion is
119+
* being generated. This allows implementations to return different
120+
* templates for different definitions.
121+
* @return string
122+
*/
123+
protected abstract function getTemplatePath($defClass);
124+
125+
/**
126+
* This method is responsible for actually generating the substitution values
127+
* for generating the actor for the specified definition class. These values
128+
* will be substituted into the template specified by getTemplatePath().
129+
*
130+
* @param string $defClass The name of the definition class.
131+
* @return array Substitution values for generating the actor.
132+
*/
133+
protected abstract function getValues($defClass);
134+
135+
/*
136+
* =========================================================================
137+
* Dependency setters
138+
* =========================================================================
139+
*/
140+
141+
public function setNamingStrategy(NamingStrategy $namingStrategy)
142+
{
143+
$this->namingStrategy = $namingStrategy;
144+
}
145+
146+
/*
147+
* =========================================================================
148+
* Private helpers
149+
* =========================================================================
150+
*/
151+
152+
/* Ensure dependency are initialized */
153+
private function init() {
154+
// Ensure that injectable dependencies have an implementation available.
155+
if ($this->namingStrategy === null) {
156+
$this->namingStrategy = new DefaultNamingStrategy();
157+
}
158+
159+
// If the template hasn't been set then initialize this instance
160+
if ($this->tmpl === null) {
161+
}
162+
}
163+
164+
/* Convert the given namespace/classname to a path fragment. */
165+
private function toPath($name) {
166+
return str_replace(array('\\', '_'), '/', $name);
167+
}
168168
}

src/DefaultNamingStrategy.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
class DefaultNamingStrategy implements NamingStrategy
1717
{
1818

19-
public function getCompanionClassName($targetClass)
20-
{
21-
return str_replace('\\', '_', $targetClass);
22-
}
19+
public function getCompanionClassName($targetClass)
20+
{
21+
return str_replace('\\', '_', $targetClass);
22+
}
2323
}

src/NamingStrategy.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
interface NamingStrategy
1717
{
1818

19-
/**
20-
* Get the basename of any generated class based on the specified target
21-
* class. Generated classes based on the same target class but a different
22-
* class template will all have the same base name and will be
23-
* differentiated by their namespace.
24-
*
25-
* @param string $targetClass
26-
*/
27-
public function getCompanionClassName($targetClass);
28-
19+
/**
20+
* Get the basename of any generated class based on the specified target
21+
* class. Generated classes based on the same target class but a different
22+
* class template will all have the same base name and will be
23+
* differentiated by their namespace.
24+
*
25+
* @param string $targetClass
26+
*/
27+
public function getCompanionClassName($targetClass);
28+
2929
}

0 commit comments

Comments
 (0)