touki/ftp-bundle

touki/ftp 组件的封装包

dev-master / 1.0.x-dev 2015-06-09 14:06 UTC

This package is auto-updated.

Last update: 2024-09-07 23:49:13 UTC


README

这是一个用于封装 FTP 组件 的 Symfony2 扩展包

安装

composer.json

{
    "require": {
        "touki/ftp-bundle": "dev-master"
    }
}

然后运行

$ composer install touki/ftp-bundle

然后您必须在 AppKernel.php 中添加该扩展包

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return array(
            // ...
            new Touki\Bundle\FTPBundle\ToukiFTPBundle()
        );
    }
}

?>

配置

默认配置如下

touki_ftp:
    host:     localhost # Remote server name
    username: anonymous # Username to connect with
    password: guest     # Password to connect with
    port:     21        # Port to connect to
    secured:  false     # Whether to connect with SSL or not

服务列表

关于该组件的标准使用方法,请参阅 文档

<?php
$container->get('ftp.connection');
?>

保持与服务器的连接。默认情况下将其打开。

<?php
$container->get('ftp.wrapper');
?>

简单的 FTP 封装器。

<?php
$container->get('ftp.manager');
?>

文件系统管理器

<?php
$container->get('ftp');
?>

主要的 FTP 类

添加下载器

要添加自定义下载器,您需要创建一个实现以下接口的下载器

<?php

namespace Acme\FooBundle\Downloader;

use Touki\FTP\DownloaderInterface;
use Touki\FTP\DownloaderVotableInterface;
use Touki\FTP\Model\Filesystem;

class MyDownloader implements DownloaderInterface, DownloaderVotableInterface
{
    /**
     * {@inheritDoc}
     */
    public function vote($local, Filesystem $remote, array $options = array())
    {
        // Return a boolean based on arguments given to check if the downloader is compatible
    }

    /**
     * {@inheritDoc}
     */
    public function download($local, Filesystem $remote, array $options = array())
    {
        // Process the download
    }
}
?>

然后在您的 services.yml 中,创建一个新的服务并添加 ftp.downloader 标签

services:
    acme_foo.mydownloader:
        class: Acme\FooBundle\Downloader\MyDownloader
        tags:
            - { name: ftp.downloader, prepend: false } # Set prepend to true to prepend the downloader

添加上传器

要添加自定义上传器,您需要创建一个实现以下接口的上传器

<?php

namespace Acme\FooBundle\Uploader;

use Touki\FTP\UploaderInterface;
use Touki\FTP\UploaderVotableInterface;
use Touki\FTP\Model\Filesystem;

class MyUploader implements UploaderInterface, UploaderVotableInterface
{
    /**
     * {@inheritDoc}
     */
    public function vote(Filesystem $remote, $local, array $options = array())
    {
        // Return a boolean based on arguments given to check if the uploader is compatible
    }

    /**
     * {@inheritDoc}
     */
    public function upload(Filesystem $remote, $local, array $options = array())
    {
        // Process the upload
    }
}
?>

然后在您的 services.yml 中,创建一个新的服务并添加 ftp.uploader 标签

services:
    acme_foo.myuploader:
        class: Acme\FooBundle\Uploader\MyUploader
        tags:
            - { name: ftp.uploader, prepend: false } # Set prepend to true to prepend the uploader