-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from moufmouf/master
Refactoring naming strategy to account for getter/setter namings too.
- Loading branch information
Showing
9 changed files
with
244 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
|
||
namespace TheCodingMachine\TDBM\Utils; | ||
|
||
use Doctrine\DBAL\Schema\Index; | ||
|
||
/** | ||
* An abstract class offering a common implementation for most names of the NamingStrategyInterface. | ||
* It assumes getters and setters will start with get... and set..., and so on. | ||
*/ | ||
abstract class AbstractNamingStrategy implements NamingStrategyInterface | ||
{ | ||
protected abstract function getUpperCamelCaseName(AbstractBeanPropertyDescriptor $property): string; | ||
|
||
protected function getLowerCamelCaseName(AbstractBeanPropertyDescriptor $property): string | ||
{ | ||
return lcfirst($this->getUpperCamelCaseName($property)); | ||
} | ||
|
||
/** | ||
* Returns the getter name generated for the property passed in parameter. | ||
* | ||
* @param AbstractBeanPropertyDescriptor $property | ||
* @return string | ||
*/ | ||
public function getGetterName(AbstractBeanPropertyDescriptor $property): string | ||
{ | ||
return 'get'.$this->getUpperCamelCaseName($property); | ||
} | ||
|
||
/** | ||
* Returns the setter name generated for the property passed in parameter. | ||
* | ||
* @param AbstractBeanPropertyDescriptor $property | ||
* @return string | ||
*/ | ||
public function getSetterName(AbstractBeanPropertyDescriptor $property): string | ||
{ | ||
return 'set'.$this->getUpperCamelCaseName($property); | ||
} | ||
|
||
/** | ||
* Returns the variable name used in the setter generated for the property passed in parameter. | ||
* | ||
* @param AbstractBeanPropertyDescriptor $property | ||
* @return string | ||
*/ | ||
public function getVariableName(AbstractBeanPropertyDescriptor $property): string | ||
{ | ||
return '$'.$this->getLowerCamelCaseName($property); | ||
} | ||
|
||
/** | ||
* Returns the label of the JSON property for the property passed in parameter. | ||
* | ||
* @param AbstractBeanPropertyDescriptor $property | ||
* @return string | ||
*/ | ||
public function getJsonProperty(AbstractBeanPropertyDescriptor $property): string | ||
{ | ||
return $this->getLowerCamelCaseName($property); | ||
} | ||
|
||
/** | ||
* Returns the name of the find method attached to an index. | ||
* | ||
* @param AbstractBeanPropertyDescriptor[] $elements The list of properties in the index. | ||
* @return string | ||
*/ | ||
public function getFindByIndexMethodName(Index $index, array $elements): string | ||
{ | ||
$methodNameComponent = array_map([$this, 'getUpperCamelCaseName'], $elements); | ||
|
||
if ($index->isUnique()) { | ||
return 'findOneBy'.implode('And', $methodNameComponent); | ||
} else { | ||
return 'findBy' . implode('And', $methodNameComponent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.