src/Utils/Filesystem.php
public function synchronize($fromPath, $toPath, $renames = array())
    {
        // Verificar se fromPath e um diertorio
        if (!$this->isDirectory($fromPath))
            return false;

        // Verificar se deve criar o toPath
        if (!$this->isDirectory($toPath))
            $this->makeDirectory($toPath, 0777, true);

        // Copiar sincronizar estrutura
        $items = new \FilesystemIterator($fromPath, \FilesystemIterator::SKIP_DOTS);
        foreach ($items as $item)
        {
            $target = $toPath . '/' . $item->getBasename();

            if ($item->isDir())
            {
                $path = $item->getPathname();
                if (!$this->synchronize($path, $target, $renames))
                    return false;
            } else {
                // verificar se deve renomear
                foreach ($renames as $old => $new)
                    $target = str_replace($old, $new, $target);

                // Verificar se arquivo existe
                if ($this->exists($target))
                {
                    $hash_file = md5_file($item->getPathname());
                    $hash_dest = md5_file($target);
                    if ($hash_file != $hash_dest) {
                        if (!$this->copy($item->getPathname(), $target))
                            return false;
                    }
                } else {
                    if (!$this->copy($item->getPathname(), $target))
                        return false;
                }
            }
        }
        return true;
    }
public function synchronize($fromPath, $toPath, $renames = array())
    {
        // Verificar se fromPath e um diertorio
        if (!$this->isDirectory($fromPath))
            return false;

        // Verificar se deve criar o toPath
        if (!$this->isDirectory($toPath))
            $this->makeDirectory($toPath, 0777, true);

        // Copiar sincronizar estrutura
        $items = new \FilesystemIterator($fromPath, \FilesystemIterator::SKIP_DOTS);
        foreach ($items as $item)
        {
            $target = $toPath . '/' . $item->getBasename();

            if ($item->isDir())
            {
                $path = $item->getPathname();
                if (!$this->synchronize($path, $target, $renames))
                    return false;
            } else {
                // verificar se deve renomear
                foreach ($renames as $old => $new)
                    $target = str_replace($old, $new, $target);

                // Verificar se arquivo existe
                if ($this->exists($target))
                {
                    $hash_file = md5_file($item->getPathname());
                    $hash_dest = md5_file($target);
                    if ($hash_file != $hash_dest) {
                        if (!$this->copy($item->getPathname(), $target))
                            return false;
                    }
                } else {
                    if (!$this->copy($item->getPathname(), $target))
                        return false;
                }
            }
        }
        return true;
    }
public function synchronize ( $ fromPath , $ toPath , $ renames = array ( ) ) { // Verificar se fromPath e um diertorio if ( ! $ this -> isDirectory ( $ fromPath ) ) return false ; // Verificar se deve criar o toPath if ( ! $ this -> isDirectory ( $ toPath ) ) $ this -> makeDirectory ( $ toPath , 0777 , true ) ; // Copiar sincronizar estrutura $ items = new \ FilesystemIterator ( $ fromPath , \ FilesystemIterator :: SKIP_DOTS ) ; foreach ( $ items as $ item ) { $ target = $ toPath . '/' . $ item -> getBasename ( ) ; if ( $ item -> isDir ( ) ) { $ path = $ item -> getPathname ( ) ; if ( ! $ this -> synchronize ( $ path , $ target , $ renames ) ) return false ; } else { // verificar se deve renomear foreach ( $ renames as $ old => $ new ) $ target = str_replace ( $ old , $ new , $ target ) ; // Verificar se arquivo existe if ( $ this -> exists ( $ target ) ) { $ hash_file = md5_file ( $ item -> getPathname ( ) ) ; $ hash_dest = md5_file ( $ target ) ; if ( $ hash_file != $ hash_dest ) { if ( ! $ this -> copy ( $ item -> getPathname ( ) , $ target ) ) return false ; } } else { if ( ! $ this -> copy ( $ item -> getPathname ( ) , $ target ) ) return false ; } } } return true ; }
Synchronize from path with to path
@param $fromPath
@param $toPath
@return boolean
Synchronize from path with to path