Silex Doctrine Extensions - doctrine

To make use of the Doctrine Extension in the Silex usage documentation they are asking that you
"Make sure you place a copy of Doctrine DBAL in vendor/doctrine-dbal and Doctrine Common in vendor/doctrine-common."
They then go onto an example of how to register with:
$app->register(new Silex\Extension\DoctrineExtension(), array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => __DIR__.'/app.db',
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));
What I don't get are two things...
1) the path __DIR_.'vendor/doctrine-dbal/lib'
What does lib mean?? I don't see a lib folder or file in the doctrine package.
2) doctrine dbal and doctrine common...
The folder structure of the unpacked tar look like this:
does that mean I put the contents of each of those folders in their respective folders?
Thanks for your help. I'm having more trouble figuring out paths to these extensions than I am the extensions themselves.
-J

Include them as submodules if you are using git as version control system (which you should).
Then just add them this way:
git submodule add git://github.com/doctrine/dbal.git vendor/doctrine-dbal
git submodule add git://github.com/doctrine/common.git vendor/doctrine-common
Next init the submodule folders:
git submodule init
and fetch them from git:
git submodule update --recursive

lib should correspond to the DBAL/lib folder and likewise with the Common/lib folder. I think these instructions are more inline with a composer based installation layout.

After downloading the DBLA, copy the 'Doctrine' folder to 'vendor', then update db.dbal.class_path and db.common.class_path to '/vendor/'.
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'db.options' => array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'dbname' => 'testdb',
'user' => 'root',
'password' => ''
),
'db.dbal.class_path' => __DIR__.'/vendor/',
'db.common.class_path' => __DIR__.'/vendor/',
));
or
Create the following folder structure in 'vendor'
'doctrine-dbal/lib/Doctrine/DBAL/'
'doctrine-common/lib/Doctrine/Common/'
copy 'Doctrine/DBAL/' to 'vendor/doctrine-dbal/lib/Doctrine/DBAL/'
copy 'Doctrine/Common/' to 'vendor/doctrine-common/lib/Doctrine/Common/'
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => __DIR__.'/app.db',
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));

Related

Shared Hosting Laravel 8 Hosting problem: Symlink is not working

