the fact of real shit

Changing ZF2 core 2.4.13 \Zend\Stdlib\Hydrator\AbstractHydrator::hasStrategy

class: Zend\Stdlib\Hydrator\AbstractHydrator
function: hasStrategy
php version: 7.4

public function hasStrategy($name)
{
if(is_array($this->strategies))
return array_key_exists($name, $this->strategies)
|| array_key_exists(‘*’, $this->strategies);
if(is_object($this->strategies)) return property_exists($this->strategies, $name);
return false;
}

new change / new code

Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /media/shkr-home-wifi/works/workspace/vendor/ZF2/library/ Zend\Stdlib\Hydrator\AbstractHydrator on line 87

reason of change

public function hasStrategy($name)
{
return array_key_exists($name, $this->strategies)
|| array_key_exists(‘*’, $this->strategies);
}

previous code
Posted in php, zf2Tagged , , , , ,

Changing ZF2 Core 2.4.13 /Zend/I18n/Translator/Loader/Gettext::load

class: Zend\I18n/Translator/Loader/Gettext
function: load
php version: 7.4

Last portion change …….

if ($textDomain->offsetExists(”)) {
$rawHeaders = explode(“\n”, trim($textDomain->offsetGet(”)));
foreach ($rawHeaders as $rawHeader) {
list($header, $content) = explode(‘:’, $rawHeader, 2);
if (trim(strtolower($header)) === ‘plural-forms’) {
$textDomain->setPluralRule(PluralRule::fromString($content));
}
}
$textDomain->offsetUnset(”);
}

………….. end of change ………………..

Reason to change: Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in …/Zend/I18n/Translator/Loader/Gettext.php on line 142

///////// previous code ///////////////////

if (array_key_exists(”, $textDomain)) {
$rawHeaders = explode(“\n”, trim($textDomain[”]));
foreach ($rawHeaders as $rawHeader) {
list($header, $content) = explode(‘:’, $rawHeader, 2);
if (trim(strtolower($header)) === ‘plural-forms’) {
$textDomain->setPluralRule(PluralRule::fromString($content));
}
}
unset($textDomain[”]);
}

Posted in php, zf2Tagged , , , ,

Changing ZF2 Core 2.4.13 Zend\View\Helper\HeadLink::createDataStylesheet

class: Zend\View\Helper\HeadLink
function: createDataStylesheet
php version: 7.3

public function createDataStylesheet(array $args)
{
$rel = ‘stylesheet’;
$type = ‘text/css’;
$media = ‘screen’;
$conditionalStylesheet = false;
$href = array_shift($args);
if ($this->isDuplicateStylesheet($href)) { return false; } if (0 < count($args)) { $media = array_shift($args); if (is_array($media)) { $media = implode(',', $media); } else { $media = (string) $media; } } if (0 < count($args)) { $conditionalStylesheet = array_shift($args); if (!empty($conditionalStylesheet) && is_string($conditionalStylesheet)) { $conditionalStylesheet = (string) $conditionalStylesheet; } else { $conditionalStylesheet = null; } } $attributes = compact('rel', 'type', 'href', 'media', 'conditionalStylesheet'); if (0 < count($args) && is_array($args[0])) { $extras = array_shift($args); $attributes['extras'] = (array) $extras; } return $this->createData($attributes); }

new/modified/final/current code

public function createDataStylesheet(array $args)
{
$rel = ‘stylesheet’;
$type = ‘text/css’;
$media = ‘screen’;
$conditionalStylesheet = false;
$href = array_shift($args);
if ($this->isDuplicateStylesheet($href)) { return false; } if (0 < count($args)) { $media = array_shift($args); if (is_array($media)) { $media = implode(',', $media); } else { $media = (string) $media; } } if (0 < count($args)) { $conditionalStylesheet = array_shift($args); if (!empty($conditionalStylesheet) && is_string($conditionalStylesheet)) { $conditionalStylesheet = (string) $conditionalStylesheet; } else { $conditionalStylesheet = null; } } if (0 < count($args) && is_array($args[0])) { $extras = array_shift($args); $extras = (array) $extras; } $attributes = compact('rel', 'type', 'href', 'media', 'conditionalStylesheet', 'extras'); return $this->createData($attributes); }

previous/original/old code
Posted in php, zf2Tagged , , , ,

changing zf2 core 2.4.13 Zend/Stdlib/ArrayObject.php

class : Zend\Stdlib\ArrayObject
function: unserialize($data)
php version: 7.3

previous (original) code

