/** * upload image * @param Request $request * @param string $user_type * @param string $action * @return array info: * <ul> * <li>id</li> * <li>uri</li> * </ul> * @throws \Exception */ public function upload(Request $request, $user_type, $action) { $this->check_dir(); $this->auth->setType($user_type); $this->auth->requireAuth(); $uploaded_file = $request->files->get('_file'); if (is_null($uploaded_file)) { throw new \Exception('Картинка не загружена'); } if (!$uploaded_file->isValid()) { throw new \Exception('Не удалось загрузить файл'); } $file = $uploaded_file->move($this->pic_real_dir, $this->getPictureName(null, 'tmp')); unset($uploaded_file); $ext = $this->checkCorrectImageAndGetExt($file->getRealPath()); $new_name = $this->getPictureName($ext); $file->move($this->pic_real_dir, $new_name); unset($file); $id = $this->saveFile($new_name, $action); $uri = $this->pic_dir . $new_name; return ['id' => $id, 'uri' => $uri]; }
/** * @DI\InjectParams({ * "user" = @DI\Inject("access.user"), * "builder" = @DI\Inject("form_builder") * }) */ public function __construct(User $user, FormBuilder $builder) { $this->user = $user; $this->user->setType('UserBiz'); $this->builder = $builder; }
/** * * @DI\InjectParams( * { * "fb" = @DI\Inject("form_builder"), * "user"=@DI\Inject("access.user") * } * ) */ public function __construct(FormBuilder $fb, User $user) { $this->formbuilder = $fb; $this->user = $user; $this->user->setType('UserClient'); }