I need the deploy my laravel project to the web. With this introduction But the hosting provider is Doesn't allow me to use a symbolic link(symlink), I called customer service, and told me blocked for security reasons.
So, since I do not use symbolic links, there are big problems in uploading images and deploying them.
Is there a way to do deployment my app?
Change your disk configurations in the config/filesystems.php to read and write to public folder via public_path() function.
If you're deploying over a shared host, you probably have another folder like public_html as your public folder which is not included in your source. Try to link to the public_html using dots ../../public_html/
'public' => [
'driver' => 'local',
// 'root' => storage_path('app/public'),
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
'photos' => [
'driver' => 'local',
'root' => public_path('photos'),
'url' => env('APP_URL') . '/photos',
'visibility' => 'public',
],
Another way is just create something like symlink using php, example you can create a route like below:
Route::get(
'/storage/{file}',
function ($file) {
$filepath = "../storage/app/public/".$file;
header("Cache-Control: public");
header("Content-Type: ".mime_content_type($filepath));
header('Content-Length: '.filesize($filepath));
readfile($filepath);
die();
}
);
Maybe not best practice, but it will solve your problem. It's will do same as symlink.

Laravel upload via FTP prevent overriding live logs

I am updating my laravel project via FTP.
I set override all files, where edit date changed.
Problem:
It overrides the live logs with the dev logs, because the name of the log file is the same.
I wanted to change log names (could save it in .env, because live project has its own .env), but I have not found a way to do it.
Any other ideas?
Just exclude logs file/dir when copying files instead of overriding it?
Here is my solution.
Go to logging.php and edit this condig:
'single' => [
'driver' => 'single',
//'path' => storage_path('logs/laravel.log'),
'path' => storage_path(env('LOG_PATH')),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
//'path' => storage_path('logs/laravel.log'),
'path' => storage_path(env('LOG_PATH')),
'level' => 'debug',
'days' => 14,
]
Because the live project has a different .env, you can define a different folder or filename and it will work.

Laravel Storage method allDirectories() does not return recursively directories from FTP server

I need to get list of all directories from the FTP server.
After successful FTP driver setup, Storage::allDirectories() method is returning all directories from root directory. I have also tried to use:
Storage::directories('/', true)
Which should also return recursive values but it's the same case.
Does anyone have any idea what should be problem?
This is my FTP connection setup:
$ftp = Storage::createFtpDriver([
'host' => $streamServer->url,
'username' => $streamServer->username,
'password' => $streamServer->password,
'port' => '21',
'timeout' => '30',
]);
Welcome to Stackoverflow
I have checked with my code and it's working when I added the following line in my filesystems.php
I have created ftp driver in filesystems as below.
'ftp' => [
'driver' => env('DOCUMENT_UPLOAD_DRIVER','sftp'),
'host' => env('DOCUMENT_UPLOAD_HOST','127.0.0.1'),
'username' => env('DOCUMENT_UPLOAD_USERNAME','root'),
'password' => env('DOCUMENT_UPLOAD_PASSWORD','root'),
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
'port' => env('DOCUMENT_UPLOAD_PORT', 22),
'timeout' => env('DOCUMENT_UPLOAD_TIMEOUT', 30),
],
this line is additionaly added.
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
and when I use the following command it works for me.
Storage::disk('ftp')->allDirectories('directoryName');
provide directory name from which you want to get list or leave blank will provide you the list of all the recursive directories from html directory because we have provided it as a root.
after that you need to extract directories manually, as it just gives you an array like namespace will all the recursive directories.

Storing files outside the Laravel 5 Root Folder

I am developing a laravel 5 project and storing image files using imagine. I would want to store my image files in a folder outside the project's root folder. I am stuck at the moment The external folder where image files are supposed to be stored, I want to make it accessible via a sub-domain something like http://cdn.example.com Looking towards your solutions.
The laravel documentation could give you a helping hand.
Otherwise you could go to config/filesystems.php and add your own custom storage path for both local and production:
return [
'default' => 'custom',
'cloud' => 's3',
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path().'/app',
],
'custom' => [
'driver' => 'custom',
'root' => '../path/to/your/new/storage/folder',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
'rackspace' => [
'driver' => 'rackspace',
'username' => 'your-username',
'key' => 'your-key',
'container' => 'your-container',
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
'region' => 'IAD',
],
],
];
get ur path name from base_path(); function, then from the string add your desired folder location.
suppose ur
base_path() = '/home/user/user-folder/your-laravel-project-folder/'
So ur desired path should be like this
$path = '/home/user/user-folder/your-target-folder/'.$imageName;
make sure u have the writing and reading permission
You can move all or a part of storage folder in any folder of yours in your server. You must put a link from old to new folder.
ln -s new_fodler_path older_folder_path
You can make a new virtual host to serve the new folder path.

How to prevent files from being modified in elFinder?

I am using elFinder 2 + Codeigniter. And I would like to restrict users from deleting or modifying the existing files on all my folders.
I tried with this:
function elfinder_init(){
$this->load->helper('path');
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => set_realpath('root'),
'URL' => base_url('root'),
//This didn't do the trick***
'defaults' => array('read' => true, 'write' => false, 'locked' => true),
)
)
);
$this->load->library('elfinder_lib', $opts);
}
It prevent users from uploading new files, but still allows them to modify/delete the existing ones.
Official documentation there is very vague in general and there is no info on how to achieve this, so if you could help me, I'll really appreciate it.
Extracted from their own GitHub issues tickets :
Here is an example to lock folder and subfolder write / delete
array(
'pattern' => '/.(lockedFolder1|lockedFolder2)/',
// Dont write or delete to this and all subfolders
'read' => true,
'write' => false,
'locked' => true
)
Here is an example to lock root but not subfolders :
array(
'pattern' => '/.(lockedFolder1|lockedFolder2)$/',
// Dont write or delete to this but subfolders and files
'read' => true,
'write' => false,
'locked' => true
)
Source

Resources