1<?php
2/**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license    http://framework.zend.com/license/new-bsd     New BSD License
8 */
9
10namespace Zend\Form\Element;
11
12use Zend\Form\Element;
13use Zend\Form\ElementPrepareAwareInterface;
14use Zend\Form\FormInterface;
15use Zend\InputFilter\InputProviderInterface;
16
17class File extends Element implements InputProviderInterface, ElementPrepareAwareInterface
18{
19    /**
20     * Seed attributes
21     *
22     * @var array
23     */
24    protected $attributes = array(
25        'type' => 'file',
26    );
27
28    /**
29     * Prepare the form element (mostly used for rendering purposes)
30     *
31     * @param  FormInterface $form
32     * @return mixed
33     */
34    public function prepareElement(FormInterface $form)
35    {
36        // Ensure the form is using correct enctype
37        $form->setAttribute('enctype', 'multipart/form-data');
38    }
39
40    /**
41     * Should return an array specification compatible with
42     * {@link Zend\InputFilter\Factory::createInput()}.
43     *
44     * @return array
45     */
46    public function getInputSpecification()
47    {
48        return array(
49            'type'     => 'Zend\InputFilter\FileInput',
50            'name'     => $this->getName(),
51            'required' => false,
52        );
53    }
54}
55