Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

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