/**
  * @param Properties $properties
  *
  * @return string
  */
 private function generateUnsetPropertiesCode(Properties $properties)
 {
     $code = '';
     if ($accessibleProperties = $properties->getAccessibleProperties()) {
         $code .= $this->getUnsetPropertiesGroupCode($accessibleProperties) . "\n";
     }
     foreach ($properties->getGroupedPrivateProperties() as $className => $privateProperties) {
         $cacheKey = 'cache' . str_replace('\\', '_', $className);
         $code .= 'static $' . $cacheKey . ";\n\n" . '$' . $cacheKey . ' ?: $' . $cacheKey . " = \\Closure::bind(function (\$instance) {\n" . '    ' . $this->getUnsetPropertiesGroupCode($privateProperties) . '}, null, ' . var_export($className, true) . ");\n\n" . '$' . $cacheKey . "(\$instance);\n\n";
     }
     return $code;
 }
示例#2
0
 /**
  * @param Properties $properties
  *
  * @return string
  */
 private function propertiesReferenceArrayCode(Properties $properties)
 {
     $assignments = [];
     foreach ($properties->getAccessibleProperties() as $propertyInternalName => $property) {
         $assignments[] = '    ' . var_export($propertyInternalName, true) . ' => & $this->' . $property->getName() . ',';
     }
     $code = "\$properties = [\n" . implode("\n", $assignments) . "\n];\n\n";
     // must use assignments, as direct reference during array definition causes a fatal error (not sure why)
     foreach ($properties->getGroupedPrivateProperties() as $className => $classPrivateProperties) {
         $cacheKey = 'cacheFetch' . str_replace('\\', '_', $className);
         $code .= 'static $' . $cacheKey . ";\n\n" . '$' . $cacheKey . ' ?: $' . $cacheKey . " = \\Closure::bind(function (\$instance, array & \$properties) {\n" . $this->generatePrivatePropertiesAssignmentsCode($classPrivateProperties) . "}, \$this, " . var_export($className, true) . ");\n\n" . '$' . $cacheKey . "(\$this, \$properties);";
     }
     return $code;
 }