Generate and insert methods for PHP classes into the file
To generate the methods it is necessary to position yourself on the same line or select the lines whose methods you want to generate.
Download it from github releases:
To install the extension you need to open the CMD
or Powershell
and go to the folder where you downloaded the .VSIX
file, then type and type the following command
code --install-extension PHP-Utils-X.X.X.vsix
Search for the extension name
Visual studio code
PHP-Utils.getterTemplate
: Template for getterPHP-Utils.setterTemplate
: Template for setterPHP-Utils.toStringTemplate
: Template for toStringPHP-Utils.constructTemplate
: Template for construct
For now none :)
Added thigs for github
Translated in english for publishing
- Issue #2
- Auto indentation
- Template support
Initial release
Templates can be used by placing them in folders:
- Linux:
~ / .config / Code / User / PHP-Utils
- OSX:
~ / Library / Application Support / Code / User / PHP-Utils
- Windows:
Users \ {User} \ AppData \ Roaming \ Code \ User \ PHP-Utils
The templates must be contained in a je .js
, after that you will need to go into the settings and search for PHP-Utils
, and finally change the desired settings.
module.exports = (line) => {
let template: string;
if(line.getType()) {
template = `
/**
* @return ${line.getType()}
*/
public function get${line.getNameCamel()}(): ${line.getType()} {
return $this->${line.getName()};
}
`
} else {
template = `
public function get${line.getNameCamel()}() {
return $this->${line.getName()};
}
`
}
return template.replace(/\n/gm, '\n' + line.getSpacing()).trimEnd() + '\n';
}
module.exports = (line) => {
let template: string;
if(line.getType()) {
template = `
/**
* @param ${line.getType()} $${line.getName()}
*/
public function set${line.getNameCamel()}(${line.getType()} $${line.getName()}): void {
$this->${line.getName()} = $${line.getName()};
}
`
} else {
template = `
/**
* @param $${line.getName()}
*/
public function set${line.getNameCamel()}($${line.getName()}) {
$this->${line.getName()} = $${line.getName()};
}
`
}
return template.replace(/\n/gm, '\n' + line.getSpacing()).trimEnd() + '\n';
}
module.exports = (line) => {
let template: string;
let string = '';
let type = true;
for(let line of lines) {
type = line.getType() != '' && type;
string += `${line.getNameCamel()}: {$this->${line.getName()}}, `;
}
string = string.substr(0, string.length-2);
if(type) {
template = `
/**
* @return string
*/
public function __toString(): string {
return "${string}";
}
`
} else {
template = `
/**
* @return string
*/
public function __toString() {
return "${string}";
}
`
}
return template.replace(/\n/gm, '\n' + lines[0].getSpacing()).trimEnd() + '\n';
}
module.exports = (line) => {
let string = '';
let params = '';
let type = true;
for(let line of lines) {
type = line.getType() != '' && type;
string += `\t$this->${line.getName()} = $${line.getName()};\n`;
}
for(let line of lines) {
if(type) {
params += `${line.getType()} $${line.getName()}, `;
} else {
params += `$${line.getName()}, `;
}
}
params = params.substr(0, params.length-2);
let template = `
function __construct(${params}) {
${string}
}
`
return template.replace(/\n/gm, '\n' + lines[0].getSpacing()).trimEnd() + '\n';
}
If you want to create your own templates you will need to create the .js
file which must have a basic structure as shown.
module.exports = (line) => {
// code here
}
This creates a function that can be imported and used to create the template, and to do so there is the Line
class which has:
getVisibility ()
the visibility of the [public, private, protected] attributegetType ()
the type of the attribute (if any) [int, float, string, ...]getName ()
the attribute namegetNameCamel ()
the attribute name with the first capital lettergetSpacing ()
the distance between the attribute and the left margin of vs code, used for automatic indentation