diff --git a/framework/yii/gii/ActiveField.php b/framework/yii/gii/ActiveField.php deleted file mode 100644 index 9a03987..0000000 --- a/framework/yii/gii/ActiveField.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class ActiveField extends \yii\widgets\ActiveField -{ - public function sticky() - { - $this->options['class'] .= ' sticky'; - return $this; - } -} diff --git a/framework/yii/gii/CodeFile.php b/framework/yii/gii/CodeFile.php index bb42294..d1c6aad 100644 --- a/framework/yii/gii/CodeFile.php +++ b/framework/yii/gii/CodeFile.php @@ -9,6 +9,8 @@ namespace yii\gii; use Yii; use yii\base\Object; +use yii\gii\components\TextDiff; +use yii\helpers\Html; /** * @@ -21,6 +23,7 @@ class CodeFile extends Object const OP_OVERWRITE = 'overwrite'; const OP_SKIP = 'skip'; + public $id; /** * @var string the file path that the new code should be saved to. */ @@ -34,10 +37,6 @@ class CodeFile extends Object * @var string the operation to be performed */ public $operation; - /** - * @var string the error occurred when saving the code into a file - */ - public $error; /** * Constructor. @@ -48,11 +47,9 @@ class CodeFile extends Object { $this->path = strtr($path, array('/' => DIRECTORY_SEPARATOR, '\\' => DIRECTORY_SEPARATOR)); $this->content = $content; + $this->id = md5($this->path); if (is_file($path)) { $this->operation = file_get_contents($path) === $content ? self::OP_SKIP : self::OP_OVERWRITE; - } elseif ($content === null) // is dir - { - $this->operation = is_dir($path) ? self::OP_SKIP : self::OP_NEW; } else { $this->operation = self::OP_NEW; } @@ -60,24 +57,11 @@ class CodeFile extends Object /** * Saves the code into the file {@link path}. + * @return string|boolean */ public function save() { $module = Yii::$app->controller->module; - if ($this->content === null) // a directory - { - if (!is_dir($this->path)) { - $oldmask = @umask(0); - $result = @mkdir($this->path, $module->newDirMode, true); - @umask($oldmask); - if (!$result) { - $this->error = "Unable to create the directory '{$this->path}'."; - return false; - } - } - return true; - } - if ($this->operation === self::OP_NEW) { $dir = dirname($this->path); if (!is_dir($dir)) { @@ -85,14 +69,12 @@ class CodeFile extends Object $result = @mkdir($dir, $module->newDirMode, true); @umask($oldmask); if (!$result) { - $this->error = "Unable to create the directory '$dir'."; - return false; + return "Unable to create the directory '$dir'."; } } } if (@file_put_contents($this->path, $this->content) === false) { - $this->error = "Unable to write the file '{$this->path}'."; - return false; + return "Unable to write the file '{$this->path}'."; } else { $oldmask = @umask(0); @chmod($this->path, $module->newFileMode); @@ -124,4 +106,33 @@ class CodeFile extends Object return 'unknown'; } } + + public function preview() + { + if (($pos = strrpos($this->path, '.')) !== false) { + $type = substr($this->path, $pos + 1); + } else { + $type = 'unknown'; + } + + if ($type === 'php') { + return '
order
generates OrderController.php
order-item
generates OrderItemController.php
admin/user
generates UserController.php
within the admin
module.
+ You may change the content of this page by modifying
+ the file echo __FILE__; ?>
.
+
order
generates OrderController.php
order-item
generates OrderItemController.php
admin/user
generates UserController.php
within the admin
module.
+ * $diff = new Horde_Text_Diff($lines1, $lines2);
+ * $rev = $diff->reverse();
+ *
+ *
+ * @return Horde_Text_Diff A Diff object representing the inverse of the
+ * original diff. Note that we purposely don't return a
+ * reference here, since this essentially is a clone()
+ * method.
+ */
+ public function reverse()
+ {
+ if (version_compare(zend_version(), '2', '>')) {
+ $rev = clone($this);
+ } else {
+ $rev = $this;
+ }
+ $rev->_edits = array();
+ foreach ($this->_edits as $edit) {
+ $rev->_edits[] = $edit->reverse();
+ }
+ return $rev;
+ }
+
+ /**
+ * Checks for an empty diff.
+ *
+ * @return boolean True if two sequences were identical.
+ */
+ public function isEmpty()
+ {
+ foreach ($this->_edits as $edit) {
+ if (!($edit instanceof Horde_Text_Diff_Op_Copy)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Computes the length of the Longest Common Subsequence (LCS).
+ *
+ * This is mostly for diagnostic purposes.
+ *
+ * @return integer The length of the LCS.
+ */
+ public function lcs()
+ {
+ $lcs = 0;
+ foreach ($this->_edits as $edit) {
+ if ($edit instanceof Horde_Text_Diff_Op_Copy) {
+ $lcs += count($edit->orig);
+ }
+ }
+ return $lcs;
+ }
+
+ /**
+ * Gets the original set of lines.
+ *
+ * This reconstructs the $from_lines parameter passed to the constructor.
+ *
+ * @return array The original sequence of strings.
+ */
+ public function getOriginal()
+ {
+ $lines = array();
+ foreach ($this->_edits as $edit) {
+ if ($edit->orig) {
+ array_splice($lines, count($lines), 0, $edit->orig);
+ }
+ }
+ return $lines;
+ }
+
+ /**
+ * Gets the final set of lines.
+ *
+ * This reconstructs the $to_lines parameter passed to the constructor.
+ *
+ * @return array The sequence of strings.
+ */
+ public function getFinal()
+ {
+ $lines = array();
+ foreach ($this->_edits as $edit) {
+ if ($edit->final) {
+ array_splice($lines, count($lines), 0, $edit->final);
+ }
+ }
+ return $lines;
+ }
+
+ /**
+ * Removes trailing newlines from a line of text. This is meant to be used
+ * with array_walk().
+ *
+ * @param string $line The line to trim.
+ * @param integer $key The index of the line in the array. Not used.
+ */
+ static public function trimNewlines(&$line, $key)
+ {
+ $line = str_replace(array("\n", "\r"), '', $line);
+ }
+
+ /**
+ * Checks a diff for validity.
+ *
+ * This is here only for debugging purposes.
+ */
+ protected function _check($from_lines, $to_lines)
+ {
+ if (serialize($from_lines) != serialize($this->getOriginal())) {
+ trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
+ }
+ if (serialize($to_lines) != serialize($this->getFinal())) {
+ trigger_error("Reconstructed final doesn't match", E_USER_ERROR);
+ }
+
+ $rev = $this->reverse();
+ if (serialize($to_lines) != serialize($rev->getOriginal())) {
+ trigger_error("Reversed original doesn't match", E_USER_ERROR);
+ }
+ if (serialize($from_lines) != serialize($rev->getFinal())) {
+ trigger_error("Reversed final doesn't match", E_USER_ERROR);
+ }
+
+ $prevtype = null;
+ foreach ($this->_edits as $edit) {
+ if ($prevtype == get_class($edit)) {
+ trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
+ }
+ $prevtype = get_class($edit);
+ }
+
+ return true;
+ }
+}
diff --git a/framework/yii/gii/lib/Horde/Text/Diff/Engine/Native.php b/framework/yii/gii/lib/Horde/Text/Diff/Engine/Native.php
new file mode 100644
index 0000000..e1318e7
--- /dev/null
+++ b/framework/yii/gii/lib/Horde/Text/Diff/Engine/Native.php
@@ -0,0 +1,435 @@
+ 2, and some optimizations) are from
+ * Geoffrey T. Dairiki Code File | -Action | -- operation !== CodeFile::OP_SKIP) { - $count++; - } - } - if ($count > 1) { - echo ''; - } - ?> - | -
---|---|---|
- getRelativePath()), array('code', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?> - operation === CodeFile::OP_OVERWRITE): ?> - $i), array('class' => 'view-code label label-warning', 'rel' => $file->path)); ?> - - | -- operation === CodeFile::OP_SKIP) { - echo 'unchanged'; - } else { - echo $file->operation; - } - ?> - | -- operation === CodeFile::OP_SKIP) { - echo ' '; - } else { - $key = md5($file->path); - echo Html::checkBox("answers[$key]", isset($answers) ? isset($answers[$key]) : ($file->operation === CodeFile::OP_NEW)); - } - ?> - | -
Start the fun with the following code generators:
diff --git a/framework/yii/gii/views/default/view.php b/framework/yii/gii/views/default/view.php index 541ae26..b8ff95c 100644 --- a/framework/yii/gii/views/default/view.php +++ b/framework/yii/gii/views/default/view.php @@ -3,13 +3,15 @@ use yii\gii\Generator; use yii\helpers\Html; use yii\widgets\ActiveForm; +use yii\gii\components\ActiveField; use yii\gii\CodeFile; /** * @var yii\base\View $this * @var yii\gii\Generator $generator * @var yii\widgets\ActiveForm $form - * @var string $result + * @var string $results + * @var boolean $hasError * @var CodeFile[] $files * @var array $answers */ @@ -25,37 +27,42 @@ foreach ($generator->templates as $name => $path) {getDescription(); ?>
- array('class' => 'yii\gii\ActiveField'))); ?> -Click on the above Generate
button to generate the files selected below:
Code File | +Action | ++ operation !== CodeFile::OP_SKIP) { + echo ''; + break; + } + } + ?> + | +
---|---|---|
+ getRelativePath()), array('preview', 'file' => $file->id), array('class' => 'preview-code', 'data-title' => $file->getRelativePath())); ?> + operation === CodeFile::OP_OVERWRITE): ?> + $file->id), array('class' => 'diff-code label label-warning', 'data-title' => $file->getRelativePath())); ?> + + | ++ operation === CodeFile::OP_SKIP) { + echo 'unchanged'; + } else { + echo $file->operation; + } + ?> + | ++ operation === CodeFile::OP_SKIP) { + echo ' '; + } else { + echo Html::checkBox("answers[{$file->id}]", isset($answers) ? isset($answers[$file->id]) : ($file->operation === CodeFile::OP_NEW)); + } + ?> + | +