Yeoman - php project - php

I'm starting a new php project and I'm trying to learn new techniques (for me). Grunt, yeoman etc.
Now I want to start a php project and found this example from Bradleycorn => generator-php. As far as I think, I have everything working, but I can't rund my development local site using grunt server. I'm getting a error:
Running "php:server" (php) task
Invalid address: http://localhost/myproject.nl:80
I have this folder structure:
\Applications\XAMPP\xamppfiles\htdocs\myproject.nl\
Beneath this folder:
myproject\
|--.sass-cache\
|--.tmp\
|--app\
|--dist\
|--node_modules\
|--bower.json
|--Grunftile.js
|--package.jason
|--router-dist.php
|--router.php
In the Gruntfile.js this code is placed (part of the code with the dev URL):
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// CONFIGURABLE PATHS
// The yeomanConfig object contains file paths and other "constants" that are used throughout
// The rest of this Gruntfile. Basically, any value that is used in multiple places should be
// put here for ease of maintenance. Update the value here, and all other places are updated
// automagically.
var yeomanConfig = {
app: 'app',
dist: 'dist',
siteURL: 'www.myproject.nl',
devURL: 'http://localhost/myproject.nl',
devPort: 80
};
I also tried this devURL http://localhost/myproject.nl/myproject/dist:, but also not working. What should the devURL be in this case?
PS: I also want to run a local database, I'm using XAMPP for that.

Related

Vite & Vue3: Adding JS and CSS bundle to Wordpress plugin

I have a small Vue app and I want to use it as a plugin in Wordpress. I got this working without problems. The only challenge I have is to get Vite to use the PHP plugin file as the entry point instead of the usual index.html.
This is problematic because the build gives the bundles a unique file name by adding a hash, like index-eb5dc3f1.js. The index.html is generated during the build and automatically links to the unique files, but I need to manually change the PHP file after every build. I want to keep this mechanism of unique bundle names.
As a workaround I have changed my vite.config.js so vite no longer adds the hash:
build: {
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
}
}
}
And in the WordPress plugin I am adding it like:
wp_register_script('the-plugin', plugin_dir_url( __FILE__ ).'assets/index.js', true );
This works, but I rather would keep the hashes in the file name. Is there a possibility to let Vite alter the PHP file?
I have tried adding input: 'index.php', to the rollupOptions, but it is choaking on the PHP:
error during build:
RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)

How to control public resoucre(js, css, image,...) in Codeigniter like Express

I'm newbie in Codeigniter. Almost the whole time ago I use NodeJS. Can you show me how to control public resource in Codeigniter like Express? I want use /js/dev in development mode instead of /js.
example:
When first load web page with path: http://xxxx.com/js/default.js will get content from /js/dev/default.js instead of /js/default.js at development mode
Below is my code in Express for this idea.
if (process.env.NODE_ENV === 'development') {//path dev -> min to product
app.use('/js', express.static('client/js/dev'))
app.use('/css', express.static('client/css/dev'))
}
You can create any folder on your root directory. After that you can access those files with base_url(), be sure your base_url is correct, you can change it on 'application/config/config.php'
<?php
echo base_url('public/js/xyz.js');
echo base_url('uploads/img/15.jpg');

php (wordpress) - server not respond to file changes

I'm facing weird problem which a bit complicated to understand. So the situation is that:
we have 2 installs (actually more, but not relevant for now)
both installs places on same server (apache + nginx)
we update our code and therefore deploy to staging - first install works great, second one has problem.
the code is 100% percent the same
there is no influence of other plugin (wordpress) on the specific part of code
The relevant code is the following:
$track = new trackClass();
$track->store_parameters();
$parameters = unserialize($track->parameters);
class trackClass // this class sits on different file
{
public $parameters;
public function __construct() {
...
}
method...
method...
method ..
public function store_parameters()
{
...
}
}
Before we modify our code, the function store_parameters was private, now its public.
So when on the second install the code is running its raise an error that the store_paramters() function is private and not accessible (remind you that it happens only on the second install).
I tried another thing get_class_methods($track) and the response was all the methods except the store_parameters(). Again - weird.
Next step, put wp_die('test') in the top of the file of the class. Refreshing the page and all as usual (the file is definitely loaded). If I try to access the admin (wp-admin) the changes make difference - the page is killed, blank screen and 'test' on it.
Next step, remove this file completely from the server. Refreshing the page and nothing happen. Their is ajax request from the class file which run as usual, like the file is exists and everything is ok. Again, going to the admin page and the error is raised (require_once ... not found).
Its doesn't seems like its code or development problem. The code is same. I'm afraid that its something on the server side / environment (apache, nginx) but unfortunately I've no access to the linux, I only can chat with the support of the hosting company.
They are insists that is code problem. No matter the tests I wrote above.
What can cause this kind of problem? I'm losing my mind here with no lead, its like the file is stuck somewhere.

