diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2016-01-31 21:32:41 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2016-01-31 21:32:41 +0100 |
commit | b9cfabe5597467f3a61dc6f311f86fa9f4de0bbd (patch) | |
tree | 47640320261bce5c49b1ffe633951ab692015c0a | |
parent | 37119f54407b43b837eb2484fd86881dcf470f15 (diff) | |
download | extbase-generator-cli-b9cfabe5597467f3a61dc6f311f86fa9f4de0bbd.tar.gz extbase-generator-cli-b9cfabe5597467f3a61dc6f311f86fa9f4de0bbd.tar.bz2 extbase-generator-cli-b9cfabe5597467f3a61dc6f311f86fa9f4de0bbd.zip |
add property: Try to define the property before the first function
..but only if a function is found, else write it to the end of the file
-rwxr-xr-x | add_extbase_property.sh | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/add_extbase_property.sh b/add_extbase_property.sh index bcbc293..faf87a5 100755 --- a/add_extbase_property.sh +++ b/add_extbase_property.sh @@ -241,14 +241,43 @@ sed -i -f - ext_tables.sql << EOF EOF -sed -i "\$s#^#\n\ +sed -i -f - ${model_file} << EOF +# Use ^class selector to ensure we're adding the property only once +/^class/ { + :loop + /---PROPERTY--/! { + # Try to define the new property before the first function + /[^ ]*public function / { + s/\n\n\([^\n][^\n]*\n\)*[ \t]*public function/\n\n---PROPERTY---&/ + } + } + /\n}/ { + # If we've found no function, add the new property to the end of the file + /---PROPERTY--/! { + s/\n}/\n---PROPERTY---&/ + } + s/\n}/\n\n---GETTER---&/ + s/\n}/\n\n---SETTER---&/ + + b replace + } + N + bloop +} + +# leave the script here – functionality below is explicitly requesting by a jump +b + +:replace +s#\n---PROPERTY---#\n\ /**\n\ * ${property}\n\ *\n\ * @var ${php_type}\n\ */\n\ - protected \$${property} = ${default_value};\n\ -\n\ + protected \$${property} = ${default_value};# + +s#\n---GETTER---#\n\ /**\n\ * Returns the ${property}\n\ *\n\ @@ -257,8 +286,9 @@ sed -i "\$s#^#\n\ public function get${uproperty}()\n\ {\n\ return \$this->${property};\n\ - }\n\ -\n\ + }# + +s#\n---SETTER---#\n\ /**\n\ * Sets the ${property}\n\ *\n\ @@ -268,8 +298,8 @@ sed -i "\$s#^#\n\ public function set${uproperty}(\$${property})\n\ {\n\ \$this->${property} = \$${property};\n\ - }\n#" \ - $model_file + }# +EOF echo "Created \$${property} in ${model}" echo |