Re: svn: /php/php-src/branches/PHP_5_3/ NEWS UPGRADING ext/spl/spl_directory.c ext/spl/tests/DirectoryIterator_getExtension_basic.phpt
ext/spl/tests/SplFileInfo_getExtension_basic.phpt

From: Date: Fri, 11 Feb 2011 22:10:17 +0000
Subject: Re: svn: /php/php-src/branches/PHP_5_3/ NEWS UPGRADING ext/spl/spl_directory.c ext/spl/tests/DirectoryIterator_getExtension_basic.phpt
ext/spl/tests/SplFileInfo_getExtension_basic.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-64531@lists.php.net to get a copy of this message
hi, Please add it to UPGRADING too :) Cheers, On Fri, Feb 11, 2011 at 11:07 PM, Peter Cowburn <salathe@php.net> wrote: > salathe                                  Fri, 11 Feb 2011 22:07:22 +0000 > > Revision: > http://svn.php.net/viewvc?view=revision&revision=308264 > > Log: > MFH - Added SplFileInfo::getExtension() (FR #48767) > > Bug: http://bugs.php.net/48767 (To be documented) > SplFileInfo::getExtension() > > Changed paths: >    U   php/php-src/branches/PHP_5_3/NEWS >    U   php/php-src/branches/PHP_5_3/UPGRADING >    U   php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c >    A   php/php-src/branches/PHP_5_3/ext/spl/tests/DirectoryIterator_getExtension_basic.phpt >    A   php/php-src/branches/PHP_5_3/ext/spl/tests/SplFileInfo_getExtension_basic.phpt > > Modified: php/php-src/branches/PHP_5_3/NEWS > =================================================================== > --- php/php-src/branches/PHP_5_3/NEWS   2011-02-11 21:13:16 UTC (rev 308263) > +++ php/php-src/branches/PHP_5_3/NEWS   2011-02-11 22:07:22 UTC (rev 308264) > @@ -148,7 +148,8 @@ >   . Fixed bug #53914 (SPL assumes HAVE_GLOB is defined). (Chris Jones) >   . Fixed bug #53515 (property_exists incorrect on ArrayObject null and 0 >     values). (Felipe) > - > +  . Added SplFileInfo::getExtension(). FR #48767. (Peter Cowburn) > + >  - SQLite3 extension: >   . Fixed memory leaked introduced by the NULL poisoning patch. >     (Mateusz Kocielski, Pierre) > > Modified: php/php-src/branches/PHP_5_3/UPGRADING > =================================================================== > --- php/php-src/branches/PHP_5_3/UPGRADING      2011-02-11 21:13:16 UTC (rev 308263) > +++ php/php-src/branches/PHP_5_3/UPGRADING      2011-02-11 22:07:22 UTC (rev 308264) > @@ -670,7 +670,9 @@ >                        ReflectionClass::inNamespace() >                        ReflectionClass::getNamespaceName() >                        ReflectionClass::getShortName() > -       - SPL           SplObjectStorage::addAll() > +       - SPL:          DirectoryIterator::getExtension() > +                       SplFileObject::getExtension() > +                       SplObjectStorage::addAll() >                        SplObjectStorage::removeAll() >        - XSL:          XSLTProcessor::setProfiling() > > > Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c > =================================================================== > --- php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c        2011-02-11 21:13:16 UTC > (rev 308263) > +++ php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c        2011-02-11 22:07:22 UTC > (rev 308264) > @@ -849,6 +849,66 @@ >  } >  /* }}} */ > > +/* {{{ proto string SplFileInfo::getExtension() > +   Returns file extension component of path */ > +SPL_METHOD(SplFileInfo, getExtension) > +{ > +       spl_filesystem_object *intern = > (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); > +       char *fname, *p; > +       size_t flen; > +       int path_len, idx; > + > +       if (zend_parse_parameters_none() == FAILURE) { > +               return; > +       } > + > +       spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); > + > +       if (path_len && path_len < intern->file_name_len) { > +               fname = intern->file_name + path_len + 1; > +               flen = intern->file_name_len - (path_len + 1); > +       } else { > +               fname = intern->file_name; > +               flen = intern->file_name_len; > +       } > + > +       php_basename(fname, flen, NULL, 0, &fname, &flen TSRMLS_CC); > + > +       p = zend_memrchr(fname, '.', flen); > +       if (p) { > +               idx = p - fname; > +               RETURN_STRINGL(fname + idx + 1, flen - idx - 1, 1); > +       } > + > +       RETURN_EMPTY_STRING(); > +} > +/* }}}*/ > + > +/* {{{ proto string DirectoryIterator::getExtension() > +   Returns the file extension component of path */ > +SPL_METHOD(DirectoryIterator, getExtension) > +{ > +       spl_filesystem_object *intern = > (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); > +       char *fname, *p; > +       size_t flen; > +       int idx; > + > +       if (zend_parse_parameters_none() == FAILURE) { > +               return; > +       } > + > +       php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), > NULL, 0, &fname, &flen TSRMLS_CC); > + > +       p = zend_memrchr(fname, '.', flen); > +       if (p) { > +               idx = p - fname; > +               RETURN_STRINGL(fname + idx + 1, flen - idx - 1, 1); > +       } > + > +       RETURN_EMPTY_STRING(); > +} > +/* }}} */ > + >  /* {{{ proto string SplFileInfo::getBasename([string $suffix]) U >    Returns filename component of path */ >  SPL_METHOD(SplFileInfo, getBasename) > @@ -1786,6 +1846,7 @@ >        SPL_ME(SplFileInfo,       __construct,   arginfo_info___construct, > ZEND_ACC_PUBLIC) >        SPL_ME(SplFileInfo,       getPath,       arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) >        SPL_ME(SplFileInfo,       getFilename,   arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) > +       SPL_ME(SplFileInfo,       getExtension,  arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) >        SPL_ME(SplFileInfo,       getBasename,   arginfo_optinalSuffix, ZEND_ACC_PUBLIC) >        SPL_ME(SplFileInfo,       getPathname,   arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) >        SPL_ME(SplFileInfo,       getPerms,      arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) > @@ -1829,6 +1890,7 @@ >  static const zend_function_entry spl_DirectoryIterator_functions[] = { >        SPL_ME(DirectoryIterator, __construct,   arginfo_dir___construct, ZEND_ACC_PUBLIC) >        SPL_ME(DirectoryIterator, getFilename,   arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) > +       SPL_ME(DirectoryIterator, getExtension,  arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) >        SPL_ME(DirectoryIterator, getBasename,   arginfo_optinalSuffix, ZEND_ACC_PUBLIC) >        SPL_ME(DirectoryIterator, isDot,         arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) >        SPL_ME(DirectoryIterator, rewind,        arginfo_splfileinfo_void, > ZEND_ACC_PUBLIC) > > Added: php/php-src/branches/PHP_5_3/ext/spl/tests/DirectoryIterator_getExtension_basic.phpt > =================================================================== > --- php/php-src/branches/PHP_5_3/ext/spl/tests/DirectoryIterator_getExtension_basic.phpt     >                            (rev 0) > +++ php/php-src/branches/PHP_5_3/ext/spl/tests/DirectoryIterator_getExtension_basic.phpt     >    2011-02-11 22:07:22 UTC (rev 308264) > @@ -0,0 +1,51 @@ > +--TEST-- > +SPL: DirectoryIterator::getExtension() basic test > +--FILE-- > +<?php > +$dir = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . > DIRECTORY_SEPARATOR; > +mkdir($dir); > + > +$files = array('test.txt', 'test.extension', 'test..', > 'test.', 'test'); > +foreach ($files as $file) { > +    touch($dir . $file); > +} > + > +$dit_exts = array(); > +$nfo_exts = array(); > +$skip = array('.', '..'); > + > +foreach (new DirectoryIterator($dir) as $file) { > +    if (in_array($file->getFilename(), $skip)) { > +        continue; > +    } > +    $dit_exts[] = $file->getExtension(); > +    $nfo_exts[] = pathinfo($file->getFilename(), PATHINFO_EXTENSION); > +} > +var_dump($dit_exts === $nfo_exts); > +sort($dit_exts); > +var_dump($dit_exts); > +?> > +--CLEAN-- > +<?php > +$dir   = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . > DIRECTORY_SEPARATOR; > +$files = array('test.txt', 'test.extension', 'test..', > 'test.', 'test'); > +foreach ($files as $file) { > +    unlink($dir . $file); > +} > +rmdir($dir); > +?> > +--EXPECTF-- > +bool(true) > +array(5) { > +  [0]=> > +  string(0) "" > +  [1]=> > +  string(0) "" > +  [2]=> > +  string(0) "" > +  [3]=> > +  string(9) "extension" > +  [4]=> > +  string(3) "txt" > +} > + > > Added: php/php-src/branches/PHP_5_3/ext/spl/tests/SplFileInfo_getExtension_basic.phpt > =================================================================== > --- php/php-src/branches/PHP_5_3/ext/spl/tests/SplFileInfo_getExtension_basic.phpt         >                      (rev 0) > +++ php/php-src/branches/PHP_5_3/ext/spl/tests/SplFileInfo_getExtension_basic.phpt     >  2011-02-11 22:07:22 UTC (rev 308264) > @@ -0,0 +1,31 @@ > +--TEST-- > +SPL: SplFileInfo::getExtension() basic test > +--FILE-- > +<?php > +$file = md5('SplFileInfo::getExtension'); > +$exts = array('.txt', '.extension', '..', '.', > ''); > +foreach ($exts as $ext) { > +    touch($file . $ext); > +    $info = new SplFileInfo($file . $ext); > +    var_dump($info->getExtension(), pathinfo($file . $ext, PATHINFO_EXTENSION)); > +} > +?> > +--CLEAN-- > +<?php > +$file = md5('SplFileInfo::getExtension'); > +$exts = array('.txt', '.extension', '..', '.', > ''); > +foreach ($exts as $ext) { > +    unlink($file . $ext); > +} > +?> > +--EXPECTF-- > +string(3) "txt" > +string(3) "txt" > +string(9) "extension" > +string(9) "extension" > +string(0) "" > +string(0) "" > +string(0) "" > +string(0) "" > +string(0) "" > +string(0) "" > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

« previous php.cvs (#64531) next »