Updating version number in php file using grunt

I'm using grunt to compile, minify etc css and javascript which is all working as it should. But as i'm integrating it into an existing php site, for me to see the changes I need to update the version number in the php to clear the cache and the updated CSS to be shown.eg:
$nVersion = 20150807;
I've looked around but can't find a npm package which will allow me to specify the file and update certainly elements of the file.
Does anyone know of a package like this exists or know another way for me to achieve this?
For anyone else interested I've used grunt-text-replace npm package with the following grunt task:
replace: {
version: {
src: ['./version.php'],
dest: './version.php',
replacements: [{
from: /^\$nVersion = ([0-9])+/igm, // eg $nVersion = 20150807;
to: '$nVersion = ' + Date.now() // $nVersion = 1439212970400;
}]
}
}
And have attached the task to the watcher for any changes to the SCSS, JS files then it updates the version number

Flattering a directory structure while renaming all of the files to represent their original paths

I'm looking into storing Zend Framework on Microsoft Azures Blob Storage. Azure Blob storage has a flat file system where as Zend Framework has a deeply nested structure.
I want to create a folder containing all Zend Framework files using the following naming convention / method.
eg: The Zend_Log_Writter class is stored at:
library/Zend/Log/Writer.php
In the new flat output folder the file would be named:
Zend.Log.Writter.php
I'll use any tool that will accomplish the job linux or windows. I could write a PHP script that would do this but I'm guessing there is a piece of Linux Foo out there that could accomplish what I'm after with a few linked commands.
If I'm reading this question correctly, it sounds like you're trying to map a file system to individual blobs in Windows Azure Storage. You'd need some type of in-between tier to map requested files to individual blobs (and php has a very robust SDK you can use for accessing blobs). One correction about blobs: it's not exactly flat: The URI would be https://mystorageaccount/containername/blobname. You have one native directory (container), and you can then simulate further levels with the technique Pekka provided a link to.
However: To me, this mapping sounds like it may have performance implications, as well as transaction implications.
As an alternative, why not mount an NTFS-formatted Cloud Drive in a Windows Azure page blob? Your drive can be up to 1TB, accessible via drive-letter. It's durable (meaning triple-replicated within the data center), and would let you then install pretty much anything to it (such as the file directory structure for Zend). Pretty easy to set up - maybe a dozen lines of code.
The one caveat to Cloud Drives: only one writer. You'd have to keep that in mind when scaling your web app to multiple instances. There are workarounds (such as having one Cloud Drive per instance), and taking advantage of caching (such as the new AppFabric Cache which recently went into production).
EDIT: Here's a great Cloud Drive sample by Maarten Balliauw, demonstrating the steps needed for creating/allocating/mounting a Cloud Drive.
I know how to do this in python. Here is an example. Test it on some dummy directory first just to make sure you're using it right.
import os
import shutil
directory = '/path/to/your/directory/'
for root, folder, files in os.walk(directory):
for file in files:
print(directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
shutil.copy(root+'/'+file, directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
Edit as to why I used python: I did try using the find command and the -exec option in Linux initially....but much cleaner and easier to understand this way. I'm guessing you could go with one uber awesome line at the bash shell. However not sure the extra time needed to try and figure that out is worth it being as this is basically only 4 lines of relevant code.
Try this code. It makes use of StorageClient library from Microsoft.
namespace RenameBlobs
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount csa = CloudStorageAccount.DevelopmentStorageAccount;
string blobContainerName = "png1";
string oldDelimiter = "/";
string newDelimiter = ".";
CloudBlobClient blobClient = csa.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(blobContainerName);
string blobContainerUriString = blobContainer.Uri.AbsoluteUri;
BlobRequestOptions blobRequestOptions = new BlobRequestOptions()
{
UseFlatBlobListing = true,
};
var blobsList = blobContainer.ListBlobs(blobRequestOptions);
foreach (var blob in blobsList)
{
var blockBlob = (CloudBlockBlob) blob;
var abc = blockBlob.Metadata;
blockBlob.FetchAttributes();
string blobName = blockBlob.Uri.AbsoluteUri;
blobName = blobName.Replace(blobContainerUriString, string.Empty);
if (blobName.StartsWith(oldDelimiter))
{
blobName = blobName.Substring(1);
}
if (blobName.Contains(oldDelimiter))
{
blobName = blobName.Replace(oldDelimiter, newDelimiter);
string newBlobUriString = string.Format("{0}/{1}", blobContainerUriString, blobName);
var cloudBlob = blobContainer.GetBlobReference(newBlobUriString);
cloudBlob.CopyFromBlob(blockBlob);
}
}
}
}
}
Let me know if you have any questions about this code.
Hope this helps.
Thanks

Categories