/**
* Unserialize an ArrayObject
*
* @param string $data
* @return void
*/
public function unserialize($data)
{
$ar = unserialize($data);
$this->protectedProperties = array_keys(get_object_vars($this));

$this->setFlags($ar[‘flag’]);
$this->exchangeArray($ar[‘storage’]);
$this->setIteratorClass($ar[‘iteratorClass’]);

foreach ($ar as $k => $v) {
switch ($k) {
case ‘flag’:
$this->setFlags($v);
break;
case ‘storage’:
$this->exchangeArray($v);
break;
case ‘iteratorClass’:
$this->setIteratorClass($v);
break;
case ‘protectedProperties’:
continue;
default:
$this->__set($k, $v);
}
}
}

new code

public function unserialize($data)
{
$ar = unserialize($data);
$this->protectedProperties = array_keys(get_object_vars($this));

$this->setFlags($ar[‘flag’]);
$this->exchangeArray($ar[‘storage’]);
$this->setIteratorClass($ar[‘iteratorClass’]);

$need2continue=false;
foreach ($ar as $k => $v) {
$need2continue=false;
switch ($k) {
case ‘flag’:
$this->setFlags($v);
break;
case ‘storage’:
$this->exchangeArray($v);
break;
case ‘iteratorClass’:
$this->setIteratorClass($v);
break;
case ‘protectedProperties’:
/**
* in php 7.3 it shows
* Warning: “continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”? in /…location of zf2 ………../Zend/Stdlib/ArrayObject.php on line 426
*/
#continue;
$need2continue=true;
break;
default:
$this->__set($k, $v);
}
if(true==$need2continue) continue;
}
}

 

Posted in php, zf2Tagged , , , ,

going to change ZF2.4.9 core

I decided to change ZF 2.4.9 core. I know its a wired decision. But I don’t have any choice, cause they didn’t provide any release for PHP 7x. But the change will noted in this site by adding post for future.

Today I’m changing –

class: Zend\Validator\EmailAddress
function: idnToAscii($email) and
function: idnToUtf8($email)

Previous (original) code –

protected function idnToAscii($email)
{
if (extension_loaded(‘intl’)) {
return (idn_to_ascii($email) ?: $email);
}
return $email;
}

protected function idnToUtf8($email)
{
if (extension_loaded(‘intl’)) {
return idn_to_utf8($email);
}
return $email;
}

New Code

protected function idnToAscii($email)
{
if (extension_loaded(‘intl’)) {
return (idn_to_ascii($email, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) ?: $email);
}
return $email;
}

