当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_CodeGenerator_Php_Class::fromReflection方法代码示例

本文整理汇总了PHP中Zend_CodeGenerator_Php_Class::fromReflection方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_CodeGenerator_Php_Class::fromReflection方法的具体用法?PHP Zend_CodeGenerator_Php_Class::fromReflection怎么用?PHP Zend_CodeGenerator_Php_Class::fromReflection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_CodeGenerator_Php_Class的用法示例。


在下文中一共展示了Zend_CodeGenerator_Php_Class::fromReflection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 /**
  * Get CodeGenerator instance for specified class
  *
  * @param	string			$className
  * @param 	bool 			$alias
  *
  * @return	bool|Zend_CodeGenerator_Php_Class
  */
 public static function get($className, $alias = true)
 {
     if (!XDT_CLI_Helper::classExists($className, true, $alias)) {
         return false;
     }
     $classNameOriginal = $className;
     // Load class file
     if ($alias) {
         $className = XDT_CLI_Helper::loadClassAliased($className);
     }
     $class = Zend_CodeGenerator_Php_Class::fromReflection(new Zend_Reflection_Class($className));
     if (!$class) {
         return false;
     }
     // Set tab indentation
     $class->setIndentation('	');
     if ($alias) {
         $class->setName($classNameOriginal);
     }
     return $class;
 }
开发者ID:NixFifty,项目名称:XenForo-XDT,代码行数:29,代码来源:ClassGenerator.php

示例2: updateAction

 /**
  * Update an action
  *
  * This method is used whenever an action is updated from the
  * administration panel.
  *
  * @param string $file  The file to update.
  * @param string $name  The name of the file to update.
  * @param array  $properties An array of properties related to an action.
  *
  * @return Either a generated/updated action or false.
  */
 private function updateAction($file, $name, $properties)
 {
     $className = 'Action_' . $name;
     if (!class_exists($className)) {
         include $file;
     }
     // In case the file is empty or messed up, lets generate it again
     if (!class_exists($className)) {
         return $this->generateAction($name, $properties);
     }
     try {
         $class = Zend_CodeGenerator_Php_Class::fromReflection(new Zend_Reflection_Class($className));
         $default = $class->getProperty('requiredParams');
         if (is_object($default) && $default->getDefaultValue()->getValue() != $properties) {
             $default->setSourceDirty(true);
             $class->setProperty($default->setDefaultValue($properties));
         }
         $file = new Zend_CodeGenerator_Php_File();
         $file->setClass($class);
     } catch (Exception $e) {
         return false;
     }
     return $file->generate();
 }
开发者ID:rjack,项目名称:frapi,代码行数:36,代码来源:Action.php

示例3: testClassFromReflectionDiscardParentImplementedInterfaces

 /**
  * @group ZF-7909
  */
 public function testClassFromReflectionDiscardParentImplementedInterfaces()
 {
     if (!class_exists('Zend_CodeGenerator_Php_ClassWithInterface')) {
         require_once dirname(__FILE__) . "/_files/ClassAndInterfaces.php";
     }
     require_once "Zend/Reflection/Class.php";
     $reflClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_NewClassWithInterface');
     $codeGen = Zend_CodeGenerator_Php_Class::fromReflection($reflClass);
     $codeGen->setSourceDirty(true);
     $code = $codeGen->generate();
     $expectedClassDef = 'class Zend_CodeGenerator_Php_NewClassWithInterface extends Zend_CodeGenerator_Php_ClassWithInterface implements Zend_Code_Generator_Php_ThreeInterface';
     $this->assertContains($expectedClassDef, $code);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:16,代码来源:ClassTest.php

示例4: fromReflection

 /**
  * fromReflection()
  *
  * @param Zend_Reflection_File $reflectionFile
  * @return Zend_CodeGenerator_Php_File
  */
 public static function fromReflection(Zend_Reflection_File $reflectionFile)
 {
     $file = new self();
     $file->setSourceContent($reflectionFile->getContents());
     $file->setSourceDirty(false);
     $body = $reflectionFile->getContents();
     // @todo this whole area needs to be reworked with respect to how body lines are processed
     foreach ($reflectionFile->getClasses() as $class) {
         $file->setClass(Zend_CodeGenerator_Php_Class::fromReflection($class));
         $classStartLine = $class->getStartLine(true);
         $classEndLine = $class->getEndLine();
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
             if ($lineNum == $classStartLine) {
                 $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass);
                 //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
                 $lineNum = $classEndLine;
             } else {
                 $bodyReturn[] = $bodyLines[$lineNum - 1];
                 // adjust for index -> line conversion
             }
         }
         $body = implode("\n", $bodyReturn);
         unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
     }
     if ($reflectionFile->getDocComment() != '') {
         $docblock = $reflectionFile->getDocblock();
         $file->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($docblock));
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
             if ($lineNum == $docblock->getStartLine()) {
                 $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock);
                 //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
                 $lineNum = $docblock->getEndLine();
             } else {
                 $bodyReturn[] = $bodyLines[$lineNum - 1];
                 // adjust for index -> line conversion
             }
         }
         $body = implode("\n", $bodyReturn);
         unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
     }
     $file->setBody($body);
     return $file;
 }
