File templates: make a PHP variable with template variable case conversion
Hi,
i'm trying to make a file template for a generating a model. I would like to use the ${NAME} variable and in some places convert it to camel case.
I would like to create something like this, where the protected variable has the same name as the model but in camel case:
<?php
declare(strict_types=1);
namespace App\Model;
/**
* Class TestModel
* @package App\Model
*
* @property int TestModelID
*
*/
class TestModel extends AbstractModel
{
protected $testModel = null;
}
I didn't find anything online, the closest to my problem is this post but I don't understand the "answer". I installed the String manipulation plugin and tried to set a $CAMEL_CASE variable as David Rees has written in the post I linked but with no success. I also tried to use `uncapitalize` string manipulation function but it doesn't work:
My file template:
<?php
declare(strict_types=1);
namespace App\Model;
#set($CAMEL_NAME = ${StringUtils.uncapitalize(${NAME})})
/**
* Class ${NAME}
* @package App\Model
*
* @property int ${NAME}ID
*
*/
class ${NAME} extends AbstractModel
{
/** @var ${NAME} */
protected ${CAMEL_NAME} = null;
}
Generated output:
<?php
declare(strict_types=1);
namespace App\Model;
/**
* Class TestModel
* @package App\Model
*
* @property int TestModelID
*
*/
class TestModel extends AbstractModel
{
/** @var TestModel */
protected ${
CAMEL_NAME
} = null;
}
Can you please tell me what I'm doing wrong and how to solve my problem.
Recap: I would like to make a PHP variable with camel case from a template variable ${NAME}.
Thanks
请先登录再写评论。
Hi there,
Here we have separate variables for 1st letter (which we need to manipulate: make it lower case) and the rest of the name.
Thank you, this is what I was looking for.
I created another variable from concatenated first letter and the rest of the word so it's a little less writing :)