protected function idnToUtf8($email)
{
if (extension_loaded(‘intl’)) {
return idn_to_utf8($email, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
}
return $email;
}

I took this decision for –

https://bugs.php.net/bug.php?id=75609 and
https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003

 

Posted in php, zf2Tagged , , ,

PHP Archive (.phar) Attaching with ZF2

PHP archive aka phar is a stream wrapper which can serve any packaged PHP library efficiently.

To create a phar document for a library (not for web output or for cli executable) is simple as pie like –

$phar = new \Phar('target-location-where-to-save.phar', 
 FilesystemIterator::CURRENT_AS_FILEINFO |
 FilesystemIterator::KEY_AS_FILENAME, 'optionalPharAliasName');
$phar->buildFromDirectory('source/lib/path');

After creating phar document, file can use to attach ZF2 standard autoloader as follows –

Zend\Loader\AutoloaderFactory::factory(array(
 'Zend\Loader\StandardAutoloader' => array(
   'autoregister_zf' => true,
   'namespaces' => array(
          'YourProjectNamespace'=>'phar:///absolute/path/of/project/phar/file.phar',
        ),
     ),
   ));

This works as simple folder of your file system. Easily distributable, packaged.

Posted in php, webdevelopmentTagged , , , , , , ,

Batch file that will create skeleton directories of ZF2

After a long time write a batch file to create a skeleton directory for Zend Framework 2 module. Hope it may help someone who work in windows 7 OS

@echo off
@setlocal ENABLEDELAYEDEXPANSION
@rem this file will create required empty directory of a ZF2 module
@rem author Shahadat Hossain Khan (shahadathossain.com)
ECHO.
IF "%~1"=="" GOTO noModuleName
SET modName=%~1
CALL :UCase %modName% _UCMN
CALL :LCase %modName% _LCMN
IF NOT EXIST "%_UCMN%" (
 MKDIR %_UCMN%
 MKDIR %_UCMN%\config
 MKDIR %_UCMN%\src
 MKDIR %_UCMN%\src\%_UCMN%
 MKDIR %_UCMN%\src\%_UCMN%\Controller
 MKDIR %_UCMN%\src\%_UCMN%\Form
 MKDIR %_UCMN%\src\%_UCMN%\Model
 MKDIR %_UCMN%\view\
 MKDIR %_UCMN%\view\%_LCMN%
 MKDIR %_UCMN%\view\%_LCMN%\%_LCMN%
 ECHO Directory created. Named - %modName%
) else (
 ECHO Directory already exist!
) 
GOTO:EOF
:noModuleName
ECHO You must provide module name along with this command as 1st argument
GOTO:EOF


:LCase
:UCase
:: Syntax: CALL :UCase _VAR1 _VAR2
:: Syntax: CALL :LCase _VAR1 _VAR2
:: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
:: _VAR2 = NAME of variable to hold the converted value
:: Note: Use variable NAMES in the CALL, not values (pass "by reference")
set varX=%1
set frstChar=%varX:~0,1%
set rstChar=%varX:~1%
FOR %%Z IN (Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx 
Yy Zz) DO (
 SET pX=%%Z
 set c1=!pX:~0,1!
 set c2=!pX:~1,1!
 IF /I "%0"==":UCase" (
 if %frstChar%==!c1! SET _Abet=!c1!
 if %frstChar%==!c2! SET _Abet=!c1!
 )
 IF /I "%0"==":LCase" (
 if %frstChar%==!c1! SET _Abet=!c2!
 if %frstChar%==!c2! SET _Abet=!c2!
 )
)
SET _Word_Rtrn=%_Abet%%rstChar%
SET %2=%_Word_Rtrn%
GOTO:EOF


endlocal

Usage

<your batch file name> <the module name>

Posted in php, webdevelopment, windowsTagged , , , , , , ,

Install Zend Framework 2 into Windows IIS

This article will show you how you can install Zend Framework 2 into your windows OS without composer.phar help.

1. Download latest stable copy of ZF2 from http://framework.zend.com/downloads/latest and unpack, we call it ZF2

2. Download latest stable copy of ZF2 skeleton app from https://github.com/zendframework/ZendSkeletonApplication/ and unpack, we call it ZF2Skeleton

3. Create folder like <ZF2Skeleton folder>/vendor/ZF2. Now copy ZF2/* into <ZF2Skeleton folder>/vendor/ZF2 And the final directory structure may look like following image (for ZF2 version 2.3.1 dated 20140426)

zf2 basic folder structure

4. Now point any domain into “public” folder. e.g. zf2.localhost.tld

  • 4.a. Open notepad as administrator user
  • 4.b. Add an entry to your hosts (file) like – “127.0.0.1 zf2.localhost.tld” [one host in each line]
    • 4.b.1 hosts file is typically located at C:\WINDOWS\system32\drivers\etc\hosts
  • 4.c Now save the hosts file and close
  • 4.d. Now create an entry in your IIS (6 or 7 both are same procedure) by following http://support.microsoft.com/kb/816576 with the above host name i.e. zf2.localhost.tld

5. Now you need to fix ZF2_PATH or $zf2Path variable at “/init_autoloader.php” file of root to point our “/vendor/ZF2” folder

Find following code:

$zf2Path = false;
if (getenv(‘ZF2_PATH’)) { // Support for ZF2_PATH environment variable
$zf2Path = getenv(‘ZF2_PATH’);
} elseif (get_cfg_var(‘zf2_path’)) { // Support for zf2_path directive value
$zf2Path = get_cfg_var(‘zf2_path’);
}

Replace by following code:

define(‘DS’, DIRECTORY_SEPARATOR);
define(‘APP_ROOT_PATH’, dirname(__FILE__).DS);
$zf2Path = false;
if (is_dir(APP_ROOT_PATH.’vendor’.DS.’ZF2′.DS.’library’)) {
$zf2Path = APP_ROOT_PATH.’vendor’.DS.’ZF2′.DS.’library’;
} elseif (getenv(‘ZF2_PATH’)) { // Support for ZF2_PATH environment variable or git submodule
$zf2Path = getenv(‘ZF2_PATH’);
} elseif (get_cfg_var(‘zf2_path’)) { // Support for zf2_path directive value
$zf2Path = get_cfg_var(‘zf2_path’);
}

You can now visit zf2.localhost.tld to get your expected site.

Please note, you must run latest copy of PHP (at least bigger then 5.3.23 when I write this article there I found version 5.3.28 stable for windows non thread safe version installer for download) from http://windows.php.net/download/

Now the problem is URL route in IIS. That means when you lookup into ZF2 getting started docs you may find some code to edit .htaccess of apache. What about IIS in this case?

IIS have solution of URL rewrite problem. Visit www.iis.net/urlrewrite to get the latest copy of the plugin to attach into your IIS installation. Just install this addon/plugin/extension/demon/program whatever name you called.

After installation you need a file web.config into your “<ZF2Skeleton folder>/public” folder. No matter, here we do a small trick. Just download Drupal 7+ core from https://drupal.org/project/drupal and unpack it. There you found a web.config file at root path. Just copy and paste that file into your <ZF2Skeleton folder>/public folder.

That’s all folk!

Posted in php, webdevelopment, windowsTagged , , , , , , , ,