Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezphpcreator.php
Go to the documentation of this file.
1 <?php
52 class eZPHPCreator
53 {
54 const VARIABLE = 1;
55 const SPACE = 2;
56 const TEXT = 3;
57 const METHOD_CALL = 4;
58 const CODE_PIECE = 5;
59 const EOL_COMMENT = 6;
60 const INCLUDE_STATEMENT = 7;
61 const VARIABLE_UNSET = 8;
62 const DEFINE = 9;
63 const VARIABLE_UNSET_LIST = 10;
64 const RAW_VARIABLE = 11;
65
66 const VARIABLE_ASSIGNMENT = 1;
67 const VARIABLE_APPEND_TEXT = 2;
68 const VARIABLE_APPEND_ELEMENT = 3;
69
70 const INCLUDE_ONCE_STATEMENT = 1;
71 const INCLUDE_ALWAYS_STATEMENT = 2;
72
73 const METHOD_CALL_PARAMETER_VALUE = 1;
74 const METHOD_CALL_PARAMETER_VARIABLE = 2;
75
84 public function __construct( $dir, $file, $prefix = '', $options = array() )
85 {
86 $this->PHPDir = $dir;
87 $this->PHPFile = $file;
88 $this->FilePrefix = $prefix;
89 $this->FileResource = false;
90 $this->Elements = array();
91 $this->TextChunks = array();
92 $this->TemporaryCounter = 0;
93 if ( isset( $options['spacing'] ) and ( $options['spacing'] == 'disabled') )
94 {
95 $this->Spacing = false;
96 }
97 else
98 {
99 $this->Spacing = true;
100 }
101
102 if ( isset( $options['clustering'] ) )
103 {
104 $this->ClusteringEnabled = true;
105 $this->ClusterFileScope = $options['clustering'];
106 }
107 else
108 {
109 $this->ClusteringEnabled = false;
110 }
111 $this->ClusterHandler = null;
112 }
113
115
138 function addDefine( $name, $value, $caseSensitive = true, $parameters = array() )
139 {
140 $element = array( eZPHPCreator::DEFINE,
141 $name,
142 $value,
143 $caseSensitive,
144 $parameters );
145 $this->Elements[] = $element;
146 }
147
159 function addRawVariable( $name, $value )
160 {
161 $element = array( eZPHPCreator::RAW_VARIABLE, $name, $value );
162 $this->Elements[] = $element;
163 }
164
193 function addVariable( $name, $value, $assignmentType = eZPHPCreator::VARIABLE_ASSIGNMENT,
194 $parameters = array() )
195 {
196 $element = array( eZPHPCreator::VARIABLE,
197 $name,
198 $value,
199 $assignmentType,
200 $parameters );
201 $this->Elements[] = $element;
202 }
203
223 function addVariableUnset( $name,
224 $parameters = array() )
225 {
226 $element = array( eZPHPCreator::VARIABLE_UNSET,
227 $name,
228 $parameters );
229 $this->Elements[] = $element;
230 }
231
251 function addVariableUnsetList( $list,
252 $parameters = array() )
253 {
254 $element = array( eZPHPCreator::VARIABLE_UNSET_LIST,
255 $list,
256 $parameters );
257 $this->Elements[] = $element;
258 }
259
270 function addSpace( $lines = 1 )
271 {
272 $element = array( eZPHPCreator::SPACE,
273 $lines );
274 $this->Elements[] = $element;
275 }
276
287 function addText( $text )
288 {
289 $element = array( eZPHPCreator::TEXT,
290 $text );
291 $this->Elements[] = $element;
292 }
293
325 function addMethodCall( $objectName, $methodName, $methodParameters, $returnValue = false, $parameters = array() )
326 {
327 $element = array( eZPHPCreator::METHOD_CALL,
328 $objectName,
329 $methodName,
330 $methodParameters,
331 $returnValue,
332 $parameters );
333 $this->Elements[] = $element;
334 }
335
360 function addCodePiece( $code, $parameters = array() )
361 {
362 $element = array( eZPHPCreator::CODE_PIECE,
363 $code,
364 $parameters );
365 $this->Elements[] = $element;
366 }
367
390 function addComment( $comment, $eol = true, $whitespaceHandling = true, $parameters = array() )
391 {
392 $element = array( eZPHPCreator::EOL_COMMENT,
393 $comment,
394 array_merge( $parameters,
395 array( 'eol' => $eol,
396 'whitespace-handling' => $whitespaceHandling ) ) );
397 $this->Elements[] = $element;
398 }
399
421 function addInclude( $file, $type = eZPHPCreator::INCLUDE_ONCE_STATEMENT, $parameters = array() )
422 {
423 $element = array( eZPHPCreator::INCLUDE_STATEMENT,
424 $file,
425 $type,
426 $parameters );
427 $this->Elements[] = $element;
428 }
429
431
442 static function variableNameText( $variableName, $assignmentType, $variableParameters = array() )
443 {
444 $text = '$' . $variableName;
445 if ( $assignmentType == eZPHPCreator::VARIABLE_ASSIGNMENT )
446 {
447 $text .= ' = ';
448 }
449 else if ( $assignmentType == eZPHPCreator::VARIABLE_APPEND_TEXT )
450 {
451 $text .= ' .= ';
452 }
453 else if ( $assignmentType == eZPHPCreator::VARIABLE_APPEND_ELEMENT )
454 {
455 $text .= '[] = ';
456 }
457 return $text;
458 }
459
481 function thisVariableText( $value, $column = 0, $iteration = 0, $maxIterations = 2 )
482 {
483 if ( isset( $this->Spacing ) and !$this->Spacing )
484 {
485 return var_export( $value, true );
486 }
487
488 if ( $value === true )
489 $text = 'true';
490 else if ( $value === false )
491 $text = 'false';
492 else if ( $value === null )
493 $text = 'null';
494 else if ( is_string( $value ) )
495 {
496 $valueText = str_replace( array( "\\",
497 "\"",
498 "\$",
499 "\n" ),
500 array( "\\\\",
501 "\\\"",
502 "\\$",
503 "\\n" ),
504 $value );
505 $text = "\"$valueText\"";
506 }
507 else if ( is_numeric( $value ) )
508 $text = $value;
509 else if ( is_object( $value ) )
510 {
511 if ( $maxIterations !== false and
512 $iteration > $maxIterations )
513 {
514 $temporaryVariableName = $this->temporaryVariableName( 'obj' );
515 $this->writeVariable( $temporaryVariableName, $value );
516 $text = '$' . $temporaryVariableName;
517 }
518 else
519 {
520 $text = '';
521 if ( method_exists( $value, 'serializeData' ) )
522 {
523 $serializeData = $value->serializeData();
524 $className = $serializeData['class_name'];
525 $text = "new $className(";
526
527 $column += strlen( $text );
528 $parameters = $serializeData['parameters'];
529 $variables = $serializeData['variables'];
530
531 $i = 0;
532 foreach ( $parameters as $parameter )
533 {
534 if ( $i > 0 )
535 {
536 $text .= ",\n" . str_repeat( ' ', $column );
537 }
538 $variableName = $variables[$parameter];
539 $variableValue = $value->$variableName;
540 $keyText = " ";
541
542 $text .= $keyText . $this->thisVariableText( $variableValue, $column + strlen( $keyText ), $iteration + 1, $maxIterations );
543
544 ++$i;
545 }
546 if ( $i > 0 )
547 $text .= ' ';
548
549 $text .= ')';
550 }
551 }
552 }
553 else if ( is_array( $value ) )
554 {
555 if ( $maxIterations !== false and
556 $iteration > $maxIterations )
557 {
558 $temporaryVariableName = $this->temporaryVariableName( 'arr' );
559 $this->writeVariable( $temporaryVariableName, $value );
560 $text = '$' . $temporaryVariableName;
561 }
562 else
563 {
564 $text = 'array(';
565 $column += strlen( $text );
566 $valueKeys = array_keys( $value );
567 $isIndexed = true;
568 for ( $i = 0; $i < count( $valueKeys ); ++$i )
569 {
570 if ( $i !== $valueKeys[$i] )
571 {
572 $isIndexed = false;
573 break;
574 }
575 }
576 $i = 0;
577 foreach ( $valueKeys as $key )
578 {
579 if ( $i > 0 )
580 {
581 $text .= ",\n" . str_repeat( ' ', $column );
582 }
583 $element = $value[$key];
584 $keyText = ' ';
585 if ( !$isIndexed )
586 {
587 if ( is_int( $key ) )
588 $keyText = $key;
589 else
590 $keyText = "\"" . str_replace( array( "\\",
591 "\"",
592 "\n" ),
593 array( "\\\\",
594 "\\\"",
595 "\\n" ),
596 $key ) . "\"";
597 $keyText = " $keyText => ";
598 }
599
600 $text .= $keyText . $this->thisVariableText( $element, $column + strlen( $keyText ), $iteration + 1, $maxIterations );
601
602 ++$i;
603 }
604 if ( $i > 0 )
605 $text .= ' ';
606 $text .= ')';
607 }
608 }
609 else
610 $text = 'null';
611 return $text;
612 }
613
614 static function variableText( $value, $column = 0, $iteration = 0, $maxIterations = false )
615 {
616 // the last parameter will always be ignored
617 $maxIterations = false;
618
619 if ( $value === true )
620 $text = 'true';
621 else if ( $value === false )
622 $text = 'false';
623 else if ( $value === null )
624 $text = 'null';
625 else if ( is_string( $value ) )
626 {
627 $valueText = str_replace( array( "\\",
628 "\"",
629 "\$",
630 "\n" ),
631 array( "\\\\",
632 "\\\"",
633 "\\$",
634 "\\n" ),
635 $value );
636 $text = "\"$valueText\"";
637 }
638 else if ( is_numeric( $value ) )
639 $text = $value;
640 else if ( is_object( $value ) )
641 {
642 $text = '';
643 if ( method_exists( $value, 'serializeData' ) )
644 {
645 $serializeData = $value->serializeData();
646 $className = $serializeData['class_name'];
647 $text = "new $className(";
648
649 $column += strlen( $text );
650 $parameters = $serializeData['parameters'];
651 $variables = $serializeData['variables'];
652
653 $i = 0;
654 foreach ( $parameters as $parameter )
655 {
656 if ( $i > 0 )
657 {
658 $text .= ",\n" . str_repeat( ' ', $column );
659 }
660 $variableName = $variables[$parameter];
661 $variableValue = $value->$variableName;
662 $keyText = " ";
663
664 $text .= $keyText . eZPHPCreator::variableText( $variableValue, $column + strlen( $keyText ), $iteration + 1 );
665 ++$i;
666 }
667 if ( $i > 0 )
668 $text .= ' ';
669
670 $text .= ')';
671 }
672 }
673 else if ( is_array( $value ) )
674 {
675 $text = 'array(';
676 $column += strlen( $text );
677 $valueKeys = array_keys( $value );
678 $isIndexed = true;
679 for ( $i = 0; $i < count( $valueKeys ); ++$i )
680 {
681 if ( $i !== $valueKeys[$i] )
682 {
683 $isIndexed = false;
684 break;
685 }
686 }
687 $i = 0;
688 foreach ( $valueKeys as $key )
689 {
690 if ( $i > 0 )
691 {
692 $text .= ",\n" . str_repeat( ' ', $column );
693 }
694 $element = $value[$key];
695 $keyText = ' ';
696 if ( !$isIndexed )
697 {
698 if ( is_int( $key ) )
699 $keyText = $key;
700 else
701 $keyText = "\"" . str_replace( array( "\\",
702 "\"",
703 "\n" ),
704 array( "\\\\",
705 "\\\"",
706 "\\n" ),
707 $key ) . "\"";
708 $keyText = " $keyText => ";
709 }
710
711 $text .= $keyText . eZPHPCreator::variableText( $element, $column + strlen( $keyText ), $iteration + 1 );
712
713 ++$i;
714 }
715 if ( $i > 0 )
716 $text .= ' ';
717 $text .= ')';
718 }
719 else
720 $text = 'null';
721 return $text;
722 }
723
734 static function prependSpacing( $text, $spacing, $skipEmptyLines = true, $spacingString = " ", $splitString = "\n" )
735 {
736 if ( $spacing == 0 )
737 return $text;
738 $textArray = explode( $splitString, $text );
739 $newTextArray = array();
740 foreach ( $textArray as $text )
741 {
742 if ( trim( $text ) != '' )
743 $textLine = str_repeat( $spacingString, $spacing ) . $text;
744 else
745 $textLine = $text;
746 $newTextArray[] = $textLine;
747 }
748 return implode( $splitString, $newTextArray );
749 }
750
752
759 function open( $atomic = false )
760 {
761 if ( $this->ClusteringEnabled )
762 return true;
763
764 if ( !$this->FileResource )
765 {
766 if ( !file_exists( $this->PHPDir ) )
767 {
768 eZDir::mkdir( $this->PHPDir, false, true );
769 }
770 $path = $this->PHPDir . '/' . $this->PHPFile;
771 $oldumask = umask( 0 );
772 $pathExisted = file_exists( $path );
773 if ( $atomic )
774 {
775 $this->isAtomic = true;
776 $this->requestedFilename = $path;
777 $uniqid = md5( uniqid( "ezp". getmypid(), true ) );
778 $path .= ".$uniqid";
779 $this->tmpFilename = $path;
780 }
781 $ini = eZINI::instance();
782 $perm = octdec( $ini->variable( 'FileSettings', 'StorageFilePermissions' ) );
783 $this->FileResource = @fopen( $this->FilePrefix . $path, "w" );
784 if ( !$this->FileResource )
785 eZDebug::writeError( "Could not open file '$path' for writing, perhaps wrong permissions" );
786 if ( $this->FileResource and
787 !$pathExisted )
788 chmod( $path, $perm );
789 umask( $oldumask );
790 }
791 return $this->FileResource;
792 }
793
797 function close()
798 {
799 if ( $this->ClusteringEnabled )
800 {
801 $this->ClusterHandler = null;
802 return;
803 }
804
805 if ( $this->FileResource )
806 {
807 fclose( $this->FileResource );
808
809 if ( $this->isAtomic )
810 {
811 eZFile::rename( $this->tmpFilename, $this->requestedFilename, false, eZFile::CLEAN_ON_FAILURE );
812 }
813 $this->FileResource = false;
814 }
815 }
816
821 function exists()
822 {
823 $path = $this->PHPDir . '/' . $this->PHPFile;
824 if ( !$this->ClusteringEnabled )
825 return file_exists( $path );
826
827 if ( !$this->ClusterHandler )
828 {
829 $this->ClusterHandler = eZClusterFileHandler::instance();
830 }
831 return $this->ClusterHandler->fileExists( $path );
832 }
833
841 function canRestore( $timestamp = false )
842 {
843 $path = $this->PHPDir . '/' . $this->PHPFile;
844
845 if ( $this->ClusteringEnabled )
846 {
847 if ( !$this->ClusterHandler )
848 {
849 $this->ClusterHandler = eZClusterFileHandler::instance( $path );
850 }
851 // isExpired() expects -1 to disable expiry check
852 $expiry = ( $timestamp === false ) ? -1 : $timestamp;
853 return !$this->ClusterHandler->isExpired( $expiry, time(), null );
854 }
855
856 $canRestore = file_exists( $path );
857 if ( $timestamp !== false and
858 $canRestore )
859 {
860 $cacheModifierTime = filemtime( $path );
861 $canRestore = ( $cacheModifierTime >= $timestamp );
862 }
863
864 return $canRestore;
865 }
866
884 function restore( $variableDefinitions )
885 {
886 $returnVariables = array();
887 $path = $this->PHPDir . '/' . $this->PHPFile;
888
889 if ( !$this->ClusteringEnabled )
890 {
891 $returnVariables = $this->_restoreCall( $path, false, $variableDefinitions );
892 }
893 else
894 {
895 if ( !$this->ClusterHandler )
896 {
897 $this->ClusterHandler = eZClusterFileHandler::instance( $path );
898 }
899 $returnVariables = $this->ClusterHandler->processFile( array( $this, '_restoreCall' ), null, $variableDefinitions );
900 }
901 return $returnVariables;
902 }
903
908 function _restoreCall( $path, $mtime, $variableDefinitions )
909 {
910 $returnVariables = array();
911 include( $path );
912 foreach ( $variableDefinitions as $variableReturnName => $variableName )
913 {
914 $variableRequired = true;
915 $variableDefault = false;
916 if ( is_array( $variableName ) )
917 {
918 $variableDefinition = $variableName;
919 $variableName = $variableDefinition['name'];
920 $variableRequired = $variableDefinition['required'];
921 if ( isset( $variableDefinition['default'] ) )
922 $variableDefault = $variableDefinition['default'];
923 }
924 if ( isset( $$variableName ) )
925 {
926 $returnVariables[$variableReturnName] = $$variableName;
927 }
928 else if ( $variableRequired )
929 {
930 eZDebug::writeError( "Variable '$variableName' is not present in cache '$path'", __METHOD__ );
931 }
932 else
933 {
934 $returnVariables[$variableReturnName] = $variableDefault;
935 }
936 }
937 return $returnVariables;
938 }
939
943 function store( $atomic = false )
944 {
945 if ( $this->open( $atomic ) )
946 {
947 $this->write( "<?php\n" );
948
949 $this->writeElements();
950
951 $this->write( "?>\n" );
952
953 $this->writeChunks();
954 $this->flushChunks();
955 $this->close();
956
957 if ( !$this->ClusteringEnabled )
958 {
959 $perm = octdec( eZINI::instance()->variable( 'FileSettings', 'StorageFilePermissions' ) );
960 chmod( eZDir::path( array( $this->PHPDir, $this->PHPFile ) ), $perm );
961 }
962
963 // Write log message to storage.log
964 eZLog::writeStorageLog( $this->PHPFile, $this->PHPDir . '/' );
965 return true;
966 }
967 else
968 {
969 eZDebug::writeError( "Failed to open file '" . $this->PHPDir . '/' . $this->PHPFile . "'", __METHOD__ );
970 return false;
971 }
972 }
973
978 function fetch( $addPHPMarkers = true )
979 {
980 if ( $addPHPMarkers )
981 $this->write( "<?php\n" );
982 $this->writeElements();
983 if ( $addPHPMarkers )
984 $this->write( "?>\n" );
985
986 $text = implode( '', $this->TextChunks );
987
988 $this->flushChunks();
989
990 return $text;
991 }
992
994
998 function writeChunks()
999 {
1000 $count = count( $this->TextChunks );
1001
1002 if ( $this->ClusteringEnabled )
1003 {
1004 $text = '';
1005 for ( $i = 0; $i < $count; ++$i )
1006 $text .= $this->TextChunks[$i];
1007
1008 $filePath = $this->FilePrefix . $this->PHPDir . '/' . $this->PHPFile;
1009
1010 if ( !$this->ClusterHandler )
1011 {
1012 $this->ClusterHandler = eZClusterFileHandler::instance();
1013 }
1014 $this->ClusterHandler->fileStoreContents( $filePath, $text, $this->ClusterFileScope, 'php' );
1015
1016 return;
1017 }
1018
1019 for ( $i = 0; $i < $count; ++$i )
1020 {
1021 $text = $this->TextChunks[$i];
1022 fwrite( $this->FileResource, $text );
1023 }
1024 }
1025
1029 function flushChunks()
1030 {
1031 $this->TextChunks = array();
1032 }
1033
1037 function write( $text )
1038 {
1039 $this->TextChunks[] = $text;
1040 }
1041
1045 function writeElements()
1046 {
1047 foreach( $this->Elements as $element )
1048 {
1049 if ( $element[0] == eZPHPCreator::DEFINE )
1050 {
1051 $this->writeDefine( $element );
1052 }
1053 else if ( $element[0] == eZPHPCreator::RAW_VARIABLE )
1054 {
1055 $this->writeRawVariable( $element[1], $element[2] );
1056 }
1057 else if ( $element[0] == eZPHPCreator::VARIABLE )
1058 {
1059 $this->writeVariable( $element[1], $element[2], $element[3], $element[4] );
1060 }
1061 else if ( $element[0] == eZPHPCreator::VARIABLE_UNSET )
1062 {
1063 $this->writeVariableUnset( $element );
1064 }
1065 else if ( $element[0] == eZPHPCreator::VARIABLE_UNSET_LIST )
1066 {
1067 $this->writeVariableUnsetList( $element );
1068 }
1069 else if ( $element[0] == eZPHPCreator::SPACE )
1070 {
1071 $this->writeSpace( $element );
1072 }
1073 else if ( $element[0] == eZPHPCreator::TEXT )
1074 {
1075 $this->writeText( $element );
1076 }
1077 else if ( $element[0] == eZPHPCreator::METHOD_CALL )
1078 {
1079 $this->writeMethodCall( $element );
1080 }
1081 else if ( $element[0] == eZPHPCreator::CODE_PIECE )
1082 {
1083 $this->writeCodePiece( $element );
1084 }
1085 else if ( $element[0] == eZPHPCreator::EOL_COMMENT )
1086 {
1087 $this->writeComment( $element );
1088 }
1089 else if ( $element[0] == eZPHPCreator::INCLUDE_STATEMENT )
1090 {
1091 $this->writeInclude( $element );
1092 }
1093 }
1094 }
1095
1099 function writeDefine( $element )
1100 {
1101 $name = $element[1];
1102 $value = $element[2];
1103 $caseSensitive = $element[3];
1104 $parameters = $element[4];
1105 $text = '';
1106 if ( $this->Spacing )
1107 {
1108 $spacing = 0;
1109 if ( isset( $parameters['spacing'] ) )
1110 $spacing = $parameters['spacing'];
1111 $text = str_repeat( ' ', $spacing );
1112 }
1113 $nameText = $this->thisVariableText( $name, 0 );
1114 $valueText = $this->thisVariableText( $value, 0 );
1115 $text .= "define( $nameText, $valueText";
1116 if ( !$caseSensitive )
1117 $text .= ", true";
1118 $text .= " );\n";
1119 $this->write( $text );
1120 }
1121
1125 function writeInclude( $element )
1126 {
1127 $includeFile = $element[1];
1128 $includeType = $element[2];
1129 $parameters = $element[3];
1130 if ( $includeType == eZPHPCreator::INCLUDE_ONCE_STATEMENT )
1131 $includeName = 'include_once';
1132 else if ( $includeType == eZPHPCreator::INCLUDE_ALWAYS_STATEMENT )
1133 $includeName = 'include';
1134 $includeFileText = $this->thisVariableText( $includeFile, 0 );
1135 $text = "$includeName( $includeFileText );\n";
1136 if ( $this->Spacing )
1137 {
1138 $spacing = 0;
1139 if ( isset( $parameters['spacing'] ) )
1140 $spacing = $parameters['spacing'];
1141 $text = str_repeat( ' ', $spacing ) . $text;
1142 }
1143 $this->write( $text );
1144 }
1145
1149 function writeComment( $element )
1150 {
1151 $elementAttributes = $element[2];
1152 $spacing = 0;
1153 if ( isset( $elementAttributes['spacing'] ) and $this->Spacing )
1154 $spacing = $elementAttributes['spacing'];
1155 $whitespaceHandling = $elementAttributes['whitespace-handling'];
1156 $eol = $elementAttributes['eol'];
1157 $newCommentArray = array();
1158 $commentArray = preg_split( "/\r\n|\r|\n/", $element[1] );
1159 foreach ( $commentArray as $comment )
1160 {
1161 $textLine = '// ' . $comment;
1162 if ( $whitespaceHandling )
1163 {
1164 $textLine = rtrim( $textLine );
1165 $textLine = str_replace( "\t", ' ', $textLine );
1166 }
1167 $textLine = str_repeat( ' ', $spacing ) . $textLine;
1168 $newCommentArray[] = $textLine;
1169 }
1170 $text = implode( "\n", $newCommentArray );
1171 if ( $eol )
1172 $text .= "\n";
1173 $this->write( $text );
1174 }
1175
1179 function writeSpace( $element )
1180 {
1181 $text = str_repeat( "\n", $element[1] );
1182 $this->write( $text );
1183 }
1184
1188 function writeCodePiece( $element )
1189 {
1190 $code = $element[1];
1191 $parameters = $element[2];
1192 $spacing = 0;
1193 if ( isset( $parameters['spacing'] ) and $this->Spacing )
1194 $spacing = $parameters['spacing'];
1195 $text = eZPHPCreator::prependSpacing( $code, $spacing );
1196 $this->write( $text );
1197 }
1198
1202 function writeText( $element )
1203 {
1204 $text = $element[1];
1205 $this->write( "\n?>" );
1206 $this->write( $text );
1207 $this->write( "<?php\n" );
1208 }
1209
1213 function writeMethodCall( $element )
1214 {
1215 $objectName = $element[1];
1216 $methodName = $element[2];
1217 $methodParameters = $element[3];
1218 $returnValue = $element[4];
1219 $parameters = $element[5];
1220 $text = '';
1221 $spacing = 0;
1222 if ( isset( $parameters['spacing'] ) and $this->Spacing )
1223 $spacing = $parameters['spacing'];
1224 if ( is_array( $returnValue ) )
1225 {
1226 $variableName = $returnValue[0];
1227 $assignmentType = eZPHPCreator::VARIABLE_ASSIGNMENT;
1228 if ( isset( $variableValue[1] ) )
1229 $assignmentType = $variableValue[1];
1230 $text = $this->variableNameText( $variableName, $assignmentType );
1231 }
1232 $text .= '$' . $objectName . '->' . $methodName . '(';
1233 $column = strlen( $text );
1234 $i = 0;
1235 foreach ( $methodParameters as $parameterData )
1236 {
1237 if ( $i > 0 )
1238 $text .= ",\n" . str_repeat( ' ', $column );
1239 $parameterType = eZPHPCreator::METHOD_CALL_PARAMETER_VALUE;
1240 $parameterValue = $parameterData[0];
1241 if ( isset( $parameterData[1] ) )
1242 $parameterType = $parameterData[1];
1243 if ( $parameterType == eZPHPCreator::METHOD_CALL_PARAMETER_VALUE )
1244 $text .= ' ' . $this->thisVariableText( $parameterValue, $column + 1 );
1245 else if ( $parameterType == eZPHPCreator::METHOD_CALL_PARAMETER_VARIABLE )
1246 $text .= ' $' . $parameterValue;
1247 ++$i;
1248 }
1249 if ( $i > 0 )
1250 $text .= ' ';
1251 $text .= ");\n";
1252 $text = eZPHPCreator::prependSpacing( $text, $spacing );
1253 $this->write( $text );
1254 }
1255
1259 function writeVariableUnset( $element )
1260 {
1261 $variableName = $element[1];
1262 $parameters = $element[2];
1263 $spacing = 0;
1264 if ( isset( $parameters['spacing'] ) and $this->Spacing )
1265 $spacing = $parameters['spacing'];
1266 $text = "unset( \$$variableName );\n";
1267 $text = eZPHPCreator::prependSpacing( $text, $spacing );
1268 $this->write( $text );
1269 }
1270
1274 function writeVariableUnsetList( $element )
1275 {
1276 $variableNames = $element[1];
1277
1278 if ( count( $variableNames ) )
1279 {
1280 $parameters = $element[2];
1281 $spacing = 0;
1282 if ( isset( $parameters['spacing'] ) and $this->Spacing )
1283 $spacing = $parameters['spacing'];
1284 $text = 'unset( ';
1285 foreach( $variableNames as $k => $variableName )
1286 {
1287 $variableName="\$".$variableName;
1288 $variableNames[ $k ] = $variableName;
1289 }
1290 $text .= join( ', ', $variableNames );
1291 $text .= " );\n";
1292 $text = eZPHPCreator::prependSpacing( $text, $spacing );
1293 $this->write( $text );
1294 }
1295 }
1296
1300 function writeRawVariable( $variableName, $variableValue )
1301 {
1302 $this->write( "\${$variableName} = ". var_export( $variableValue, true). ";\n" );
1303 }
1304
1308 function writeVariable( $variableName, $variableValue, $assignmentType = eZPHPCreator::VARIABLE_ASSIGNMENT,
1309 $variableParameters = array() )
1310 {
1311 $variableParameters = array_merge( array( 'full-tree' => false,
1312 'spacing' => 0 ),
1313 $variableParameters );
1314 $fullTree = $variableParameters['full-tree'];
1315 $spacing = $this->Spacing ? $variableParameters['spacing'] : 0;
1316 $text = $this->variableNameText( $variableName, $assignmentType, $variableParameters );
1317 $maxIterations = 2;
1318 if ( $fullTree )
1319 $maxIterations = false;
1320 $text .= $this->thisVariableText( $variableValue, strlen( $text ), 0, $maxIterations );
1321 $text .= ";\n";
1322 $text = eZPHPCreator::prependSpacing( $text, $spacing );
1323 $this->write( $text );
1324 }
1325
1329 function temporaryVariableName( $prefix )
1330 {
1331 $variableName = $prefix . '_' . $this->TemporaryCounter;
1332 ++$this->TemporaryCounter;
1333 return $variableName;
1334 }
1335
1337 public $PHPDir;
1338 public $PHPFile;
1339 public $FilePrefix;
1340 public $FileResource;
1341 public $Elements;
1342 public $TextChunks;
1343 public $isAtomic;
1344 public $TemporaryCounter;
1345 public $tmpFilename;
1346 public $requestedFilename;
1347 public $Spacing = true;
1348 public $ClusterHandler;
1349 public $ClusteringEnabled = false;
1350 public $ClusterFileScope = false;
1351 }
1352 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:237
eZFile\CLEAN_ON_FAILURE
const CLEAN_ON_FAILURE
Definition: ezfile.php:31
eZFile\rename
static rename( $srcFile, $destFile, $mkdir=false, $flags=0)
Definition: ezfile.php:152
eZLog\writeStorageLog
static writeStorageLog( $name, $dir=false)
Definition: ezlog.php:85
eZPHPCreator
eZPHPCreator provides a simple interface for creating and executing PHP code.
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.