Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved array accessor and mutator methods

  • Loading branch information...
commit a8abfc6146923749c897de02f92ab97931c6b6e7 1 parent 6ed02e5
@mpscholten authored
View
144 src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -300,149 +300,7 @@ protected function addClassClose(&$script)
";
$this->applyBehaviorModifier('objectFilter', $script, "");
}
-
- /**
- * Adds a tester method for an array column.
- *
- * @param string &$script
- * @param Column $column
- */
- protected function addHasArrayElement(&$script, Column $column)
- {
- $clo = $column->getLowercasedName();
- $cfc = $column->getPhpName();
- $visibility = $column->getAccessorVisibility();
- $singularPhpName = rtrim($cfc, 's');
- $script .= "
- /**
- * Test the presence of a value in the [$clo] array column value.
- * @param mixed \$value
- * ".$column->getDescription();
- if ($column->isLazyLoad()) {
- $script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
- }
- $script .= "
- * @return boolean
- */
- $visibility function has$singularPhpName(\$value";
- if ($column->isLazyLoad()) {
- $script .= ", ConnectionInterface \$con = null";
- }
-
- $script .= ")
- {
- return in_array(\$value, \$this->get$cfc(";
- if ($column->isLazyLoad()) {
- $script .= "\$con";
- }
-
- $script .= "));
- } // has$singularPhpName()
-";
- }
-
- /**
- * Adds a push method for an array column.
- * @param string &$script The script will be modified in this method.
- * @param Column $col The current column.
- *
- * @TOdo: made public for twig
- */
- public function addAddArrayElement(Column $col)
- {
- $script = '';
- $clo = $col->getLowercasedName();
- $cfc = $col->getPhpName();
- $visibility = $col->getAccessorVisibility();
- $singularPhpName = rtrim($cfc, 's');
- $script .= "
- /**
- * Adds a value to the [$clo] array column value.
- * @param mixed \$value
- * ".$col->getDescription();
- if ($col->isLazyLoad()) {
- $script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
- }
- $script .= "
- * @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
- */
- $visibility function add$singularPhpName(\$value";
- if ($col->isLazyLoad()) {
- $script .= ", ConnectionInterface \$con = null";
- }
-
- $script .= ")
- {
- \$currentArray = \$this->get$cfc(";
- if ($col->isLazyLoad()) {
- $script .= "\$con";
- }
-
- $script .= ");
- \$currentArray []= \$value;
- \$this->set$cfc(\$currentArray);
-
- return \$this;
- } // add$singularPhpName()
-";
-
- return $script;
- }
-
- /**
- * Adds a remove method for an array column.
- * @param string &$script The script will be modified in this method.
- * @param Column $col The current column.
- *
- * @Todo: made public for twig
- */
- public function addRemoveArrayElement(Column $col)
- {
- $script = '';
- $clo = $col->getLowercasedName();
- $cfc = $col->getPhpName();
- $visibility = $col->getAccessorVisibility();
- $singularPhpName = rtrim($cfc, 's');
- $script .= "
- /**
- * Removes a value from the [$clo] array column value.
- * @param mixed \$value
- * ".$col->getDescription();
- if ($col->isLazyLoad()) {
- $script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
- }
- $script .= "
- * @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
- */
- $visibility function remove$singularPhpName(\$value";
- if ($col->isLazyLoad()) {
- $script .= ", ConnectionInterface \$con = null";
- }
- // we want to reindex the array, so array_ functions are not the best choice
- $script .= ")
- {
- \$targetArray = array();
- foreach (\$this->get$cfc(";
- if ($col->isLazyLoad()) {
- $script .= "\$con";
- }
- $script .= ") as \$element) {
- if (\$element != \$value) {
- \$targetArray []= \$element;
- }
- }
- \$this->set$cfc(\$targetArray);
-
- return \$this;
- } // remove$singularPhpName()
-";
-
- return $script;
- }
-
+
public function getInvalidTemporalString(Column $column)
{
if ($this->getPlatform() instanceof MysqlPlatform) {
View
12 src/Propel/Generator/Builder/Om/templates/Object/_accessor/_arrayHasElement.php.twig
@@ -0,0 +1,12 @@
+/**
+ * Test the presence of a value in the [{{ column.name|lower }}] array column value.
+ * @param mixed $value
+{% if column.lazyLoad %}
+ * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.
+{% endif %}
+ * @return boolean
+ */
+{{ column.accessorVisibility }} function has{{ column.singularPhpName }}($value{% if column.lazyLoad %}, ConnectionInterface $con = null{% endif %})
+{
+ return in_array($value, $this->get{{ column.phpName }}({% if column.lazyLoad %}$con{% endif %});
+}
View
4 src/Propel/Generator/Builder/Om/templates/Object/_columnAccessorMethods.php.twig
@@ -5,6 +5,10 @@
{% include 'Object/_accessor/_objectAccessor.php.twig' with {'column': column, 'builder': builder} %}
{% elseif column.phpArrayType %}
{% include 'Object/_accessor/_arrayAccessor.php.twig' with {'column': column, 'builder': builder} %}
+
+ {% if column.namePlural %}
+ {% include 'Object/_accessor/_arrayHasElement.php.twig' with {'column': column, 'builder': builder} %}
+ {% endif %}
{% elseif column.enumType %}
{% include 'Object/_accessor/_enumAccessor.php.twig' with {'column': column, 'builder': builder} %}
{% else %}
View
17 src/Propel/Generator/Builder/Om/templates/Object/_mutator/_arrayAdd.php.twig
@@ -0,0 +1,17 @@
+/**
+ * Adds a value to the [{{ column.name|lower }}] array column value.
+ * @param mixed $value
+ * {{ column.description }}
+{% if column.lazyLoad %}
+ * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.
+{% endif %}
+ * @return {{ builder.objectClassName }} The current object (for fluent API support)
+ */
+$visibility function add{{ column.singularPhpName }}($value{% if column.lazyLoad %}, ConnectionInterface $con = null{% endif %})
+{
+ $currentArray = $this->get{{ column.phpName }}({% if column.lazyLoad %}$con{% endif %});
+ $currentArray []= $value;
+ $this->set{{ column.phpName }}($currentArray);
+
+ return $this;
+}
View
22 src/Propel/Generator/Builder/Om/templates/Object/_mutator/_arrayRemove.php.twig
@@ -0,0 +1,22 @@
+/**
+ * Removes a value from the [{{ column.name|lower }}] array column value.
+ * @param mixed $value
+ * {{ column.description }}
+{% if column.lazyLoad %}
+ * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.
+{% endif %}
+ * @return {{ builder.objectClassName }} The current object (for fluent API support)
+ */
+{{ column.accessorVisibility }} function remove{{ column.singularPhpName }}($value{% if column.lazyLoad %}, ConnectionInterface $con = null{% endif %})
+{
+ // we want to reindex the array, so array_ functions are not the best choice
+ $targetArray = array();
+ foreach ($this->get{{ column.phpName }}({% if column.lazyLoad %}$con{% endif %}) as $element) {
+ if ($element != $value) {
+ $targetArray []= $element;
+ }
+ }
+ $this->set{{ column.phpName }}($targetArray);
+
+ return $this;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.