如何覆盖laravel 5.4供应商的功能?

时间:2017-10-27 09:20:38

标签: laravel

我正在使用elFinder package。请帮我覆盖Laravel中的sanitizeFileName方法

vendor\studio-42\elfinder\php\plugins\Sanitizer\plugin.php

以下是方法:

private function sanitizeFileName($filename, $opts, $allows = array())
{
    $targets = $allows? array_diff($opts['targets'], $allows) : $opts['targets'];
    return str_replace($targets, $opts['replace'], $filename);
}

1 个答案:

答案 0 :(得分:0)

您可以通过继承该类来覆盖它,然后在您的类中编写确切的方法。像这样:

class MyClass extends Plugin{

  private function sanitizeFileName($filename, $opts, $allows = array()){
   // your code here...
  }

}

如果您对可见性有疑问,请改用protected / public

更新: 扩展课程

What is the proper way to extend a class in another file?

http://php.net/manual/it/keyword.extends.php

http://php.net/manual/en/language.oop5.inheritance.php