1. Vladimir Mihailenco
  2. vladimir.webdev

Commits

ad...@admin-PC.dic.md  committed 0bda687 Merge

merge

  • Participants
  • Parent commits b612bb8, a5d6e0f
  • Branches default

Comments (0)

Files changed (15)

File .hgignore

File contents unchanged.

File init.php

View file
+<?php
+if (!defined('PATH_SEPARATOR')) {
+    define('PATH_SEPARATOR', getenv('COMSPEC') ? ';' : ':');
+}
+ini_set(
+    'include_path',
+    ini_get('include_path')
+        . PATH_SEPARATOR . dirname(__FILE__) . '/library'
+);
+
+function __autoload($class)
+{
+    require str_replace('_', '/', $class) . '.php';
+}

File library/AnotherTool.php

View file
+<?php
+class AnotherTool extends ZendY_Registry_Tool
+{
+    public function anotherTool()
+    {
+        return __CLASS__;
+    }
+}

File library/Neno/Java/Jad.php

View file
+<?php
+class Neno_Java_Jad
+{
+    /**
+     * Enter description here...
+     *
+     * @var string
+     */
+    protected $_tempDir = '';
+
+    /**
+     * Enter description here...
+     *
+     * @var string
+     */
+    protected $_manifestPath = 'META-INF/MANIFEST.MF';
+
+    /**
+     * Enter description here...
+     *
+     * @param string $tempDir
+     * @return Neno_Java_Jad
+     */
+    public function setTempDir($tempDir)
+    {
+        $this->_tempDir = $tempDir;
+        return $this;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @return string
+     */
+    public function getTempDir()
+    {
+        if ('' === $this->_tempDir) {
+            $this->_tempDir = sys_get_temp_dir();
+        }
+        return $this->_tempDir;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $manifestPath
+     * @return Neno_Java_Jad
+     */
+    public function setManifestPath($manifestPath)
+    {
+        $this->_manifestPath = $manifestPath;
+        return $this;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @return string
+     */
+    public function getManifestPath()
+    {
+        return $this->_manifestPath;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $tempDir
+     */
+    public function __construct($tempDir = '')
+    {
+        $this->setTempDir($tempDir);
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $jarFile
+     * @param string $jarUrl
+     * @return string
+     */
+    public function generate($jarFile, $jarUrl)
+    {
+        $archive = new PclZip($jarFile);
+
+        $extracted = $archive->extract(
+            PCLZIP_OPT_PATH, $this->getTempDir(),
+            PCLZIP_OPT_BY_NAME, $this->getManifestPath()
+        );
+        if (0 === $extracted || 0 === count($extracted)) {
+            throw new Neno_Java_Jad_Exception('Could not find "META-INF/MANIFEST.MF" in "' . $jarFile . '"');
+        }
+
+        $manifest = new Neno_Java_Manifest($this->_tempDir . '/' . $this->_manifestPath);
+
+        unlink($this->_tempDir . '/' . $this->_manifestPath);
+
+        return $this->_generateJad($manifest, filesize($jarFile), $jarUrl);
+    }
+
+    protected function _generateJad(Neno_Java_Manifest $manifest, $size, $url)
+    {
+        $jad = '';
+        foreach ($manifest as $var => $value) {
+            $jad .= $var . $manifest->getSeparator() . $value . "\r\n";
+        }
+        $jad .= 'MIDlet-Jar-Size' . $manifest->getSeparator() . $size . "\r\n";
+        $jad .= 'MIDlet-Jar-URL' . $manifest->getSeparator() . $url . "\r\n";
+
+        return $jad;
+    }
+}

File library/Neno/Java/Jad/Exception.php

View file
+<?php
+class Neno_Java_Jad_Exception extends Neno_Exception
+{}

File library/Neno/Java/Manifest.php

View file
+<?php
+class Neno_Java_Manifest implements Countable, Iterator
+{
+    /**
+     * Enter description here...
+     *
+     * @var array
+     */
+    protected $_data = array();
+
+    /**
+     * Enter description here...
+     *
+     * @var int
+     */
+    protected $_index = 0;
+
+    /**
+     * Enter description here...
+     *
+     * @var int
+     */
+    protected $_count = 0;
+
+    /**
+     * Enter description here...
+     *
+     * @var string
+     */
+    protected $_filename = '';
+
+    /**
+     * Enter description here...
+     *
+     * @var array
+     */
+    protected $_allowedVars = array(
+        'Manifest-Version',
+        'Ant-Version',
+        'Created-By',
+        'Main-Class',
+        'MIDlet-1',
+        'MIDlet-Name',
+        'MIDlet-Vendor',
+        'MIDlet-Version',
+        'MicroEdition-Configuration',
+        'MicroEdition-Profile'
+    );
+
+    /**
+     * Enter description here...
+     *
+     * @var string
+     */
+    protected $_separator = ': ';
+
+    /**
+     * Enter description here...
+     *
+     * @param string $filename
+     * @return Neno_Java_Manifest
+     */
+    protected function setFilename($filename)
+    {
+        if (!is_file($filename)) {
+            throw new Neno_Java_Manifest_Exception('Could not find file "' . $filename . '"');
+        }
+        $this->_filename = $filename;
+        return $this;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @return string
+     */
+    protected function getFilename()
+    {
+        return $this->_filename;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $separator
+     * @return Neno_Java_Manifest
+     */
+    public function setSeparator($separator)
+    {
+        $this->_separator = $separator;
+        return $this;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @return string
+     */
+    public function getSeparator()
+    {
+        return $this->_separator;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $filename
+     */
+    public function __construct($filename = '')
+    {
+        if ('' !== $filename) {
+            $this->load($filename);
+        }
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function set($var, $value)
+    {
+        if (in_array($var, $this->_allowedVars)) {
+            switch ($var) {
+                case 'MIDlet-Name':
+                    if ($this->isDefined('MIDlet-1')) {
+                        $parts = explode(',', $this->get('MIDlet-1'));
+                        $parts[0] = $value;
+                        $this->set('MIDlet-1', implode(',', $parts));
+                    }
+                default:
+                    $this->_data[$var] = $value;
+            }
+        } else {
+            throw new Neno_Java_Manifest_Exception('Unknown property: ' . $var);
+        }
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function get($var)
+    {
+        if ($this->isDefined($var)) {
+            return $this->_data[$var];
+        } else {
+            throw new Neno_Java_Manifest_Exception('Undefined property: ' . $var);
+        }
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function isDefined($var)
+    {
+        if (
+            in_array($var, $this->_allowedVars)
+            && array_key_exists($var, $this->_data)
+        ) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function delete($var)
+    {
+        unset($this->_data[$var]);
+    }
+
+    public function fromArray($arr)
+    {
+        $this->_data = $arr;
+        return $this;
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function toArray()
+    {
+        return $this->_data;
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function count()
+    {
+        return $this->_count;
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function current()
+    {
+        return current($this->_data);
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function key()
+    {
+        return key($this->_data);
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function next()
+    {
+        next($this->_data);
+        $this->_index++;
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function rewind()
+    {
+        reset($this->_data);
+        $this->_index = 0;
+    }
+
+    /**
+     * Enter description here...
+     *
+     */
+    public function valid()
+    {
+        return $this->_index < $this->_count;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $filename
+     */
+    public function load($filename)
+    {
+        $this->setFilename($filename);
+
+        $manifest = file($this->getFilename());
+        $this->_data = array();
+        foreach ($manifest as $line) {
+            $line = trim($line);
+            if (empty($line)) continue;
+
+            list($var, $value) = explode($this->getSeparator(), $line);
+            $this->_data[$var] = $value;
+        }
+
+        $this->_count = count($this->_data);
+        $this->_index = 0;
+    }
+
+    /**
+     * Enter description here...
+     *
+     * @param string $filename
+     */
+    public function save($filename = '')
+    {
+        if (null !== $filename) {
+            $this->setFilename($filename);
+        }
+
+        $result = '';
+        foreach ($this->_data as $var => $value) {
+            $result .= $var . $this->getSeparator() . $value . "\r\n";
+        }
+        file_put_contents($this->getFilename(), $result);
+    }
+}

File library/Neno/Java/Manifest/Exception.php

View file
+<?php
+class Neno_Java_Manifest_Exception extends Neno_Exception
+{}

File library/TestTool.php

View file
+<?php
+class TestTool extends ZendY_Registry_Tool
+{
+    public function testTool()
+    {
+        return __CLASS__;
+    }
+}

File library/Zend/Debug.php

View file
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Debug
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+
+/**
+ * Concrete class for generating debug dumps related to the output source.
+ *
+ * @category   Zend
+ * @package    Zend_Debug
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+
+class Zend_Debug
+{
+
+    /**
+     * @var string
+     */
+    protected static $_sapi = null;
+
+    /**
+     * Get the current value of the debug output environment.
+     * This defaults to the value of PHP_SAPI.
+     *
+     * @return string;
+     */
+    public static function getSapi()
+    {
+        if (self::$_sapi === null) {
+            self::$_sapi = PHP_SAPI;
+        }
+        return self::$_sapi;
+    }
+
+    /**
+     * Set the debug ouput environment.
+     * Setting a value of null causes Zend_Debug to use PHP_SAPI.
+     *
+     * @param string $sapi
+     * @return void;
+     */
+    public static function setSapi($sapi)
+    {
+        self::$_sapi = $sapi;
+    }
+
+    /**
+     * Debug helper function.  This is a wrapper for var_dump() that adds
+     * the <pre /> tags, cleans up newlines and indents, and runs
+     * htmlentities() before output.
+     *
+     * @param  mixed  $var   The variable to dump.
+     * @param  string $label OPTIONAL Label to prepend to output.
+     * @param  bool   $echo  OPTIONAL Echo output if true.
+     * @return string
+     */
+    public static function dump($var, $label=null, $echo=true)
+    {
+        // format the label
+        $label = ($label===null) ? '' : rtrim($label) . ' ';
+
+        // var_dump the variable into a buffer and keep the output
+        ob_start();
+        var_dump($var);
+        $output = ob_get_clean();
+
+        // neaten the newlines and indents
+        $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
+        if (self::getSapi() == 'cli') {
+            $output = PHP_EOL . $label
+                    . PHP_EOL . $output
+                    . PHP_EOL;
+        } else {
+            if(!extension_loaded('xdebug')) {
+                $output = htmlspecialchars($output, ENT_QUOTES);
+            }
+
+            $output = '<pre>'
+                    . $label
+                    . $output
+                    . '</pre>';
+        }
+
+        if ($echo) {
+            echo($output);
+        }
+        return $output;
+    }
+
+}

File library/Zend/Registry.php

View file
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Registry
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Registry.php 15576 2009-05-14 12:41:46Z matthew $
+ */
+
+/**
+ * Generic storage class helps to manage global data.
+ *
+ * @category   Zend
+ * @package    Zend_Registry
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Registry extends ArrayObject
+{
+    /**
+     * Class name of the singleton registry object.
+     * @var string
+     */
+    private static $_registryClassName = 'Zend_Registry';
+
+    /**
+     * Registry object provides storage for shared objects.
+     * @var Zend_Registry
+     */
+    private static $_registry = null;
+
+    /**
+     * Retrieves the default registry instance.
+     *
+     * @return Zend_Registry
+     */
+    public static function getInstance()
+    {
+        if (self::$_registry === null) {
+            self::init();
+        }
+
+        return self::$_registry;
+    }
+
+    /**
+     * Set the default registry instance to a specified instance.
+     *
+     * @param Zend_Registry $registry An object instance of type Zend_Registry,
+     *   or a subclass.
+     * @return void
+     * @throws Zend_Exception if registry is already initialized.
+     */
+    public static function setInstance(Zend_Registry $registry)
+    {
+        if (self::$_registry !== null) {
+            require_once 'Zend/Exception.php';
+            throw new Zend_Exception('Registry is already initialized');
+        }
+
+        self::setClassName(get_class($registry));
+        self::$_registry = $registry;
+    }
+
+    /**
+     * Initialize the default registry instance.
+     *
+     * @return void
+     */
+    protected static function init()
+    {
+        self::setInstance(new self::$_registryClassName());
+    }
+
+    /**
+     * Set the class name to use for the default registry instance.
+     * Does not affect the currently initialized instance, it only applies
+     * for the next time you instantiate.
+     *
+     * @param string $registryClassName
+     * @return void
+     * @throws Zend_Exception if the registry is initialized or if the
+     *   class name is not valid.
+     */
+    public static function setClassName($registryClassName = 'Zend_Registry')
+    {
+        if (self::$_registry !== null) {
+            require_once 'Zend/Exception.php';
+            throw new Zend_Exception('Registry is already initialized');
+        }
+
+        if (!is_string($registryClassName)) {
+            require_once 'Zend/Exception.php';
+            throw new Zend_Exception("Argument is not a class name");
+        }
+
+        /**
+         * @see Zend_Loader
+         */
+        if (!class_exists($registryClassName)) {
+            require_once 'Zend/Loader.php';
+            Zend_Loader::loadClass($registryClassName);
+        }
+
+        self::$_registryClassName = $registryClassName;
+    }
+
+    /**
+     * Unset the default registry instance.
+     * Primarily used in tearDown() in unit tests.
+     * @returns void
+     */
+    public static function _unsetInstance()
+    {
+        self::$_registry = null;
+    }
+
+    /**
+     * getter method, basically same as offsetGet().
+     *
+     * This method can be called from an object of type Zend_Registry, or it
+     * can be called statically.  In the latter case, it uses the default
+     * static instance stored in the class.
+     *
+     * @param string $index - get the value associated with $index
+     * @return mixed
+     * @throws Zend_Exception if no entry is registerd for $index.
+     */
+    public static function get($index)
+    {
+        $instance = self::getInstance();
+
+        if (!$instance->offsetExists($index)) {
+            require_once 'Zend/Exception.php';
+            throw new Zend_Exception("No entry is registered for key '$index'");
+        }
+
+        return $instance->offsetGet($index);
+    }
+
+    /**
+     * setter method, basically same as offsetSet().
+     *
+     * This method can be called from an object of type Zend_Registry, or it
+     * can be called statically.  In the latter case, it uses the default
+     * static instance stored in the class.
+     *
+     * @param string $index The location in the ArrayObject in which to store
+     *   the value.
+     * @param mixed $value The object to store in the ArrayObject.
+     * @return void
+     */
+    public static function set($index, $value)
+    {
+        $instance = self::getInstance();
+        $instance->offsetSet($index, $value);
+    }
+
+    /**
+     * Returns TRUE if the $index is a named value in the registry,
+     * or FALSE if $index was not found in the registry.
+     *
+     * @param  string $index
+     * @return boolean
+     */
+    public static function isRegistered($index)
+    {
+        if (self::$_registry === null) {
+            return false;
+        }
+        return self::$_registry->offsetExists($index);
+    }
+
+    /**
+     * Constructs a parent ArrayObject with default
+     * ARRAY_AS_PROPS to allow acces as an object
+     *
+     * @param array $array data array
+     * @param integer $flags ArrayObject flags
+     */
+    public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
+    {
+        parent::__construct($array, $flags);
+    }
+
+    /**
+     * @param string $index
+     * @returns mixed
+     *
+     * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960).
+     */
+    public function offsetExists($index)
+    {
+        return array_key_exists($index, $this);
+    }
+
+}

File library/ZendY/Registry/Tool.php

View file
+<?php
+abstract class ZendY_Registry_Tool
+{
+    protected $_previous = null;
+
+    public function setPrevious(ZendY_Registry_Tool $previous)
+    {
+        if ($this->_previous) {
+            $this->_previous->setPrevious($previous);
+        } else {
+            $this->_previous = $previous;
+        }
+        return $this;
+    }
+
+    public function getPrevious()
+    {
+        return $this->_previous;
+    }
+
+    public function __construct(ZendY_Registry_Tool $previous = null)
+    {
+        if (null !== $previous) {
+            $this->setPrevious($previous);
+        }
+    }
+
+    public function __call($method, $args)
+    {
+        if (null !== $this->_previous) {
+            return $this->_previous->$method();
+        } else {
+            throw new ZendY_Registry_Tool_Exception('Undefined tool "' . $method . '"');
+        }
+    }
+
+    public function get($index)
+    {
+        $method = $index . 'Tool';
+        return $this->$method();
+    }
+}

File library/ZendY/Registry/Tool/Exception.php

View file
+<?php
+
+class ZendY_Registry_Tool_Exception extends Exception
+{}

File library/ZendY/Registry/Toolkit.php

View file
+<?php
+class ZendY_Registry_Toolkit extends Zend_Registry
+{
+    protected $_tool = null;
+
+    public function setTool(ZendY_Registry_Tool $tool)
+    {
+        $this->_tool = $tool;
+        return $this;
+    }
+
+    public function getTool()
+    {
+        return $this->_tool;
+    }
+
+    public function addTool(ZendY_Registry_Tool $tool)
+    {
+        if ($this->_tool) {
+            $tool->setPrevious($this->_tool);
+        }
+        $this->setTool($tool);
+        return $this;
+    }
+
+    public function emptyTool()
+    {
+        $this->_tool = null;
+        return $this;
+    }
+
+    public function offsetExists($index)
+    {
+        if (parent::offsetExists($index)) {
+            return true;
+        } else {
+            try {
+                $this->offsetSet($index, $this->_tool->get($index));
+                return true;
+            } catch (ZendY_Registry_Tool_Exception $e) {
+                return false;
+            }        
+        }
+    }
+}

File library/ZendY/View/Helper/Highlight.php

View file
+<?php
+class ZendY_View_Helper_Highlight extends Zend_View_Helper_Abstract
+{
+    protected $_scriptPath = '';
+    protected $_stylePath = '';
+    protected $_tabReplace = '';
+    protected $_languages = array();
+
+    public function setBasePath($path)
+    {
+        $this->_basePath = $path;
+        return $this;
+    }
+
+    public function getBasePath()
+    {
+        return $this->_basePath;
+    }
+
+    public function setScriptPath($path)
+    {
+        $this->_scriptPath = $this->getBasePath() . $path;
+        return $this;
+    }
+
+    public function getScriptPath()
+    {
+        return $this->_scriptPath;
+    }
+
+    public function setStylePath($path)
+    {
+        $this->_stylePath = $this->getBasePath() . $path;
+        return $this;
+    }
+
+    public function getStylePath()
+    {
+        return $this->_stylePath;
+    }
+
+    public function setTabReplace($tabReplace)
+    {
+        $this->_tabReplace = $tabReplace;
+        return $this;
+    }
+
+    public function getTabReplace()
+    {
+        return $this->_tabReplace;
+    }
+
+    public function setLanguages(array $languages)
+    {
+        $this->_languages = $languages;
+        return $this;
+    }
+
+    public function getLanguages()
+    {
+        return $this->_languages;
+    }
+
+    public function setOptions(array $options)
+    {
+        foreach ($options as $key => $value) {
+            $methodName = 'set' . $key;
+            if (method_exists($this, $methodName)) {
+                $this->$methodName($value);
+            } else {
+                throw new Zend_View_Exception('Unknown option "' . $key . '"');
+            }
+        }
+        return $this;
+    }
+
+    public function highlight(array $options = array())
+    {
+        $this->setOptions($options);
+        return $this;
+    }
+
+    protected function _getScript()
+    {
+        $script = '';
+
+        $tabReplace = $this->getTabReplace();
+        if ('' !== $tabReplace) {
+            $tabReplace = str_replace('"', '\"', $tabReplace);
+            $script .= 'hljs.tabReplace = "' . $tabReplace . '";' . PHP_EOL;
+        }
+
+        $languages = $this->getLanguages();
+        if (array() !== $languages) {
+            $languages = '"' . implode('", "', $languages) . '"';
+        } else {
+            $languages = '';
+        }
+        $script .= 'hljs.initHighlightingOnLoad(' . $languages . ');' . PHP_EOL;
+
+        return $script;
+    }
+
+    public function inject()
+    {
+        $localPath = $this->getScriptPath();
+        if ('' !== $localPath) {
+	        $this->view->headScript()
+		        ->appendFile($localPath)
+		        ->appendScript($this->_getScript())
+		    ;
+        } else {
+            throw new Zend_View_Exception('Option "scriptPath" must be set');
+        }
+
+        $stylePath = $this->getStylePath();
+        if ('' !== $stylePath) {
+		    $this->view->headLink()
+		        ->appendStylesheet($stylePath)
+		    ;
+        }
+    }
+
+    public function __toString()
+    {
+        $this->inject();
+        return '';
+    }
+}

File zendRegistry.php

View file
+<?php
+require_once './init.php';
+
+Zend_Registry::setInstance(new ZendY_Registry_Toolkit());
+$toolkit = Zend_Registry::getInstance();
+
+$toolkit->addTool(new TestTool());
+$toolkit->addTool(new AnotherTool());
+
+Zend_Debug::dump(Zend_Registry::get('test'));
+Zend_Debug::dump(Zend_Registry::get('another'));