开发者ID:travisj,项目名称:zf,代码行数:53,代码来源:File.php

示例5: testAction

    public function testAction()
    {
        $name = 'Testing1';
        $dir  = ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'Action';
        $file = $dir . DIRECTORY_SEPARATOR . $name . '.php';
        require_once $file;

        $class = Zend_CodeGenerator_Php_Class::fromReflection(
            new Zend_Reflection_Class('Action_' . $name)
        );

        $error  = array();
        $errors = array();

        foreach ($class->getMethods() as $key => $method) {
            $body = $method->getBody();
            $methodName = $method->getName();

            $toks = token_get_all('<?' . 'php ' . $body . '?>');

            $it = new ArrayIterator($toks);

            for ($it->rewind(); $it->valid(); $it->next()) {
                $current = $it->current();
                $key = $it->key();

                $item = (double)$current[0];

                if ($item == T_STRING && stristr('frapi_error', $current[1]) !== false) {
                    if ($error = $this->getErrors($it, $methodName)) {
                        $errors[] = $error;
                    }
                }

            }
        }

        //print_r($errors);

        die();

    }
开发者ID:reith2004,项目名称:frapi,代码行数:42,代码来源:ActionController.php

示例6: create_action

    /**
     *
     * @param string $pAction
     * @return string
     */
    public function create_action($pAction = NULL, $pParams = NULL)
    {
        $action = $pAction ? $pAction : $this->get_action();
        if ($pParams && array_key_exists('view_body', $pParams)) {
            $view_body = $pParams['view_body'];
            unset($pParams['view_body']);
        } else {
            $view_body = '';
            if ($pParams && is_array($pParams) && count($pParams)) {
                foreach ($pParams as $param) {
                    if (is_array($param)) {
                        list($name, $alias, $default) = $param;
                        $default = trim($default);
                    } elseif (!trim($param)) {
                        continue;
                    } else {
                        $name = $alias = trim($param);
                        $default = NULL;
                    }
                    $name = trim($name);
                    if (!$name) {
                        continue;
                    }
                    ob_start();
                    ?>
    $this-><?php 
                    echo $name;
                    ?>
;
    
<?php 
                    $view_body .= ob_get_clean();
                }
            }
        }
        $file = $this->controller_reflection();
        $c = $file->getClass($this->controller_class_name());
        $aname = "{$action}Action";
        $class = Zend_CodeGenerator_Php_Class::fromReflection($c);
        if (!$class->hasMethod($aname)) {
            $body = '';
            $reflect = '';
            if ($pParams && is_array($pParams) && count($pParams)) {
                ob_start();
                foreach ($pParams as $param) {
                    if (!trim($param)) {
                        continue;
                    } elseif (is_array($param)) {
                        list($name, $alias, $default) = $param;
                        $default = trim($default);
                    } else {
                        $name = $alias = trim($param);
                        $default = NULL;
                    }
                    $name = trim($name);
                    if (!$name) {
                        continue;
                    }
                    printf('$%s = $this->_getParam("%s", %s); ', $name, $alias, is_null($default) ? ' NULL ' : "'{$default}'");
                    ob_start();
                    printf('$this->view->%s = $%s;', $name, $name);
                    ?>
    
<?php 
                    $reflect .= ob_get_clean();
                    ?>
    <?php 
                }
                $body = ob_get_clean() . "\n" . $reflect;
            }
            $old = $this->backup_controller();
            $method = new Zend_CodeGenerator_Php_Method();
            $method->setName($aname)->setBody($body);
            $class->setMethod($method);
            $file = new Zend_CodeGenerator_Php_File();
            $file->setClass($class);
            $new_file = preg_replace('~[\\r\\n][\\s]*[\\r\\n]~', "\r", $file->generate());
            file_put_contents($this->controller_path(), $new_file);
            $view_path = $this->view_path($action);
            if (!file_exists($view_path)) {
                $dir = dirname($view_path);
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, TRUE);
                }
                file_put_contents($view_path, "<?\n\$this->placeholder('page_title')->set('');\n{$view_body}\n");
            }
            $exec = "diff {$this->_backup_path} {$this->controller_path()} ";
            $diff = shell_exec($exec);
            return array('old' => $old, 'new' => $new_file, 'diff' => $diff, 'backup_path' => $this->_backup_path, 'controller_path' => $this->controller_path());
        }
    }
开发者ID:BGCX262,项目名称:zupal-svn-to-git,代码行数:96,代码来源:MVC.php


注:本文中的Zend_CodeGenerator_Php_Class::fromReflection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。